<!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 */
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.
---
+# 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.
## 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):`