Tweaked the keyword break slides
[cipher-training.git] / slides / keyword-break.html
index 46dded537677c2b3b1c032524452af24bdbbc9c7..49160bbb4fe394a3a5f9d88a05a797c62b732372 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 */
@@ -77,6 +77,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 +86,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 +149,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):`