From: Neil Smith Date: Wed, 23 Jul 2014 11:46:41 +0000 (+0100) Subject: Bits of tinkering X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=2e77bc75c34ac7d99310c1b778df972769068d98;p=cipher-training.git Bits of tinkering --- diff --git a/2013/solutions.txt b/2013/solutions.txt index fbf7502..23c8cb2 100644 --- a/2013/solutions.txt +++ b/2013/solutions.txt @@ -13,8 +13,8 @@ c5a = open('2013/5a.ciphertext').read() c5b = open('2013/5b.ciphertext').read() c6a = open('2013/6a.ciphertext').read() c6b = open('2013/6b.ciphertext').read() -c7a = open('2013/6a.ciphertext').read() -c7b = open('2013/6b.ciphertext').read() +c7a = open('2013/7a.ciphertext').read() +c7b = open('2013/7b.ciphertext').read() p1a = caesar_decipher(c1a, 8) p1b = caesar_decipher(c1b, 14) diff --git a/cipher.py b/cipher.py index 713db29..b53ae24 100644 --- a/cipher.py +++ b/cipher.py @@ -212,7 +212,7 @@ def affine_decipher_letter(letter, multiplier=1, adder=0, one_based=True): if one_based: cipher_number += 1 plaintext_number = ( modular_division_table[multiplier] - [(cipher_number - adder) % 26] ) + [(cipher_number - adder) % 26]) if one_based: plaintext_number -= 1 return chr(plaintext_number % 26 + alphabet_start) else: @@ -566,7 +566,7 @@ class PocketEnigma(object): >>> pe.validate_wheel_spec([]) Traceback (most recent call last): ... - ValueError: Wheel specification has 0 pairs, require 13 + ValueError: Wheel specification has 0 pairs, requires 13 >>> pe.validate_wheel_spec([('a', 'b', 'c')]*13) Traceback (most recent call last): ... diff --git a/norms.py b/norms.py index b8e4bf1..6645294 100644 --- a/norms.py +++ b/norms.py @@ -13,7 +13,7 @@ def normalise(frequencies): >>> sorted(normalise({1: 1, 2: 2, 3: 1}).items()) [(1, 0.25), (2, 0.5), (3, 0.25)] """ - length = sum([f for f in frequencies.values()]) + length = sum(f for f in frequencies.values()) return collections.defaultdict(int, ((k, v / length) for (k, v) in frequencies.items())) diff --git a/slides/caesar-break.html b/slides/caesar-break.html index 8792446..090c43f 100644 --- a/slides/caesar-break.html +++ b/slides/caesar-break.html @@ -207,6 +207,8 @@ Text encodings will bite you when you least expect it. # Five minutes on StackOverflow later... ```python +import unicodedata + def unaccent(text): """Remove all accents from letters. It does this by converting the unicode string to decomposed compatibility