Done challenge 5
[cipher-tools.git] / 2020-early / 2020-a-challenge2.md
1 ---
2 jupyter:
3 jupytext:
4 formats: ipynb,md
5 text_representation:
6 extension: .md
7 format_name: markdown
8 format_version: '1.2'
9 jupytext_version: 1.3.4
10 kernelspec:
11 display_name: Python 3
12 language: python
13 name: python3
14 ---
15
16 ```python
17 import os,sys,inspect
18 currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
19 parentdir = os.path.dirname(currentdir)
20 sys.path.insert(0,parentdir)
21 ```
22
23 ```python
24 from cipher.caesar import *
25 from cipher.affine import *
26
27 from support.text_prettify import *
28 from support.utilities import *
29 from support.plot_frequency_histogram import *
30 ```
31
32 ```python
33 challenge_number = 2
34 plaintext_a_filename = f'{challenge_number}a.plaintext'
35 plaintext_b_filename = f'{challenge_number}b.plaintext'
36 ciphertext_a_filename = f'{challenge_number}a.ciphertext'
37 ciphertext_b_filename = f'{challenge_number}b.ciphertext'
38 ```
39
40 ```python
41 ca = open(ciphertext_a_filename).read()
42 cb = open(ciphertext_b_filename).read()
43
44 sca = sanitise(ca)
45 pca = letters(ca)
46 pta = depunctuate(ca)
47
48 scb = sanitise(cb)
49 pcb = letters(cb)
50 ptb = depunctuate(cb)
51 ```
52
53 ```python
54 (ma, ca, za), score_a = affine_break(sca)
55 print((ma, ca, za), '\n')
56 pa = repunctuate(affine_decipher(sca, ma, ca, za), pta)
57 print(pa)
58 ```
59
60 ```python
61 open(plaintext_a_filename, 'w').write(pa)
62 ```
63
64 ```python
65 (mb, cb, zb), score_a = affine_break(scb)
66 print((mb, cb, zb), '\n')
67 pb = repunctuate(affine_decipher(scb, mb, cb, zb), ptb)
68 print(pb)
69 ```
70
71 ```python
72 open(plaintext_b_filename, 'w').write(pb)
73 ```
74
75 ```python
76
77 ```