1cdf8ddf0ad3cc22da75e10f27385c2f569ce118
[cipher-training.git] / slides / caesar-encipher.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Title</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
6 <style type="text/css">
7 /* Slideshow styles */
8 body {
9 font-size: 20px;
10 }
11 h1, h2, h3 {
12 font-weight: 400;
13 margin-bottom: 0;
14 }
15 h1 { font-size: 4em; }
16 h2 { font-size: 2em; }
17 h3 { font-size: 1.6em; }
18 a, a > code {
19 /* color: rgb(249, 38, 114); */
20 text-decoration: none;
21 }
22 code {
23 -moz-border-radius: 5px;
24 -web-border-radius: 5px;
25 background: #e7e8e2;
26 border-radius: 5px;
27 font-size: 16px;
28 }
29 </style>
30 </head>
31 <body>
32 <textarea id="source">
33
34 # Caesar ciphers
35
36 ![centre-aligned Caesar wheel](caesarwheel1.gif)
37
38 * Letter-by-letter enciphering
39
40 ---
41
42 # The [string module](http://docs.python.org/3.3/library/string.html) is your friend
43
44 ```python
45 import string
46 string.ascii_letters
47 string.ascii_lowercase
48 string.ascii_uppercase
49 string.digits
50 string.punctuation
51 ```
52
53 ---
54
55 # Doctest
56
57 * Why document?
58 * Why test?
59
60 ---
61
62 # The magic doctest incantation
63
64 ```python
65 if __name__ == "__main__":
66 import doctest
67 doctest.testmod()
68 ```
69
70 ---
71
72 # Doing all the letters
73
74 ## Abysmal
75
76 ```python
77 ciphertext = ''
78 for i in range(len(plaintext)):
79 ciphertext += caesar_encipher_letter(plaintext[i], key)
80 ```
81
82 ---
83
84 # Doing all the letters
85
86 ## (Merely) Bad
87
88 ```python
89 ciphertext = ''
90 for p in plaintext:
91 ciphertext += caesar_encipher_letter(p, key)
92 ```
93
94 ---
95
96 # Doing all the letters
97
98 ## Good (but unPythonic)
99
100 ```python
101 ciphertext = map(lambda p: caesar_encipher_letter(p, key),
102 plaintext)
103 ```
104
105 ---
106
107 # Doing all the letters
108
109 ## Best
110
111 ```python
112 ciphertext = [caesar_encipher_letter(p, key)
113 for p in plaintext]
114 ```
115
116
117 </textarea>
118 <script src="http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type="text/javascript">
119 </script>
120 <script type="text/javascript">
121 var slideshow = remark.create();
122 </script>
123 </body>
124 </html>