Updated for challenge 9
[cipher-tools.git] / 2014 / 2014-challenge5.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import os,sys,inspect\n",
10 "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
11 "parentdir = os.path.dirname(currentdir)\n",
12 "sys.path.insert(0,parentdir) \n",
13 "\n",
14 "import matplotlib.pyplot as plt\n",
15 "import pandas as pd\n",
16 "import collections\n",
17 "import string\n",
18 "%matplotlib inline\n",
19 "\n",
20 "from cipher.keyword_cipher import *\n",
21 "from cipher.column_transposition import *\n",
22 "from cipher.railfence import *\n",
23 "from support.utilities import *\n",
24 "from support.text_prettify import *\n",
25 "from support.language_models import *\n",
26 "from support.plot_frequency_histogram import *\n",
27 "\n",
28 "c5a = open('5a.ciphertext').read()\n",
29 "c5b = open('5b.ciphertext').read()"
30 ]
31 },
32 {
33 "cell_type": "code",
34 "execution_count": 2,
35 "metadata": {},
36 "outputs": [
37 {
38 "data": {
39 "text/plain": [
40 "<matplotlib.axes._subplots.AxesSubplot at 0x7fc6513e1a90>"
41 ]
42 },
43 "execution_count": 2,
44 "metadata": {},
45 "output_type": "execute_result"
46 },
47 {
48 "data": {
49 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAD7CAYAAACWq8i5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAGXNJREFUeJzt3X+0XWV95/H3p1B+TAsSNKYsgsZOM1rK+ANSSFdtR6WFgJ2GTpXBtpJxKJkW7KLj9Ec67ZQR6xTbaW0Z23RYkhrUqaLVIa1gmhW11iqYIBQEyuIWZUgWQiT8cLTV4nznj/OkHq7nnPvckHAuyfu11lln7+9+nv3sc+6593P2j3NuqgpJkn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
55 "output_type": "display_data"
56 }
57 ],
58 "source": [
59 "freqs = pd.Series(english_counts)\n",
60 "freqs.plot(kind='bar')"
61 ]
62 },
63 {
64 "cell_type": "code",
65 "execution_count": 3,
66 "metadata": {},
67 "outputs": [
68 {
69 "data": {
70 "text/plain": [
71 "'sssatanuelclaendeeheevrnhtailsltocsoeoanuodoeecaferbetrtenoiiucrwurfaproeercssoeuatulgtematremlieaveieogcelesaeeeyyiuuoaidaosdmdecsshthuhatcnxaererseltunaghanrdtevepisydtaeamcinmrnweoramrvibodsdfdpatimrssietdaospecgracnetblfioeushsmeeirlshmittrlnesehmclssoswfottwnbyteyngeymttgstariixeeedrnasmltwgmildcrtseogohrolsshmawndsstrabndnecfcayehotdornonenecatneavoeaatehercyrighsayrefsooatemncwtkaaawndadmsllnnnlutfoeeenoyoewtmanrrsxhvorolhisfunnthaeeofolphebaatmnornoeodnvtphnoetedeaeonphpaeuratvhndetahrahpoorsefovddsttpsvgraaatodsuryidovtrelerltmemdheoarshoarrrerxisgeifawfaiyidusiyieeesotkeaelatresntifemteiaighaceiondktkitteaeanecnndictnedddenstsheanrtamneahshidaocnuissctehslnlectheetlltidlcttnpnmcvsvnositdaelxpihsfattysfoedcmwhtebaachertaigriuirtngiaphetrowehwswaacmgcouwoogoegsmtarteeiemvayinogstitagblncstcycolretedarehopnebyegwcteetlteyeteenansafmo'"
72 ]
73 },
74 "execution_count": 3,
75 "metadata": {},
76 "output_type": "execute_result"
77 }
78 ],
79 "source": [
80 "c5bs = sanitise(c5b)\n",
81 "c5bs"
82 ]
83 },
84 {
85 "cell_type": "code",
86 "execution_count": 4,
87 "metadata": {},
88 "outputs": [
89 {
90 "data": {
91 "text/plain": [
92 "(('seabird', <KeywordWrapAlphabet.from_largest: 3>), -1255.0542494109186)"
93 ]
94 },
95 "execution_count": 4,
96 "metadata": {},
97 "output_type": "execute_result"
98 }
99 ],
100 "source": [
101 "key_a, score = keyword_break_mp(c5a)\n",
102 "key_a, score"
103 ]
104 },
105 {
106 "cell_type": "code",
107 "execution_count": 5,
108 "metadata": {},
109 "outputs": [
110 {
111 "name": "stdout",
112 "output_type": "stream",
113 "text": [
114 "harry i cracked that last message for myself and noticed something really odd the text said it was\n",
115 "encrypted using a column transposition with keyword seabird but it was enciphered using a rail fence\n",
116 "cipher i can only assume that the text we retrieved was an archive of the original message re\n",
117 "encrypted for safety whoever the flag day associates are they have a pretty sophisticated operation\n",
118 "if they are filing messages like this more like one of the major terrorist groups than the usual\n",
119 "hacker collective the tech guys took a look at the aerial from the boat and they tell me that it is\n",
120 "a drag wire usually used to communicate with a submarine when submerged it carried an acoustic\n",
121 "transducer array as well as a shortwave transmitter and listening gear one thing that puzzles me now\n",
122 "is why we were allowed to find the ship floating at all surely they must have planned to sink her\n",
123 "using the scuttling equipment otherwise what was it for they seem too smart to leave it floating for\n",
124 "us to find any thoughts mark ps just before i sent this the cipher clerk came in with a decrypt of\n",
125 "the attached columnar transposition keyword has length six think it answers some of our questions\n",
126 "about the nautilus system\n"
127 ]
128 }
129 ],
130 "source": [
131 "print(prettify(keyword_decipher(sanitise(c5a), key_a[0], key_a[1])))"
132 ]
133 },
134 {
135 "cell_type": "code",
136 "execution_count": 6,
137 "metadata": {},
138 "outputs": [
139 {
140 "data": {
141 "text/plain": [
142 "(((3, 2, 4, 1, 5, 0), False, True), -1998.321513226948)"
143 ]
144 },
145 "execution_count": 6,
146 "metadata": {},
147 "output_type": "execute_result"
148 }
149 ],
150 "source": [
151 "key_b, score = column_transposition_break_mp(c5bs)\n",
152 "key_b, score"
153 ]
154 },
155 {
156 "cell_type": "code",
157 "execution_count": 7,
158 "metadata": {},
159 "outputs": [
160 {
161 "name": "stdout",
162 "output_type": "stream",
163 "text": [
164 "phase five seahorse is ready for trials and the nautilus system is fully functional we engaged the\n",
165 "mechanism and lowered the deck to three feet above sealevel approaching the shore by the radar\n",
166 "station at all times signals from their communications were monitored and no sign was given that our\n",
167 "approach had been monitored or even noticed we backed off the deck was raised by two feet and the\n",
168 "approach attempted again once more our incursion was unnoticed overnight we conducted a range of\n",
169 "tests and mapped the radar coverage on three separate occasions there seems to have been a flurry of\n",
170 "activity and our modeling suggests that the ships masts may have triggered brief alarms on all\n",
171 "occasions the automatic dive systems cut incorrectly lowering the decks to sealevel and the alarms\n",
172 "were cancelled the seahorse deployment system will be fully mounted tonight and we will conduct a\n",
173 "battery of tests on the deployment and emergency recovery systems over the next two nights assuming\n",
174 "that sea and air traffic remains low xxxx\n"
175 ]
176 }
177 ],
178 "source": [
179 "print(prettify(column_transposition_decipher(sanitise(c5bs), key_b[0], \n",
180 " fillcolumnwise=key_b[1], \n",
181 " emptycolumnwise=key_b[2])))"
182 ]
183 },
184 {
185 "cell_type": "code",
186 "execution_count": 8,
187 "metadata": {},
188 "outputs": [
189 {
190 "data": {
191 "text/plain": [
192 "(((3, 2, 4, 1, 5, 0), False, True), -2821.4971440358026)"
193 ]
194 },
195 "execution_count": 8,
196 "metadata": {},
197 "output_type": "execute_result"
198 }
199 ],
200 "source": [
201 "key_b, score = column_transposition_break_mp(c5bs, fitness=Ptrigrams)\n",
202 "key_b, score"
203 ]
204 },
205 {
206 "cell_type": "code",
207 "execution_count": 9,
208 "metadata": {},
209 "outputs": [
210 {
211 "name": "stdout",
212 "output_type": "stream",
213 "text": [
214 "phase five seahorse is ready for trials and the nautilus system is fully functional we engaged the\n",
215 "mechanism and lowered the deck to three feet above sealevel approaching the shore by the radar\n",
216 "station at all times signals from their communications were monitored and no sign was given that our\n",
217 "approach had been monitored or even noticed we backed off the deck was raised by two feet and the\n",
218 "approach attempted again once more our incursion was unnoticed overnight we conducted a range of\n",
219 "tests and mapped the radar coverage on three separate occasions there seems to have been a flurry of\n",
220 "activity and our modeling suggests that the ships masts may have triggered brief alarms on all\n",
221 "occasions the automatic dive systems cut incorrectly lowering the decks to sealevel and the alarms\n",
222 "were cancelled the seahorse deployment system will be fully mounted tonight and we will conduct a\n",
223 "battery of tests on the deployment and emergency recovery systems over the next two nights assuming\n",
224 "that sea and air traffic remains low xxxx\n"
225 ]
226 }
227 ],
228 "source": [
229 "print(prettify(column_transposition_decipher(c5bs, key_b[0], \n",
230 " fillcolumnwise=key_b[1], \n",
231 " emptycolumnwise=key_b[2])))"
232 ]
233 },
234 {
235 "cell_type": "code",
236 "execution_count": 10,
237 "metadata": {},
238 "outputs": [
239 {
240 "data": {
241 "text/plain": [
242 "['tokens',\n",
243 " 'trials',\n",
244 " 'tricks',\n",
245 " 'tromps',\n",
246 " 'umiaks',\n",
247 " 'unfair',\n",
248 " 'urbans',\n",
249 " 'urgent',\n",
250 " 'vocals',\n",
251 " 'womans',\n",
252 " 'womens',\n",
253 " 'wreaks',\n",
254 " 'wrecks',\n",
255 " 'yokels',\n",
256 " 'ricardo',\n",
257 " 'sneaker',\n",
258 " 'speaker',\n",
259 " 'tobagos',\n",
260 " 'trebles',\n",
261 " 'woolens',\n",
262 " 'sneakers',\n",
263 " 'speakers',\n",
264 " 'speedier',\n",
265 " 'tobaccos',\n",
266 " 'together',\n",
267 " 'treaties',\n",
268 " 'treatise',\n",
269 " 'trollops',\n",
270 " 'unedited',\n",
271 " 'woollens',\n",
272 " 'wreckers',\n",
273 " 'treatises',\n",
274 " 'triteness',\n",
275 " 'usherette',\n",
276 " 'woodcocks',\n",
277 " 'tritenesss',\n",
278 " 'usherettes']"
279 ]
280 },
281 "execution_count": 10,
282 "metadata": {},
283 "output_type": "execute_result"
284 }
285 ],
286 "source": [
287 "transpositions[key_b[0]]"
288 ]
289 },
290 {
291 "cell_type": "code",
292 "execution_count": null,
293 "metadata": {},
294 "outputs": [],
295 "source": []
296 }
297 ],
298 "metadata": {
299 "kernelspec": {
300 "display_name": "Python 3",
301 "language": "python",
302 "name": "python3"
303 },
304 "language_info": {
305 "codemirror_mode": {
306 "name": "ipython",
307 "version": 3
308 },
309 "file_extension": ".py",
310 "mimetype": "text/x-python",
311 "name": "python",
312 "nbconvert_exporter": "python",
313 "pygments_lexer": "ipython3",
314 "version": "3.6.3"
315 }
316 },
317 "nbformat": 4,
318 "nbformat_minor": 1
319 }