9 jupytext_version: 1.3.4
11 display_name: Python 3
18 currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
19 parentdir = os.path.dirname(currentdir)
20 sys.path.insert(0,parentdir)
24 from cipher.caesar import *
25 from cipher.affine import *
26 from cipher.keyword_cipher import *
28 from support.text_prettify import *
29 from support.utilities import *
30 from support.plot_frequency_histogram import *
36 plaintext_a_filename = f'{challenge_number}a.plaintext'
37 plaintext_b_filename = f'{challenge_number}b.plaintext'
38 ciphertext_a_filename = f'{challenge_number}a.ciphertext'
39 ciphertext_b_filename = f'{challenge_number}b.ciphertext'
43 ca = open(ciphertext_a_filename).read()
44 cb = open(ciphertext_b_filename).read()
56 kshifta, score = caesar_break(sca, fitness=Ptrigrams)
61 pa = caesar_decipher(sca, kshifta)
66 fpa = lcat(tpack(segment(pa)))
71 open(plaintext_a_filename, 'w').write(fpa)
75 fc = collections.Counter(scb)
76 plot_frequency_histogram(fc, sort_key=fc.get)
80 (kwordb, kwrapb), score = keyword_break_mp(scb, fitness=Ptrigrams)
85 kwordb, score = simulated_annealing_break(scb, fitness=Ptrigrams)
90 print(keyword_decipher(cb, kwordb))
94 pb = keyword_decipher(cb, 'heavywater', KeywordWrapAlphabet.from_last)
99 open(plaintext_b_filename, 'w').write(pb)
103 print(keyword_cipher_alphabet_of('heavywater', KeywordWrapAlphabet.from_last))