if not alphabet:
alphabet = list(string.ascii_lowercase)
random.shuffle(alphabet)
- alphabet = ''.join(alphabet)
+ alphabet = cat(alphabet)
return monoalphabetic_break_hillclimbing_worker(ciphertext, alphabet,
max_iterations, fitness)
else:
this_alphabet = list(string.ascii_lowercase)
random.shuffle(this_alphabet)
- this_alphabet = ''.join(this_alphabet)
+ this_alphabet = cat(this_alphabet)
worker_args.append((ciphertext, this_alphabet, max_iterations, fitness))
with Pool() as pool:
breaks = pool.starmap(monoalphabetic_break_hillclimbing_worker,
"""
def worker(message, key_length, fitness):
splits = every_nth(sanitised_message, key_length)
- key = ''.join([chr(caesar_break(s)[0] + ord('a')) for s in splits])
+ key = cat([chr(caesar_break(s)[0] + ord('a')) for s in splits])
plaintext = vigenere_decipher(message, key)
fit = fitness(plaintext)
return key, fit
"""
def worker(message, key_length, fitness):
splits = every_nth(sanitised_message, key_length)
- key = ''.join([chr(-caesar_break(s)[0] % 26 + ord('a'))
+ key = cat([chr(-caesar_break(s)[0] % 26 + ord('a'))
for s in splits])
plaintext = beaufort_decipher(message, key)
fit = fitness(plaintext)
with Pool() as pool:
helper_args = [(message, trans, fillcolumnwise, emptycolumnwise,
fitness)
- for trans in translist.keys()
+ for trans in translist
for fillcolumnwise in [True, False]
for emptycolumnwise in [True, False]]
# Gotcha: the helper function here needs to be defined at the top level
(5, 0, 6, 1, 3, 4, 2): ['fourteen'], \
(6, 1, 0, 4, 5, 3, 2): ['keyword']}, \
patterns=[(1, 2)]) # doctest: +ELLIPSIS
- (((2, 0, 5, 3, 1, 4, 6), (1, 2)), -709.4646722...)
+ (((2, 0, 5, 3, 1, 4, 6), (1, 2), <AmscoFillStyle.continuous: 1>), -709.4646722...)
>>> amsco_break(amsco_transposition_encipher(sanitise( \
"It is a truth universally acknowledged, that a single man in \
possession of a good fortune, must be in want of a wife. However \
(5, 0, 6, 1, 3, 4, 2): ['fourteen'], \
(6, 1, 0, 4, 5, 3, 2): ['keyword']}, \
patterns=[(1, 2), (2, 1)], fitness=Ptrigrams) # doctest: +ELLIPSIS
- (((2, 0, 5, 3, 1, 4, 6), (2, 1)), -997.0129085...)
+ (((2, 0, 5, 3, 1, 4, 6), (2, 1), <AmscoFillStyle.continuous: 1>), -997.0129085...)
"""
with Pool() as pool:
helper_args = [(message, trans, pattern, fillstyle, fitness)
- for trans in translist.keys()
+ for trans in translist
for pattern in patterns
for fillstyle in fillstyles]
# Gotcha: the helper function here needs to be defined at the top level
def plot_frequency_histogram(freqs, sort_key=None):
- x = range(len(freqs.keys()))
- y = [freqs[l] for l in sorted(freqs.keys(), key=sort_key)]
+ x = range(len(freqs))
+ y = [freqs[l] for l in sorted(freqs, key=sort_key)]
f = plt.figure()
ax = f.add_axes([0.1, 0.1, 0.9, 0.9])
ax.bar(x, y, align='center')
ax.set_xticks(x)
- ax.set_xticklabels(sorted(freqs.keys(), key=sort_key))
+ ax.set_xticklabels(sorted(freqs, key=sort_key))
f.show()