color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Duplicate and extend your `caesar_break()` function
* How to cycle through all the keys?
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
* Count the gaps in the letters.
---
+
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# How affine ciphers work
-_ciphertext_letter_ =_plaintext_letter_ × a + b
+.ciphertext[_ciphertext_letter_] =.plaintext[_plaintext_letter_] × a + b
* Convert letters to numbers
* Take the total modulus 26
Result from number theory: only numbers coprime with _n_ have multiplicative inverses in arithmetic mod _n_.
-Another result from number theory: for non-negative integers _a_ and _n_, and there exist unique integers _x_ and _y_ such that _ax_ + _ny_ = gcd(_a_, _b_)
+Another result from number theory: for non-negative integers _m_ and _n_, and there exist unique integers _x_ and _y_ such that _mx_ + _ny_ = gcd(_m_, _n_)
Coprime numbers have gcd of 1.
-_ax_ + _ny_ = 1 mod _n_. But _ny_ mod _n_ = 0, so _ax_ = 1 mod _n_, so _a_ = _x_<sup>-1</sup>.
+_mx_ + _ny_ = 1 mod _n_. But _ny_ mod _n_ = 0, so _mx_ = 1 mod _m_, so _m_ = _x_<sup>-1</sup>.
Perhaps the algorithm for finding gcds could be useful?
text-shadow: 0 0 20px #333;
padding: 2px 5px;
}
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
+ }
</style>
</head>
<body>
<textarea id="source">
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Aims
Material aimed for two (three?) audiences
1. Teacher CPD
2. In-school resources for children
-3. (Outreach resources, mainly Bletchley Park)
+3. Outreach resources, mainly Bletchley Park
After your suggestions on how to extend these notes to hit these audiences
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Back to frequency of letter counts
Letter | Count
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Human vs Machine
Slow but clever vs Dumb but fast
How do we define "closeness"?
+## Here begineth the yak shaving
+
---
# What does English look like?
* Count them
```python
import collections
+collections.Counter()
```
Create the `language_models.py` file for this.
---
-# How much ciphertext do we need?
+# Homework: how much ciphertext do we need?
## Let's do an experiment to find out
4. Score 1 point if `caesar_cipher_break()` recovers the correct key
5. Repeat many times and with many plaintext lengths
+```python
+import csv
+
+def show_results():
+ with open('caesar_break_parameter_trials.csv', 'w') as f:
+ writer = csv.DictWriter(f, ['name'] + message_lengths,
+ quoting=csv.QUOTE_NONNUMERIC)
+ writer.writeheader()
+ for scoring in sorted(scores.keys()):
+ scores[scoring]['name'] = scoring
+ writer.writerow(scores[scoring])
+```
</textarea>
<script src="http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type="text/javascript">
text-shadow: 0 0 20px #333;
padding: 2px 5px;
}
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
+ }
</style>
</head>
<body>
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Enciphering and deciphering
## Arithmetic on letters
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
<body>
<textarea id="source">
+
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Taking this further
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+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?
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# The cipher
* Still character-by-character substitution, still monosubstitution.
```python
from enum import Enum
-class Keyword_wrap_alphabet(Enum):
+class KeywordWrapAlphabet(Enum):
from_a = 1
from_last = 2
from_largest = 3
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Breaking the Pocket Enigma
A _crib_ is a piece of plaintext we believe to be in the enciphered message.
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Pocket Enigma
Emulates the Enigma machine from WWII
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# ...Pick one that looks most like English
But the naïve Bayes score will always be the same!
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# Transposition ciphers
Rather than changing symbols (substitution ciphers),
color: #ff6666;
text-shadow: 0 0 20px #333;
padding: 2px 5px;
+ }
+ .indexlink {
+ position: absolute;
+ bottom: 1em;
+ left: 1em;
}
.float-right {
float: right;
---
+layout: true
+
+.indexlink[[Index](index.html)]
+
+---
+
# The problem
Ciphertext is re-split into groups to hide word bounaries.