'ls umfjsd jlsi zg hfsqysxog. ls dmmdtsd mx jls bats mh bkbsf. ls ' \
'bfmctsd kfmyxd jls lyj, mztanamyu xmc jm clm cku tmmeaxw kj lai ' \
'kxd clm ckuxj.') # doctest: +ELLIPSIS
- ((15, 22, True), 0.0598745365924...)
+ ((15, 22, True), -340.611412245...)
"""
sanitised_message = sanitise(message)
best_multiplier = 0
best_one_based = True
best_fit = float("-inf")
for one_based in [True, False]:
- for multiplier in range(1, 26, 2):
+ for multiplier in [x for x in range(1, 26, 2) if x != 13]:
for adder in range(26):
plaintext = affine_decipher(sanitised_message,
multiplier, adder, one_based)
>>> keyword_break(keyword_encipher('this is a test message for the ' \
'keyword decipherment', 'elephant', 1), \
wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS
- (('elephant', 1), 0.1066453448861...)
+ (('elephant', 1), -52.8345642265...)
"""
best_keyword = ''
best_wrap_alphabet = True
>>> keyword_break_mp(keyword_encipher('this is a test message for the ' \
'keyword decipherment', 'elephant', 1), \
wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS
- (('elephant', 1), 0.106645344886...)
+ (('elephant', 1), -52.834564226507...)
"""
with Pool() as pool:
helper_args = [(message, word, wrap, fitness)
>>> scytale_break('tfeulchtrtteehwahsdehneoifeayfsondmwpltmaoalhikotoere' \
'dcweatehiplwxsnhooacgorrcrcraotohsgullasenylrendaianeplscdriioto' \
'aek') # doctest: +ELLIPSIS
- (6, 0.092599933059...)
+ (6, -281.276219108...)
"""
best_key = 0
best_fit = float("-inf")
>>> vigenere_keyword_break(vigenere_encipher(sanitise('this is a test ' \
'message for the vigenere decipherment'), 'cat'), \
wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS
- ('cat', 0.15965224935...)
+ ('cat', -52.9479167030...)
"""
best_keyword = ''
best_fit = float("-inf")
>>> vigenere_keyword_break_mp(vigenere_encipher(sanitise('this is a test ' \
'message for the vigenere decipherment'), 'cat'), \
wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS
- ('cat', 0.159652249358...)
+ ('cat', -52.9479167030...)
"""
with Pool() as pool:
helper_args = [(message, word, fitness)
# Gotcha: the helper function here needs to be defined at the top level
# (limitation of Pool.starmap)
breaks = pool.starmap(vigenere_keyword_break_worker, helper_args, chunksize)
- return min(breaks, key=lambda k: k[1])
+ return max(breaks, key=lambda k: k[1])
def vigenere_keyword_break_worker(message, keyword, fitness):
plaintext = vigenere_decipher(message, keyword)
"afternoon when he left his jacket hanging on the easel in the " \
"attic. I jump every time I hear a footstep on the stairs, " \
"certain that the theft has been discovered and that I will " \
- "and that I will be caught. The SS officer visits less often now " \
- "that he is sure"), 'florence')) # doctest: +ELLIPSIS
- ('florence', 0.077657073...)
+ "be caught. The SS officer visits less often now that he is " \
+ "sure"), 'florence')) # doctest: +ELLIPSIS
+ ('florence', -307.5549865898...)
"""
best_fit = float("-inf")
best_key = ''
"afternoon when he left his jacket hanging on the easel in the " \
"attic. I jump every time I hear a footstep on the stairs, " \
"certain that the theft has been discovered and that I will " \
- "and that I will be caught. The SS officer visits less often now " \
+ "be caught. The SS officer visits less often now " \
"that he is sure"), 'florence')) # doctest: +ELLIPSIS
- ('florence', 0.077657073...)
+ ('florence', -307.5549865898...)
"""
best_fit = float("-inf")
best_key = ''
sanitised_message = sanitise(message)
for trial_length in range(1, 20):
splits = every_nth(sanitised_message, trial_length)
- key = ''.join([chr(caesar_break(s)[0] + ord('a')) for s in splits])
+ key = ''.join([chr(-caesar_break(s)[0] % 26 + ord('a')) for s in splits])
plaintext = beaufort_decipher(sanitised_message, key)
fit = fitness(plaintext)
logger.debug('Beaufort key length of {0} ({1}) gives fit of {2}'.