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 *
27 from cipher.column_transposition import *
28 from cipher.vigenere import *
30 from support.text_prettify import *
31 from support.utilities import *
32 from support.plot_frequency_histogram import *
38 plaintext_a_filename = f'{challenge_number}a.plaintext'
39 plaintext_b_filename = f'{challenge_number}b.plaintext'
40 ciphertext_a_filename = f'{challenge_number}a.ciphertext'
41 ciphertext_b_filename = f'{challenge_number}b.ciphertext'
45 ca = open(ciphertext_a_filename).read()
46 cb = open(ciphertext_b_filename).read()
58 fc = collections.Counter(sca)
59 plot_frequency_histogram(fc, sort_key=fc.get)
63 kworda, score = vigenere_frequency_break(sca, fitness=Ptrigrams)
68 ppa = vigenere_decipher(sca, kworda)
69 pa = repunctuate(ppa, pta)
74 open(plaintext_a_filename, 'w').write(pa)
78 fc = collections.Counter(scb)
79 plot_frequency_histogram(fc, sort_key=fc.get)
83 kcb, score = caesar_break(scb, fitness=Pletters)
88 ccb = caesar_decipher(scb, kcb)
93 (kwordb, fillb, emptyb), score = column_transposition_break_mp(ccb, fitness=Ptrigrams)
94 (kwordb, fillb, emptyb), score
98 pb = column_transposition_decipher(ccb, kwordb, fillcolumnwise=fillb, emptycolumnwise=emptyb)
103 fpb = lcat(tpack(segment(pb)))
108 open(plaintext_b_filename, 'w').write(fpb)
112 transpositions[kwordb]