Made a few tweaks
[cipher-training.git] / slides / caesar-encipher.html
index 4f99cc2e34f4f7f3e364ee1bb457cbe6a2ba24a3..4afd78dad4f3367c5107a99d0f40ff8f1e0aa037 100644 (file)
 <!DOCTYPE html>
 <html>
   <head>
-    <title>Title</title>
+    <title>Caesar cipher</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     <style type="text/css">
       /* Slideshow styles */
+      body {
+        font-size: 20px;
+      }
+      h1, h2, h3 {
+        font-weight: 400;
+        margin-bottom: 0;
+      }
+      h1 { font-size: 3em; }
+      h2 { font-size: 2em; }
+      h3 { font-size: 1.6em; }
+      a, a > code {
+        text-decoration: none;
+      }
+      code {
+        -moz-border-radius: 5px;
+        -web-border-radius: 5px;
+        background: #e7e8e2;
+        border-radius: 5px;
+        font-size: 16px;
+      }
+      .plaintext {
+        background: #272822;
+        color: #80ff80;
+        text-shadow: 0 0 20px #333;
+        padding: 2px 5px;
+      }
+      .ciphertext {
+        background: #272822;
+        color: #ff6666;
+        text-shadow: 0 0 20px #333;
+        padding: 2px 5px;
+      }
+      .indexlink {
+        position: absolute;
+        bottom: 1em;
+        left: 1em;
+      }
     </style>
   </head>
   <body>
     <textarea id="source">
 
-class: center, middle
-
 # Caesar ciphers
 
-* Letter-by-letter enciphering
+![centre-aligned Caesar wheel](caesarwheel1.gif)
+
+Letter-by-letter enciphering
+
+---
+
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
+# Enciphering and deciphering
+
+## Arithmetic on letters
+
+Convert .plaintext[letter] → .plaintext[number] → 
+.ciphertext[number] → .ciphertext[letter]
+
+Functions you will need
+
+```python
+ord()
+
+chr()
+
+%
+```
+
+* What are good test cases?
+
+---
+
+# Using the tools
+
+Before doing anything, create a new branch in Git
+
+* This will keep your changes isolated
+
+Experiment in IPython (ephemeral, for us)
+
+Once you've got something working, copy the code into a `.py` file (permanent and reusable)
+
+```python
+from imp import reload
+
+import test
+reload(test)
+from test import *
+```
+
+Re-evaluate the second cell to reload the file into the IPython notebook
+
+When you've made progress, make a Git commit
+
+* Commit early and often!
+
+When you've finished, change back to `master` branch and `merge` the development branch
 
 ---
 
@@ -22,6 +114,7 @@ class: center, middle
 
 ```python
 import string
+
 string.ascii_letters
 string.ascii_lowercase
 string.ascii_uppercase
@@ -31,11 +124,30 @@ string.punctuation
 
 ---
 
+# DRY and YAGNI
+
+Is your code DRY?
+
+---
+
 # Doctest
 
 * Why document?
 * Why test?
 
+```python
+def caesar_encipher_letter(letter, shift):
+    """Encipher a letter, given a shift amount
+
+    >>> caesar_encipher_letter('a', 1)
+    'b'
+    """
+    if letter in string.ascii_letters:
+    .
+    .
+    .
+```
+
 ---
 
 # The magic doctest incantation
@@ -48,7 +160,18 @@ if __name__ == "__main__":
 
 ---
 
-# Doing all the letters
+# Doing the whole message
+
+## Test-first developement
+
+1. Write the tests.
+    * They will fail. There is no code.
+2. Write code until the tests pass.
+3. Refactor.
+
+---
+
+# Doing the whole message
 
 ## Abysmal
 
@@ -58,11 +181,13 @@ for i in range(len(plaintext)):
     ciphertext += caesar_encipher_letter(plaintext[i], key)
 ```
 
+Try it in IPython
+
 ---
 
-# Doing all the letters
+# Doing the whole message
 
-## (Merely) Bad
+## Bad
 
 ```python
 ciphertext = ''
@@ -70,9 +195,11 @@ for p in plaintext:
     ciphertext += caesar_encipher_letter(p, key)
 ```
 
+...but easily generalisable
+
 ---
 
-# Doing all the letters
+# Doing the whole message
 
 ## Good (but unPythonic)
 
@@ -82,20 +209,26 @@ ciphertext = map(lambda p: caesar_encipher_letter(p, key), plaintext)
 
 ---
 
-# Doing all the letters
+# Doing the whole message
 
 ## Best
 
 ```python
 ciphertext = [caesar_encipher_letter(p, key) for p in plaintext]
 ```
+---
 
+# Not all iterables are equal
+
+```python
+''.join()
+```
 
     </textarea>
     <script src="http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type="text/javascript">
     </script>
     <script type="text/javascript">
-      var slideshow = remark.create();
+      var slideshow = remark.create({ ratio: "16:9" });
     </script>
   </body>
 </html>
\ No newline at end of file