Tweaked slide layout
[cipher-training.git] / slides / keyword-break.html
index 46dded537677c2b3b1c032524452af24bdbbc9c7..08013f3f0f2d5c21a212040f7dbf06d7d88f86fc 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <title>Affine ciphers</title>
+    <title>Breaking keyword ciphers</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     <style type="text/css">
       /* Slideshow styles */
         color: #ff6666;
         text-shadow: 0 0 20px #333;
         padding: 2px 5px;
+      }
+      .indexlink {
+        position: absolute;
+        bottom: 1em;
+        left: 1em;
       }
        .float-right {
         float: right;
@@ -53,6 +58,12 @@ k | e | y | w | o | r | d | a | b | c | f | g | h | i | j | l | m | n | p | q |
 
 ---
 
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
 # Duplicate and extend your `affine_break()` function
 
 * How to cycle through all the keys? What _are_ all the keys?
@@ -77,6 +88,7 @@ Thread-safe shared-memory code is hard.
 Python's Global Interpreter Lock prevents shooting yourself in the foot.
 
 Where you want true parallelism, need different threads (Python processes).
+
 * Thread-safe shared-memory code is hard.
 
 The `multiprocessing` library makes this easier.
@@ -85,6 +97,28 @@ But before we get there, a couple of diversions...
 
 ---
 
+# DRYing code
+
+Three cipher breaking tasks so far.
+
+All working on the same principle:
+
+```
+find a way to enumerate all the possible keys
+initialise 'best so far'
+for each key:
+    decipher message with this key
+    score it
+    if it's better than the best so far:
+        update best so far
+```
+
+Repetition of code is a bad smell.
+
+Separate the 'try all keys, keep the best' logic from the 'score this one key' logic.
+
+---
+
 # map()
 
 A common task is to apply a function to each item in a sequence, returning a sequence of the results.
@@ -126,7 +160,7 @@ How do you write a function that takes this many arguments?
 ## Positional, keyword
 
 * Common or garden parameters, as you're used to.
-* `def keyword_encipher(message, keyword, wrap_alphabet=0):`
+* `def keyword_encipher(message, keyword, Keyword_wrap_alphabet.from_a):`
 
 ## Excess positional
 * `def mean(x, *xs):`