From: Neil Smith Date: Wed, 20 Nov 2013 12:14:24 +0000 (+0000) Subject: Using ngram length for scytale break X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=fd02f7a4423120f5c73b4038678cee7836a659ca;p=cipher-tools.git Using ngram length for scytale break --- 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,