From fd02f7a4423120f5c73b4038678cee7836a659ca Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 20 Nov 2013 12:14:24 +0000 Subject: [PATCH] Using ngram length for scytale break --- cipher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cipher.py b/cipher.py index ba4a73f..0e22a2a 100644 --- a/cipher.py +++ b/cipher.py @@ -655,11 +655,12 @@ def scytale_break(message, """ best_key = 0 best_fit = float("inf") + ngram_length = len(next(iter(target_counts.keys()))) for key in range(1, 20): if len(message) % key == 0: plaintext = scytale_decipher(message, key) counts = message_frequency_scaling(frequencies( - ngrams(sanitise(plaintext), 2))) + ngrams(sanitise(plaintext), ngram_length))) fit = metric(target_counts, counts) logger.debug('Scytale break attempt using key {0} gives fit of ' '{1} and decrypt starting: {2}'.format(key, -- 2.34.1