Updated for challenge 9
[cipher-tools.git] / 2017 / 2017-challenge3.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 2,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import os,sys,inspect, collections\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 "%matplotlib inline\n",
16 "\n",
17 "from cipher.caesar import *\n",
18 "from cipher.affine import *\n",
19 "from cipher.polybius import *\n",
20 "from support.text_prettify import *\n",
21 "from support.language_models import *\n",
22 "\n",
23 "ca = open('3a.ciphertext').read()\n",
24 "cb = open('3b.ciphertext').read()"
25 ]
26 },
27 {
28 "cell_type": "code",
29 "execution_count": 3,
30 "metadata": {},
31 "outputs": [
32 {
33 "data": {
34 "text/plain": [
35 "(24, -2521.8122372384537)"
36 ]
37 },
38 "execution_count": 3,
39 "metadata": {},
40 "output_type": "execute_result"
41 }
42 ],
43 "source": [
44 "key_a, score = caesar_break(ca)\n",
45 "key_a, score"
46 ]
47 },
48 {
49 "cell_type": "code",
50 "execution_count": 4,
51 "metadata": {
52 "scrolled": true
53 },
54 "outputs": [
55 {
56 "name": "stdout",
57 "output_type": "stream",
58 "text": [
59 "KETQEK,\n",
60 "I HBYOUBH AYKG KYTG ELYOH CBEH QYO AEIZ IR HBG BYAFIHED, ERZ UIVGR CBEH BEA BEFFGRGZ I HBIRW I IH CYODZ LG UYYZ HY CYTW HYUGHBGT.\n",
61 "\n",
62 "ORNYTHOREHGDQ IH AGGKA HBEH I EK RYH HBG YRDQ YRG HTQIRU HY NIRZ HBG LYYW. HBGTG IA E HBTIVIRU LDESW KETWGH EKYRU LILDIYFBIDGA NYT ERQHBIRU EA YDZ EA HBIA. IH IA VGTQ VEDOELDG ERZ IN HBG LYYW ZIAEFFGETA IRHY HBG ABEZYCQ CYTDZ YN FTIVEHG DILTETIGA CG KIUBH RYH AGG IH EUEIR NYT SGRHOTIGA AY IH IA TGEDDQ IKFYTHERH CG UGH HY IH NITAH.\n",
63 "\n",
64 "HESIHOA SDGETDQ CERHGZ HY KEWG IH ZINNISODH HY EAAGKLDG HBG GRHITG ZYSOKGRH, AY BG BEZ IH BIZZGR EH E ROKLGT YN AIHGA ETYORZ HBG ERSIGRH CYTDZ. HBG LTIHIAB DILTETQ ZGSIZGZ HY AGRZ AYKGYRG HY HTQ HY NIRZ EDD HBG FIGSGA. HBGIT GJFGTHA NIUOTGZ HBG SBEFHGTA CGTG DIWGDQ HY LG GRSTQFHGZ HYY AY, UIVGR KQ LESWUTYORZ, HBGQ EAWGZ KG HY UY. HBGQ CGTG TIUBH YN SYOTAG, HBG NITAH SBEFHGT CEA ZIAUOIAGZ OAIRU E SEGAET ABINH ERZ HBG AGSYRZ LQ E ASQHEDG SIFBGT, ERZ I EK LGUIRRIRU HY CYRZGT CBEH YHBGT SIFBGTA HESIHOA KIUBH SBEDDGRUG OA CIHB. EA NET EA CG WRYC HBG TYKERA CYODZ RYH BEVG BEZ HBEH KERQ HY SBYYAG NTYK. I AOFFYAG BG KIUBH BEVG WRYCR ELYOH AYKG NYTK YN HBG FYDQLIOA SIFBGT.\n",
65 "\n",
66 "HBG ZYSOKGRHA I BEVG NYORZ AY NET (HESIHOA DEAH HGAHEKGRH ERZ SBEFHGTA YRG ERZ HCY YN BIA BIZZGR LYYW) GESB UIVG E SDOG HY HBG DYSEHIYR YN HBG RGJH YRG, ERZ EA AYYR EA HBGQ DGH KG YOH YN BYAFIHED I FDER HY HTQ HY DYSEHG HBG HBITZ SBEFHGT, CBISB HESIHOA HGDDA OA IA BIZZGR YR HBG IADG YN HBYTRA. HBGTG ETG AGVGTED FDESGA IR HBG ERSIGRH CYTDZ HBEH HBIA KIUBH TGNGT HY, LOH I BEVG E FTGHHQ UYYZ IZGE YN CBGTG IH KIUBH LG.\n",
67 "\n",
68 "IN I HBIRW YN ERQHBIRU GDAG I CIDD UGH IH HY QYO, ERZ EA TGMOGAHGZ I CIDD SYFQ IR QYOT NTIGRZ BETTQ. I AOUUGAH CG HIUBHGR AGSOTIHQ E DIHHDG. KEQLG IN CG LDYSW YOT SIFBGT HGJHA DIWG HBG GJFGTHA IH CIDD FOH YNN SEAOED IRHGTSGFHA. HBG FGYFDG CG ETG OF EUEIRAH ETG ORDIWGDQ HY LG ZGHGTTGZ LQ KOSB, LOH CG ZYR'H CERH HY IRVIHG GJHTE IRHGTDYFGTA HY HBG FETHQ.\n",
69 "\n",
70 "LQ HBG CEQ, KQ NTIGRZ IR HBG AYOW HYDZ KG HBEH BG KGH YRG YN QYOT EUGRHA CBY CEA EAWIRU IN BG WRGC CBGTG I CEA, CBISB AGGKA E LIH YZZ UIVGR HBEH QYO WRYC I EK AHOSW BGTG. CEA HBEH POAH HY HBTYC YOT TIVEDA YNN HBG ASGRH?\n",
71 "\n",
72 "EDD HBG LGAH,\n",
73 "\n",
74 "PYZIG\n"
75 ]
76 }
77 ],
78 "source": [
79 "print(caesar_decipher(ca, key_a))"
80 ]
81 },
82 {
83 "cell_type": "code",
84 "execution_count": 5,
85 "metadata": {},
86 "outputs": [
87 {
88 "data": {
89 "text/plain": [
90 "((7, 22, True), -2146.240223193519)"
91 ]
92 },
93 "execution_count": 5,
94 "metadata": {},
95 "output_type": "execute_result"
96 }
97 ],
98 "source": [
99 "(m_a, a_a, o_a), score = affine_break(ca)\n",
100 "(m_a, a_a, o_a), score"
101 ]
102 },
103 {
104 "cell_type": "code",
105 "execution_count": 6,
106 "metadata": {},
107 "outputs": [
108 {
109 "name": "stdout",
110 "output_type": "stream",
111 "text": [
112 "MARYAM,\n",
113 "I THOUGHT SOME MORE ABOUT WHAT YOU SAID IN THE HOSPITAL, AND GIVEN WHAT HAS HAPPENED I THINK I IT WOULD BE GOOD TO WORK TOGETHER.\n",
114 "\n",
115 "UNFORTUNATELY IT SEEMS THAT I AM NOT THE ONLY ONE TRYING TO FIND THE BOOK. THERE IS A THRIVING BLACK MARKET AMONG BIBLIOPHILES FOR ANYTHING AS OLD AS THIS. IT IS VERY VALUABLE AND IF THE BOOK DISAPPEARS INTO THE SHADOWY WORLD OF PRIVATE LIBRARIES WE MIGHT NOT SEE IT AGAIN FOR CENTURIES SO IT IS REALLY IMPORTANT WE GET TO IT FIRST.\n",
116 "\n",
117 "TACITUS CLEARLY WANTED TO MAKE IT DIFFICULT TO ASSEMBLE THE ENTIRE DOCUMENT, SO HE HAD IT HIDDEN AT A NUMBER OF SITES AROUND THE ANCIENT WORLD. THE BRITISH LIBRARY DECIDED TO SEND SOMEONE TO TRY TO FIND ALL THE PIECES. THEIR EXPERTS FIGURED THE CHAPTERS WERE LIKELY TO BE ENCRYPTED TOO SO, GIVEN MY BACKGROUND, THEY ASKED ME TO GO. THEY WERE RIGHT OF COURSE, THE FIRST CHAPTER WAS DISGUISED USING A CAESAR SHIFT AND THE SECOND BY A SCYTALE CIPHER, AND I AM BEGINNING TO WONDER WHAT OTHER CIPHERS TACITUS MIGHT CHALLENGE US WITH. AS FAR AS WE KNOW THE ROMANS WOULD NOT HAVE HAD THAT MANY TO CHOOSE FROM. I SUPPOSE HE MIGHT HAVE KNOWN ABOUT SOME FORM OF THE POLYBIUS CIPHER.\n",
118 "\n",
119 "THE DOCUMENTS I HAVE FOUND SO FAR (TACITUS LAST TESTAMENT AND CHAPTERS ONE AND TWO OF HIS HIDDEN BOOK) EACH GIVE A CLUE TO THE LOCATION OF THE NEXT ONE, AND AS SOON AS THEY LET ME OUT OF HOSPITAL I PLAN TO TRY TO LOCATE THE THIRD CHAPTER, WHICH TACITUS TELLS US IS HIDDEN ON THE ISLE OF THORNS. THERE ARE SEVERAL PLACES IN THE ANCIENT WORLD THAT THIS MIGHT REFER TO, BUT I HAVE A PRETTY GOOD IDEA OF WHERE IT MIGHT BE.\n",
120 "\n",
121 "IF I THINK OF ANYTHING ELSE I WILL GET IT TO YOU, AND AS REQUESTED I WILL COPY IN YOUR FRIEND HARRY. I SUGGEST WE TIGHTEN SECURITY A LITTLE. MAYBE IF WE BLOCK OUR CIPHER TEXTS LIKE THE EXPERTS IT WILL PUT OFF CASUAL INTERCEPTS. THE PEOPLE WE ARE UP AGAINST ARE UNLIKELY TO BE DETERRED BY MUCH, BUT WE DON'T WANT TO INVITE EXTRA INTERLOPERS TO THE PARTY.\n",
122 "\n",
123 "BY THE WAY, MY FRIEND IN THE SOUK TOLD ME THAT HE MET ONE OF YOUR AGENTS WHO WAS ASKING IF HE KNEW WHERE I WAS, WHICH SEEMS A BIT ODD GIVEN THAT YOU KNOW I AM STUCK HERE. WAS THAT JUST TO THROW OUR RIVALS OFF THE SCENT?\n",
124 "\n",
125 "ALL THE BEST,\n",
126 "\n",
127 "JODIE\n"
128 ]
129 }
130 ],
131 "source": [
132 "print(affine_decipher(ca, m_a, a_a, o_a))"
133 ]
134 },
135 {
136 "cell_type": "code",
137 "execution_count": 7,
138 "metadata": {},
139 "outputs": [
140 {
141 "data": {
142 "text/plain": [
143 "2163"
144 ]
145 },
146 "execution_count": 7,
147 "metadata": {},
148 "output_type": "execute_result"
149 }
150 ],
151 "source": [
152 "open('3a.plaintext', 'w').write(affine_decipher(ca, m_a, a_a, o_a))"
153 ]
154 },
155 {
156 "cell_type": "code",
157 "execution_count": 8,
158 "metadata": {},
159 "outputs": [
160 {
161 "data": {
162 "text/plain": [
163 "Counter({'c': 1064, 'd': 1368, 'l': 756, 'm': 566, 'x': 1092})"
164 ]
165 },
166 "execution_count": 8,
167 "metadata": {},
168 "output_type": "execute_result"
169 }
170 ],
171 "source": [
172 "collections.Counter(sanitise(cb))"
173 ]
174 },
175 {
176 "cell_type": "code",
177 "execution_count": 9,
178 "metadata": {},
179 "outputs": [
180 {
181 "data": {
182 "text/plain": [
183 "[('xm', 317),\n",
184 " ('dd', 240),\n",
185 " ('xx', 197),\n",
186 " ('ld', 185),\n",
187 " ('cd', 177),\n",
188 " ('dl', 159),\n",
189 " ('dc', 155),\n",
190 " ('cc', 154),\n",
191 " ('lc', 133),\n",
192 " ('xd', 105),\n",
193 " ('cx', 92),\n",
194 " ('xc', 88),\n",
195 " ('dm', 70),\n",
196 " ('cl', 58),\n",
197 " ('ml', 51),\n",
198 " ('cm', 48),\n",
199 " ('ll', 45),\n",
200 " ('lx', 41),\n",
201 " ('md', 36),\n",
202 " ('xl', 27),\n",
203 " ('mx', 27),\n",
204 " ('lm', 12),\n",
205 " ('mc', 5),\n",
206 " ('dx', 1)]"
207 ]
208 },
209 "execution_count": 9,
210 "metadata": {},
211 "output_type": "execute_result"
212 }
213 ],
214 "source": [
215 "collections.Counter(chunks(sanitise(cb), 2)).most_common()"
216 ]
217 },
218 {
219 "cell_type": "code",
220 "execution_count": 10,
221 "metadata": {
222 "scrolled": true
223 },
224 "outputs": [
225 {
226 "data": {
227 "text/plain": [
228 "'etoainhsrdlumwycfgpbvkxqz'"
229 ]
230 },
231 "execution_count": 10,
232 "metadata": {},
233 "output_type": "execute_result"
234 }
235 ],
236 "source": [
237 "ltrs = [p[0] for p in english_counts.most_common() if p[0] != 'j']\n",
238 "cat(ltrs)"
239 ]
240 },
241 {
242 "cell_type": "code",
243 "execution_count": 11,
244 "metadata": {},
245 "outputs": [
246 {
247 "data": {
248 "text/plain": [
249 "'etoanisrhdlufcmwgybpvkxqz'"
250 ]
251 },
252 "execution_count": 11,
253 "metadata": {},
254 "output_type": "execute_result"
255 }
256 ],
257 "source": [
258 "ltrs = cat(p[0] for p in \n",
259 " collections.Counter(sanitise(open('1b.plaintext').read() + open('2b.plaintext').read())).most_common()\n",
260 " if p[0] != 'j')\n",
261 "ltrs"
262 ]
263 },
264 {
265 "cell_type": "code",
266 "execution_count": 12,
267 "metadata": {},
268 "outputs": [],
269 "source": [
270 "ltrs = 'etoanisrhdlufcmwgybpvkxqz'"
271 ]
272 },
273 {
274 "cell_type": "code",
275 "execution_count": 13,
276 "metadata": {},
277 "outputs": [
278 {
279 "data": {
280 "text/plain": [
281 "['xm',\n",
282 " 'dd',\n",
283 " 'xx',\n",
284 " 'ld',\n",
285 " 'cd',\n",
286 " 'dl',\n",
287 " 'dc',\n",
288 " 'cc',\n",
289 " 'lc',\n",
290 " 'xd',\n",
291 " 'cx',\n",
292 " 'xc',\n",
293 " 'dm',\n",
294 " 'cl',\n",
295 " 'ml',\n",
296 " 'cm',\n",
297 " 'll',\n",
298 " 'lx',\n",
299 " 'md',\n",
300 " 'xl',\n",
301 " 'mx',\n",
302 " 'lm',\n",
303 " 'mc',\n",
304 " 'dx']"
305 ]
306 },
307 "execution_count": 13,
308 "metadata": {},
309 "output_type": "execute_result"
310 }
311 ],
312 "source": [
313 "prs = [p[0] for p in collections.Counter(chunks(sanitise(cb), 2)).most_common()]\n",
314 "prs"
315 ]
316 },
317 {
318 "cell_type": "code",
319 "execution_count": 14,
320 "metadata": {},
321 "outputs": [
322 {
323 "data": {
324 "text/plain": [
325 "24"
326 ]
327 },
328 "execution_count": 14,
329 "metadata": {},
330 "output_type": "execute_result"
331 }
332 ],
333 "source": [
334 "len(prs)"
335 ]
336 },
337 {
338 "cell_type": "code",
339 "execution_count": 15,
340 "metadata": {},
341 "outputs": [
342 {
343 "data": {
344 "text/plain": [
345 "{'cc': 'R',\n",
346 " 'cd': 'N',\n",
347 " 'cl': 'C',\n",
348 " 'cm': 'W',\n",
349 " 'cx': 'L',\n",
350 " 'dc': 'S',\n",
351 " 'dd': 'T',\n",
352 " 'dl': 'I',\n",
353 " 'dm': 'F',\n",
354 " 'dx': 'Q',\n",
355 " 'lc': 'H',\n",
356 " 'ld': 'A',\n",
357 " 'll': 'G',\n",
358 " 'lm': 'K',\n",
359 " 'lx': 'Y',\n",
360 " 'mc': 'X',\n",
361 " 'md': 'B',\n",
362 " 'ml': 'M',\n",
363 " 'mx': 'V',\n",
364 " 'xc': 'U',\n",
365 " 'xd': 'D',\n",
366 " 'xl': 'P',\n",
367 " 'xm': 'E',\n",
368 " 'xx': 'O'}"
369 ]
370 },
371 "execution_count": 15,
372 "metadata": {},
373 "output_type": "execute_result"
374 }
375 ],
376 "source": [
377 "trans = {pr[1]: pr[0].upper() for pr in zip(ltrs, prs)}\n",
378 "trans"
379 ]
380 },
381 {
382 "cell_type": "code",
383 "execution_count": 16,
384 "metadata": {},
385 "outputs": [
386 {
387 "data": {
388 "text/plain": [
389 "['ml',\n",
390 " 'lc',\n",
391 " 'ld',\n",
392 " 'cx',\n",
393 " 'xm',\n",
394 " 'ld',\n",
395 " 'dd',\n",
396 " 'ld',\n",
397 " 'dc',\n",
398 " 'dd',\n",
399 " 'dl',\n",
400 " 'dm',\n",
401 " 'xm',\n",
402 " 'dd',\n",
403 " 'lc',\n",
404 " 'xx',\n",
405 " 'dd',\n",
406 " 'dc',\n",
407 " 'dm',\n",
408 " 'xm',\n",
409 " 'dd',\n",
410 " 'cd',\n",
411 " 'cc',\n",
412 " 'ld',\n",
413 " 'dm',\n",
414 " 'dc',\n",
415 " 'dc',\n",
416 " 'xm',\n",
417 " 'dd',\n",
418 " 'dm',\n",
419 " 'cm',\n",
420 " 'dd',\n",
421 " 'lc',\n",
422 " 'xm',\n",
423 " 'lx',\n",
424 " 'ld',\n",
425 " 'cc',\n",
426 " 'xx',\n",
427 " 'cx',\n",
428 " 'xl',\n",
429 " 'xx',\n",
430 " 'dd',\n",
431 " 'dd',\n",
432 " 'cx',\n",
433 " 'xm',\n",
434 " 'ml',\n",
435 " 'ld',\n",
436 " 'dd',\n",
437 " 'lc',\n",
438 " 'xl',\n",
439 " 'cd',\n",
440 " 'dm',\n",
441 " 'xd',\n",
442 " 'ld',\n",
443 " 'xc',\n",
444 " 'xc',\n",
445 " 'xx',\n",
446 " 'xx',\n",
447 " 'dd',\n",
448 " 'ml',\n",
449 " 'xx',\n",
450 " 'dd',\n",
451 " 'cx',\n",
452 " 'ld',\n",
453 " 'cc',\n",
454 " 'll',\n",
455 " 'dc',\n",
456 " 'dd',\n",
457 " 'dl',\n",
458 " 'xm',\n",
459 " 'xm',\n",
460 " 'dd',\n",
461 " 'lc',\n",
462 " 'xm',\n",
463 " 'lc',\n",
464 " 'xx',\n",
465 " 'xd',\n",
466 " 'cc',\n",
467 " 'xm',\n",
468 " 'ld',\n",
469 " 'dd',\n",
470 " 'lc',\n",
471 " 'xm',\n",
472 " 'dl',\n",
473 " 'dd',\n",
474 " 'lc',\n",
475 " 'xm',\n",
476 " 'dd',\n",
477 " 'dl',\n",
478 " 'cd',\n",
479 " 'cd',\n",
480 " 'cm',\n",
481 " 'dc',\n",
482 " 'cc',\n",
483 " 'cd',\n",
484 " 'dl',\n",
485 " 'dd',\n",
486 " 'lc',\n",
487 " 'xm',\n",
488 " 'dd',\n",
489 " 'xx',\n",
490 " 'xc',\n",
491 " 'dd',\n",
492 " 'ld',\n",
493 " 'xc',\n",
494 " 'xx',\n",
495 " 'cx',\n",
496 " 'xx',\n",
497 " 'xl',\n",
498 " 'ld',\n",
499 " 'cx',\n",
500 " 'ld',\n",
501 " 'dd',\n",
502 " 'md',\n",
503 " 'dd',\n",
504 " 'cd',\n",
505 " 'cd',\n",
506 " 'mx',\n",
507 " 'xm',\n",
508 " 'dl',\n",
509 " 'xc',\n",
510 " 'cd',\n",
511 " 'cl',\n",
512 " 'xm',\n",
513 " 'dd',\n",
514 " 'lc',\n",
515 " 'xm',\n",
516 " 'lc',\n",
517 " 'dm',\n",
518 " 'll',\n",
519 " 'xm',\n",
520 " 'cc',\n",
521 " 'dm',\n",
522 " 'cl',\n",
523 " 'xm',\n",
524 " 'dl',\n",
525 " 'ld',\n",
526 " 'xc',\n",
527 " 'xx',\n",
528 " 'cx',\n",
529 " 'xd',\n",
530 " 'ld',\n",
531 " 'dc',\n",
532 " 'xx',\n",
533 " 'xd',\n",
534 " 'mx',\n",
535 " 'xx',\n",
536 " 'cc',\n",
537 " 'dd',\n",
538 " 'xx',\n",
539 " 'll',\n",
540 " 'xm',\n",
541 " 'lx',\n",
542 " 'xx',\n",
543 " 'xc',\n",
544 " 'xm',\n",
545 " 'xd',\n",
546 " 'xl',\n",
547 " 'md',\n",
548 " 'lc',\n",
549 " 'ld',\n",
550 " 'dc',\n",
551 " 'xx',\n",
552 " 'dl',\n",
553 " 'cl',\n",
554 " 'md',\n",
555 " 'ml',\n",
556 " 'ld',\n",
557 " 'dd',\n",
558 " 'lc',\n",
559 " 'cd',\n",
560 " 'dm',\n",
561 " 'dd',\n",
562 " 'dd',\n",
563 " 'lc',\n",
564 " 'xm',\n",
565 " 'dc',\n",
566 " 'dm',\n",
567 " 'cm',\n",
568 " 'cm',\n",
569 " 'cd',\n",
570 " 'dl',\n",
571 " 'dd',\n",
572 " 'cd',\n",
573 " 'lx',\n",
574 " 'xx',\n",
575 " 'll',\n",
576 " 'dl',\n",
577 " 'ld',\n",
578 " 'xc',\n",
579 " 'cd',\n",
580 " 'cx',\n",
581 " 'xx',\n",
582 " 'xx',\n",
583 " 'cc',\n",
584 " 'xd',\n",
585 " 'lc',\n",
586 " 'ld',\n",
587 " 'dc',\n",
588 " 'dd',\n",
589 " 'xx',\n",
590 " 'cx',\n",
591 " 'xm',\n",
592 " 'cc',\n",
593 " 'dd',\n",
594 " 'xm',\n",
595 " 'xd',\n",
596 " 'dc',\n",
597 " 'xc',\n",
598 " 'cd',\n",
599 " 'dm',\n",
600 " 'dd',\n",
601 " 'dc',\n",
602 " 'xd',\n",
603 " 'xm',\n",
604 " 'lx',\n",
605 " 'xm',\n",
606 " 'xx',\n",
607 " 'dd',\n",
608 " 'ml',\n",
609 " 'cd',\n",
610 " 'dm',\n",
611 " 'cx',\n",
612 " 'xd',\n",
613 " 'lc',\n",
614 " 'xx',\n",
615 " 'mx',\n",
616 " 'xm',\n",
617 " 'xl',\n",
618 " 'xm',\n",
619 " 'xm',\n",
620 " 'cc',\n",
621 " 'ld',\n",
622 " 'cc',\n",
623 " 'xm',\n",
624 " 'mx',\n",
625 " 'ld',\n",
626 " 'dd',\n",
627 " 'xx',\n",
628 " 'xl',\n",
629 " 'cx',\n",
630 " 'xm',\n",
631 " 'xx',\n",
632 " 'cc',\n",
633 " 'xd',\n",
634 " 'ml',\n",
635 " 'ld',\n",
636 " 'dd',\n",
637 " 'lc',\n",
638 " 'ld',\n",
639 " 'dd',\n",
640 " 'dd',\n",
641 " 'lc',\n",
642 " 'xm',\n",
643 " 'cx',\n",
644 " 'cd',\n",
645 " 'dc',\n",
646 " 'dc',\n",
647 " 'cd',\n",
648 " 'lx',\n",
649 " 'xl',\n",
650 " 'dl',\n",
651 " 'ld',\n",
652 " 'dd',\n",
653 " 'xx',\n",
654 " 'cc',\n",
655 " 'cc',\n",
656 " 'ld',\n",
657 " 'xx',\n",
658 " 'lc',\n",
659 " 'xx',\n",
660 " 'mx',\n",
661 " 'ld',\n",
662 " 'cc',\n",
663 " 'll',\n",
664 " 'dl',\n",
665 " 'xm',\n",
666 " 'xx',\n",
667 " 'cx',\n",
668 " 'ld',\n",
669 " 'dc',\n",
670 " 'xm',\n",
671 " 'xd',\n",
672 " 'dd',\n",
673 " 'lc',\n",
674 " 'xx',\n",
675 " 'dd',\n",
676 " 'dd',\n",
677 " 'lc',\n",
678 " 'xm',\n",
679 " 'ld',\n",
680 " 'xc',\n",
681 " 'xm',\n",
682 " 'cc',\n",
683 " 'ld',\n",
684 " 'ml',\n",
685 " 'xm',\n",
686 " 'dl',\n",
687 " 'xm',\n",
688 " 'dl',\n",
689 " 'xm',\n",
690 " 'xx',\n",
691 " 'xd',\n",
692 " 'ld',\n",
693 " 'cc',\n",
694 " 'll',\n",
695 " 'lc',\n",
696 " 'ld',\n",
697 " 'dc',\n",
698 " 'xc',\n",
699 " 'cd',\n",
700 " 'cl',\n",
701 " 'cl',\n",
702 " 'dm',\n",
703 " 'cc',\n",
704 " 'ld',\n",
705 " 'xc',\n",
706 " 'xx',\n",
707 " 'dd',\n",
708 " 'ld',\n",
709 " 'cd',\n",
710 " 'cc',\n",
711 " 'dc',\n",
712 " 'xx',\n",
713 " 'll',\n",
714 " 'dl',\n",
715 " 'ld',\n",
716 " 'xc',\n",
717 " 'cd',\n",
718 " 'cx',\n",
719 " 'xx',\n",
720 " 'xx',\n",
721 " 'dl',\n",
722 " 'dl',\n",
723 " 'xx',\n",
724 " 'cc',\n",
725 " 'll',\n",
726 " 'xm',\n",
727 " 'xd',\n",
728 " 'dd',\n",
729 " 'cd',\n",
730 " 'cm',\n",
731 " 'cx',\n",
732 " 'xx',\n",
733 " 'cc',\n",
734 " 'dd',\n",
735 " 'lx',\n",
736 " 'xx',\n",
737 " 'cx',\n",
738 " 'dc',\n",
739 " 'xm',\n",
740 " 'ld',\n",
741 " 'cc',\n",
742 " 'lx',\n",
743 " 'cd',\n",
744 " 'dl',\n",
745 " 'cl',\n",
746 " 'xx',\n",
747 " 'dd',\n",
748 " 'ld',\n",
749 " 'cd',\n",
750 " 'cc',\n",
751 " 'xx',\n",
752 " 'xl',\n",
753 " 'cd',\n",
754 " 'dm',\n",
755 " 'dd',\n",
756 " 'dd',\n",
757 " 'lc',\n",
758 " 'xm',\n",
759 " 'cm',\n",
760 " 'cx',\n",
761 " 'xx',\n",
762 " 'cc',\n",
763 " 'cc',\n",
764 " 'xm',\n",
765 " 'xd',\n",
766 " 'xd',\n",
767 " 'ld',\n",
768 " 'dc',\n",
769 " 'cm',\n",
770 " 'cd',\n",
771 " 'dc',\n",
772 " 'ld',\n",
773 " 'dd',\n",
774 " 'ld',\n",
775 " 'cd',\n",
776 " 'cc',\n",
777 " 'cd',\n",
778 " 'lx',\n",
779 " 'dd',\n",
780 " 'dl',\n",
781 " 'cd',\n",
782 " 'cd',\n",
783 " 'cm',\n",
784 " 'dc',\n",
785 " 'dc',\n",
786 " 'xm',\n",
787 " 'dd',\n",
788 " 'dd',\n",
789 " 'ld',\n",
790 " 'cc',\n",
791 " 'll',\n",
792 " 'xx',\n",
793 " 'dd',\n",
794 " 'dl',\n",
795 " 'xx',\n",
796 " 'cm',\n",
797 " 'ld',\n",
798 " 'cc',\n",
799 " 'dd',\n",
800 " 'cd',\n",
801 " 'ml',\n",
802 " 'lc',\n",
803 " 'ld',\n",
804 " 'xc',\n",
805 " 'lc',\n",
806 " 'dd',\n",
807 " 'lc',\n",
808 " 'xm',\n",
809 " 'ld',\n",
810 " 'xc',\n",
811 " 'xm',\n",
812 " 'cc',\n",
813 " 'ld',\n",
814 " 'lx',\n",
815 " 'xm',\n",
816 " 'cx',\n",
817 " 'cx',\n",
818 " 'ld',\n",
819 " 'dd',\n",
820 " 'ld',\n",
821 " 'dc',\n",
822 " 'dc',\n",
823 " 'dd',\n",
824 " 'ld',\n",
825 " 'cx',\n",
826 " 'cx',\n",
827 " 'dm',\n",
828 " 'cc',\n",
829 " 'xc',\n",
830 " 'cx',\n",
831 " 'xm',\n",
832 " 'xx',\n",
833 " 'dl',\n",
834 " 'lc',\n",
835 " 'cd',\n",
836 " 'ml',\n",
837 " 'dd',\n",
838 " 'lc',\n",
839 " 'xm',\n",
840 " 'dc',\n",
841 " 'xx',\n",
842 " 'mx',\n",
843 " 'xx',\n",
844 " 'll',\n",
845 " 'xm',\n",
846 " 'dd',\n",
847 " 'dl',\n",
848 " 'ld',\n",
849 " 'xl',\n",
850 " 'xm',\n",
851 " 'dc',\n",
852 " 'lc',\n",
853 " 'xx',\n",
854 " 'xd',\n",
855 " 'cx',\n",
856 " 'xm',\n",
857 " 'xx',\n",
858 " 'dl',\n",
859 " 'cc',\n",
860 " 'xm',\n",
861 " 'xd',\n",
862 " 'dd',\n",
863 " 'cd',\n",
864 " 'xd',\n",
865 " 'xm',\n",
866 " 'xc',\n",
867 " 'ld',\n",
868 " 'cm',\n",
869 " 'lc',\n",
870 " 'xm',\n",
871 " 'dl',\n",
872 " 'cd',\n",
873 " 'dm',\n",
874 " 'dl',\n",
875 " 'xx',\n",
876 " 'dl',\n",
877 " 'cl',\n",
878 " 'md',\n",
879 " 'dc',\n",
880 " 'xc',\n",
881 " 'cd',\n",
882 " 'cl',\n",
883 " 'cl',\n",
884 " 'dm',\n",
885 " 'cc',\n",
886 " 'ld',\n",
887 " 'xc',\n",
888 " 'xx',\n",
889 " 'dd',\n",
890 " 'ld',\n",
891 " 'cd',\n",
892 " 'cc',\n",
893 " 'dc',\n",
894 " 'xx',\n",
895 " 'dc',\n",
896 " 'dd',\n",
897 " 'lc',\n",
898 " 'xm',\n",
899 " 'md',\n",
900 " 'lc',\n",
901 " 'xx',\n",
902 " 'xd',\n",
903 " 'cc',\n",
904 " 'cd',\n",
905 " 'ml',\n",
906 " 'dl',\n",
907 " 'ld',\n",
908 " 'dd',\n",
909 " 'ld',\n",
910 " 'cc',\n",
911 " 'll',\n",
912 " 'cd',\n",
913 " 'lx',\n",
914 " 'dd',\n",
915 " 'lc',\n",
916 " 'xm',\n",
917 " 'ld',\n",
918 " 'dl',\n",
919 " 'cd',\n",
920 " 'ml',\n",
921 " 'cc',\n",
922 " 'lc',\n",
923 " 'cd',\n",
924 " 'ml',\n",
925 " 'xm',\n",
926 " 'mx',\n",
927 " 'xm',\n",
928 " 'dl',\n",
929 " 'xm',\n",
930 " 'mx',\n",
931 " 'xm',\n",
932 " 'dl',\n",
933 " 'md',\n",
934 " 'xx',\n",
935 " 'dl',\n",
936 " 'cl',\n",
937 " 'md',\n",
938 " 'lc',\n",
939 " 'xx',\n",
940 " 'dc',\n",
941 " 'ld',\n",
942 " 'dd',\n",
943 " 'dc',\n",
944 " 'dd',\n",
945 " 'dl',\n",
946 " 'xx',\n",
947 " 'ld',\n",
948 " 'dd',\n",
949 " 'cd',\n",
950 " 'dl',\n",
951 " 'dc',\n",
952 " 'xx',\n",
953 " 'cc',\n",
954 " 'xd',\n",
955 " 'ld',\n",
956 " 'dd',\n",
957 " 'dc',\n",
958 " 'xm',\n",
959 " 'xm',\n",
960 " 'cl',\n",
961 " 'dc',\n",
962 " 'cx',\n",
963 " 'ld',\n",
964 " 'lm',\n",
965 " 'xm',\n",
966 " 'cx',\n",
967 " 'md',\n",
968 " 'dd',\n",
969 " 'cd',\n",
970 " 'cl',\n",
971 " 'xm',\n",
972 " 'dd',\n",
973 " 'lc',\n",
974 " 'xx',\n",
975 " 'dd',\n",
976 " 'cd',\n",
977 " 'cc',\n",
978 " 'xm',\n",
979 " 'cd',\n",
980 " 'dl',\n",
981 " 'cl',\n",
982 " 'cd',\n",
983 " 'dl',\n",
984 " 'xm',\n",
985 " 'cd',\n",
986 " 'lx',\n",
987 " 'dd',\n",
988 " 'lc',\n",
989 " 'xm',\n",
990 " 'cx',\n",
991 " 'cd',\n",
992 " 'xc',\n",
993 " 'xx',\n",
994 " 'cx',\n",
995 " 'dd',\n",
996 " 'dl',\n",
997 " 'ld',\n",
998 " 'xl',\n",
999 " 'xm',\n",
1000 " 'dc',\n",
1001 " 'cm',\n",
1002 " 'xm',\n",
1003 " 'cd',\n",
1004 " 'cm',\n",
1005 " 'cx',\n",
1006 " 'xm',\n",
1007 " 'dd',\n",
1008 " 'dm',\n",
1009 " 'dl',\n",
1010 " 'cc',\n",
1011 " 'xm',\n",
1012 " 'xd',\n",
1013 " 'dc',\n",
1014 " 'cd',\n",
1015 " 'cl',\n",
1016 " 'xm',\n",
1017 " 'cd',\n",
1018 " 'cc',\n",
1019 " 'xm',\n",
1020 " 'dc',\n",
1021 " 'lc',\n",
1022 " 'xm',\n",
1023 " 'xx',\n",
1024 " 'xd',\n",
1025 " 'cx',\n",
1026 " 'cd',\n",
1027 " 'mx',\n",
1028 " 'xm',\n",
1029 " 'cd',\n",
1030 " 'dl',\n",
1031 " 'cl',\n",
1032 " 'cd',\n",
1033 " 'cc',\n",
1034 " 'xm',\n",
1035 " 'md',\n",
1036 " 'ld',\n",
1037 " 'dd',\n",
1038 " 'ld',\n",
1039 " 'dc',\n",
1040 " 'xx',\n",
1041 " 'cx',\n",
1042 " 'cx',\n",
1043 " 'dd',\n",
1044 " 'dl',\n",
1045 " 'xm',\n",
1046 " 'xx',\n",
1047 " 'xc',\n",
1048 " 'lc',\n",
1049 " 'xm',\n",
1050 " 'dl',\n",
1051 " 'md',\n",
1052 " 'xl',\n",
1053 " 'dm',\n",
1054 " 'dd',\n",
1055 " 'dd',\n",
1056 " 'lc',\n",
1057 " 'ld',\n",
1058 " 'dc',\n",
1059 " 'xx',\n",
1060 " 'xc',\n",
1061 " 'dd',\n",
1062 " 'dd',\n",
1063 " 'lc',\n",
1064 " 'dl',\n",
1065 " 'xm',\n",
1066 " 'xx',\n",
1067 " 'dd',\n",
1068 " 'xm',\n",
1069 " 'cc',\n",
1070 " 'xm',\n",
1071 " 'xd',\n",
1072 " 'dd',\n",
1073 " 'cd',\n",
1074 " 'dm',\n",
1075 " 'cc',\n",
1076 " 'xd',\n",
1077 " 'xm',\n",
1078 " 'dl',\n",
1079 " 'cl',\n",
1080 " 'ld',\n",
1081 " 'cc',\n",
1082 " 'xm',\n",
1083 " 'dd',\n",
1084 " 'lc',\n",
1085 " 'xm',\n",
1086 " 'xm',\n",
1087 " 'cl',\n",
1088 " 'cm',\n",
1089 " 'ld',\n",
1090 " 'dl',\n",
1091 " 'xm',\n",
1092 " 'dc',\n",
1093 " 'xm',\n",
1094 " 'cc',\n",
1095 " 'dd',\n",
1096 " 'ld',\n",
1097 " 'dl',\n",
1098 " 'xm',\n",
1099 " 'dc',\n",
1100 " 'md',\n",
1101 " 'dc',\n",
1102 " 'dd',\n",
1103 " 'xm',\n",
1104 " 'cl',\n",
1105 " 'cd',\n",
1106 " 'lx',\n",
1107 " 'dc',\n",
1108 " 'xm',\n",
1109 " 'xc',\n",
1110 " 'dm',\n",
1111 " 'dl',\n",
1112 " 'xm',\n",
1113 " 'xc',\n",
1114 " 'cd',\n",
1115 " 'cl',\n",
1116 " 'cl',\n",
1117 " 'dm',\n",
1118 " 'cc',\n",
1119 " 'ld',\n",
1120 " 'xc',\n",
1121 " 'xx',\n",
1122 " 'dd',\n",
1123 " 'ld',\n",
1124 " 'cd',\n",
1125 " 'cc',\n",
1126 " 'dd',\n",
1127 " 'lc',\n",
1128 " 'xm',\n",
1129 " 'xc',\n",
1130 " 'xx',\n",
1131 " 'xm',\n",
1132 " 'dc',\n",
1133 " 'xx',\n",
1134 " 'dl',\n",
1135 " 'xc',\n",
1136 " 'ld',\n",
1137 " 'cm',\n",
1138 " 'lc',\n",
1139 " 'xm',\n",
1140 " 'dl',\n",
1141 " 'cm',\n",
1142 " 'xm',\n",
1143 " 'dl',\n",
1144 " 'lc',\n",
1145 " 'xx',\n",
1146 " 'cm',\n",
1147 " 'dc',\n",
1148 " 'cl',\n",
1149 " 'cd',\n",
1150 " 'dl',\n",
1151 " 'xm',\n",
1152 " 'dd',\n",
1153 " 'lc',\n",
1154 " 'xx',\n",
1155 " 'cc',\n",
1156 " 'dl',\n",
1157 " 'cd',\n",
1158 " 'xx',\n",
1159 " 'xd',\n",
1160 " 'dc',\n",
1161 " 'lc',\n",
1162 " 'xx',\n",
1163 " 'xd',\n",
1164 " 'xm',\n",
1165 " 'cc',\n",
1166 " 'xx',\n",
1167 " 'xl',\n",
1168 " 'cx',\n",
1169 " 'xm',\n",
1170 " 'xd',\n",
1171 " 'dd',\n",
1172 " 'lc',\n",
1173 " 'xm',\n",
1174 " 'xm',\n",
1175 " 'cl',\n",
1176 " 'cm',\n",
1177 " 'ld',\n",
1178 " 'dl',\n",
1179 " 'xm',\n",
1180 " 'dd',\n",
1181 " 'cd',\n",
1182 " 'lx',\n",
1183 " 'dm',\n",
1184 " 'cc',\n",
1185 " 'xc',\n",
1186 " 'dd',\n",
1187 " 'ld',\n",
1188 " 'cd',\n",
1189 " 'cc',\n",
1190 " 'dc',\n",
1191 " 'xm',\n",
1192 " 'xc',\n",
1193 " 'dm',\n",
1194 " 'dl',\n",
1195 " 'xm',\n",
1196 " 'cx',\n",
1197 " 'md',\n",
1198 " 'xx',\n",
1199 " 'cc',\n",
1200 " 'xd',\n",
1201 " 'ld',\n",
1202 " 'dd',\n",
1203 " 'dc',\n",
1204 " 'cx',\n",
1205 " 'cd',\n",
1206 " 'dc',\n",
1207 " 'dc',\n",
1208 " 'ml',\n",
1209 " 'xx',\n",
1210 " 'dc',\n",
1211 " 'xx',\n",
1212 " 'xd',\n",
1213 " 'ld',\n",
1214 " 'dc',\n",
1215 " 'xx',\n",
1216 " 'dc',\n",
1217 " 'dd',\n",
1218 " 'xm',\n",
1219 " 'dl',\n",
1220 " 'dd',\n",
1221 " 'dm',\n",
1222 " 'dl',\n",
1223 " 'cc',\n",
1224 " 'ld',\n",
1225 " 'cc',\n",
1226 " 'll',\n",
1227 " 'dd',\n",
1228 " 'lc',\n",
1229 " 'xx',\n",
1230 " 'dd',\n",
1231 " 'cx',\n",
1232 " 'cd',\n",
1233 " 'dc',\n",
1234 " 'dc',\n",
1235 " 'ld',\n",
1236 " 'cc',\n",
1237 " 'dd',\n",
1238 " 'cd',\n",
1239 " 'xx',\n",
1240 " 'mx',\n",
1241 " 'ld',\n",
1242 " 'xc',\n",
1243 " 'dd',\n",
1244 " 'cd',\n",
1245 " 'dl',\n",
1246 " 'md',\n",
1247 " 'cd',\n",
1248 " 'cc',\n",
1249 " 'dd',\n",
1250 " 'lc',\n",
1251 " 'xm',\n",
1252 " 'xl',\n",
1253 " 'xx',\n",
1254 " 'dd',\n",
1255 " 'dd',\n",
1256 " 'cx',\n",
1257 " 'xm',\n",
1258 " 'lx',\n",
1259 " 'ld',\n",
1260 " 'xm',\n",
1261 " 'cx',\n",
1262 " 'xd',\n",
1263 " 'xd',\n",
1264 " 'xm',\n",
1265 " 'dc',\n",
1266 " 'xm',\n",
1267 " 'dl',\n",
1268 " 'mx',\n",
1269 " 'xm',\n",
1270 " 'xd',\n",
1271 " 'cl',\n",
1272 " 'cd',\n",
1273 " 'dl',\n",
1274 " 'xm',\n",
1275 " 'dl',\n",
1276 " 'xm',\n",
1277 " 'xc',\n",
1278 " 'cd',\n",
1279 " 'll',\n",
1280 " 'cc',\n",
1281 " 'ld',\n",
1282 " 'dd',\n",
1283 " 'ld',\n",
1284 " 'cd',\n",
1285 " 'cc',\n",
1286 " 'dd',\n",
1287 " 'lc',\n",
1288 " 'xx',\n",
1289 " 'cc',\n",
1290 " 'ld',\n",
1291 " 'dd',\n",
1292 " 'dl',\n",
1293 " 'xm',\n",
1294 " 'xc',\n",
1295 " 'xm',\n",
1296 " 'ld',\n",
1297 " 'mx',\n",
1298 " 'xm',\n",
1299 " 'xd',\n",
1300 " 'cm',\n",
1301 " 'xm',\n",
1302 " 'dl',\n",
1303 " 'lc',\n",
1304 " 'xx',\n",
1305 " 'cm',\n",
1306 " 'dc',\n",
1307 " 'dc',\n",
1308 " 'dm',\n",
1309 " 'xm',\n",
1310 " 'dd',\n",
1311 " 'cd',\n",
1312 " 'cc',\n",
1313 " 'ld',\n",
1314 " 'dm',\n",
1315 " 'dc',\n",
1316 " 'cc',\n",
1317 " 'xm',\n",
1318 " 'mx',\n",
1319 " 'xm',\n",
1320 " 'dl',\n",
1321 " 'lm',\n",
1322 " 'cc',\n",
1323 " 'xm',\n",
1324 " 'ml',\n",
1325 " 'cd',\n",
1326 " 'dl',\n",
1327 " 'cm',\n",
1328 " 'xm',\n",
1329 " 'dl',\n",
1330 " 'lc',\n",
1331 " 'xx',\n",
1332 " 'cm',\n",
1333 " 'dc',\n",
1334 " 'lc',\n",
1335 " 'xm',\n",
1336 " 'lx',\n",
1337 " 'xx',\n",
1338 " 'ld',\n",
1339 " 'cx',\n",
1340 " 'xm',\n",
1341 " 'xd',\n",
1342 " 'dd',\n",
1343 " 'cd',\n",
1344 " 'dm',\n",
1345 " 'cc',\n",
1346 " 'xd',\n",
1347 " 'xm',\n",
1348 " 'dl',\n",
1349 " 'dc',\n",
1350 " 'dd',\n",
1351 " 'xx',\n",
1352 " 'cc',\n",
1353 " 'xd',\n",
1354 " 'dd',\n",
1355 " 'lc',\n",
1356 " 'xm',\n",
1357 " 'xc',\n",
1358 " 'dm',\n",
1359 " 'cc',\n",
1360 " 'cc',\n",
1361 " 'ld',\n",
1362 " 'cc',\n",
1363 " 'll',\n",
1364 " 'cd',\n",
1365 " 'lx',\n",
1366 " 'dd',\n",
1367 " 'lc',\n",
1368 " 'xm',\n",
1369 " 'cm',\n",
1370 " 'cx',\n",
1371 " 'xx',\n",
1372 " 'cc',\n",
1373 " 'xl',\n",
1374 " 'dm',\n",
1375 " 'dd',\n",
1376 " 'xm',\n",
1377 " 'ld',\n",
1378 " 'dd',\n",
1379 " 'lc',\n",
1380 " 'xm',\n",
1381 " 'dl',\n",
1382 " 'ml',\n",
1383 " 'xx',\n",
1384 " 'md',\n",
1385 " 'xd',\n",
1386 " 'xm',\n",
1387 " 'dc',\n",
1388 " 'cm',\n",
1389 " ...]"
1390 ]
1391 },
1392 "execution_count": 16,
1393 "metadata": {},
1394 "output_type": "execute_result"
1395 }
1396 ],
1397 "source": [
1398 "scb = sanitise(cb)\n",
1399 "scbp = chunks(scb, 2)\n",
1400 "scbp"
1401 ]
1402 },
1403 {
1404 "cell_type": "code",
1405 "execution_count": 17,
1406 "metadata": {},
1407 "outputs": [
1408 {
1409 "data": {
1410 "text/plain": [
1411 "'MHALEATASTIFETHOTSFETNRAFSSETFWTHEYAROLPOTTLEMATHPNFDAUUOOTMOTLARGSTIEETHEHODREATHEITHETINNWSRNITHETOUTAUOLOPALATBTNNVEIUNCETHEHFGERFCEIAUOLDASODVORTOGEYOUEDPBHASOICBMATHNFTTHESFWWNITNYOGIAUNLOORDHASTOLERTEDSUNFTSDEYEOTMNFLDHOVEPEERAREVATOPLEORDMATHATTHELNSSNYPIATORRAOHOVARGIEOLASEDTHOTTHEAUERAMEIEIEODARGHASUNCCFRAUOTANRSOGIAUNLOOIIORGEDTNWLORTYOLSEARYNICOTANROPNFTTHEWLORREDDASWNSATANRNYTINNWSSETTARGOTIOWARTNMHAUHTHEAUERAYELLATASSTALLFRULEOIHNMTHESOVOGETIAPESHODLEOIREDTNDEUAWHEINFIOICBSUNCCFRAUOTANRSOSTHEBHODRNMIATARGNYTHEAINMRHNMEVEIEVEIBOICBHOSATSTIOATNISORDATSEECSLAKELBTNCETHOTNRENICNIENYTHELNUOLTIAPESWENWLETFIREDSNCENRESHEODLNVENICNREBATASOLLTIEOUHEIBPFTTHASOUTTHIEOTEREDTNFRDEICARETHEECWAIESERTAIESBSTECNYSEUFIEUNCCFRAUOTANRTHEUOESOIUAWHEIWEIHOWSCNIETHORINODSHODEROPLEDTHEECWAIETNYFRUTANRSEUFIELBORDATSLNSSMOSODASOSTEITFIRARGTHOTLNSSARTNOVAUTNIBNRTHEPOTTLEYAELDDESEIVEDCNIEIEUNGRATANRTHORATIEUEAVEDWEIHOWSSFETNRAFSREVEIKREMNIWEIHOWSHEYOALEDTNFRDEISTORDTHEUFRRARGNYTHEWLORPFTEATHEIMOBDESWATETHEVAUTNIBOGIAUNLOORDTHERARTHLEGANRIECOAREDARDASGIOUENRHEOIARGTHASREMSULOFDAFSUOESOIOFGFSTFSGEICORAUFSREINECWEINIASSFEDOSEUIETWINULOCOTANRESTOPLASHARGOUAWHEISUHNNLTNDEVELNWOREMSBSTECNYACWEIAOLUAWHEISATMNIKEDARSEUIETYNINVEITMERTBBEOISDEVELNWARGREMCETHNDSTNSEUFIEUNCCFRAUOTANRSOUINSSTHEECWAIESTFDBARGTHEMNIKSNYTHEGIEEKSOGESEFULADORDHBWOTAOORDEVERNLDEIMNIKSYINCORUAERTPOPBLNRTHESUHNNLDEVELNWEDREMMOBSTNSOYEGFOIDUNCCFRAUOTANRSYINCINCESERECAESTHESEREMSBSTECSMEIEMIATTERDNMRORDDASTIAPFTEDARTHEUNDEXNUUFLTNIFCWEIHOWSTHECNSTSTIAUTLBGFOIDEDDNUFCERTAROLLHASTNIBMHERATMOSYAROLLBUNCWLETEDCORBBEOISLOTEITHEECWEINIDNCATAORASSFEDOREXEUFTAVENIDEIMHAUHWIEYOUEDEVEIBUNWBNYTHEUNDEXTHOTATMOSTNPEGFOIDEDPBEVEIBLEGANRTNTHELOSTCORTHEDEYEOTNYTHEAUERAORDTHESFAUADENYPNFDAUUOWEIHOWSWINTEUTEDTHERARTHLEGANRYINCDASSNLFTANROGIAUNLOMOSLOIGELBLEYTTNHASNMRDEVAUESARTHEWINVARUETHNFGHATMOSCODEULEOITNHACTHOTTNIETFIRMNFLDCEOROTPESTDASGIOUEORDOTMNISTDEOTHAROPIEOKMATHTIODATANRTHERARTHIOASEDOREMSTORDOIDTHELEGANRMOSEXALEDARDASGIOUETNERDFIETHEHOIDORDDORGEINFSMNIKNYSFPDFARGTHEUOLEDNRAAARTHEPLEOKMALDEIRESSESNYUOLEDNRAOSFETNRAFSNIDEIEDTHERARTHTNCOIUHTNEPNIOUFCMHAUHTHEBMEIETNCOKETHEAIPOSEYNIIOADSARTNUOLEDNRAOTHEFRSWNKERIEOSNRYNITHEAIEXALEMOSTHOTARTELLAGERUEIEWNITSSFGGESTEDTHOTTHASMOSMHEIETHEBCAGHTYARDTHEAILNSTOQFALOTHNSEMHNMNFLDIEODNRCFSTYNLLNMCBYOATHYFLSLOVETAINMHNYOUESOGIOVETOSKWEIHOWSTHELOIGESTTNDOTEOSHETIOVELSTNUNRUEOLTHEYNFITHUHOWTEINYTHASTIOGAUTOLE'"
1412 ]
1413 },
1414 "execution_count": 17,
1415 "metadata": {},
1416 "output_type": "execute_result"
1417 }
1418 ],
1419 "source": [
1420 "scbpt = cat(trans[p] for p in scbp)\n",
1421 "scbpt"
1422 ]
1423 },
1424 {
1425 "cell_type": "code",
1426 "execution_count": 18,
1427 "metadata": {},
1428 "outputs": [
1429 {
1430 "data": {
1431 "text/plain": [
1432 "'while it is true that suetonius setup the final vat tle with vou di ccaat watling street he had neither the troops nor the tactical avi lity to ober come the huge numerical disad ban tage faced vy his army without the support of agricola and his talented scouts defeat would habe veen in ebita vle and with it the loss of vr it anni ahab ing realised that the iceni were reading his communications agricola arranged to plant false information av out the planned disposition of troops setting a trap into which the iceni fell it is still unclear how the saba get rives had learned to decipher our army s communications as they had no writing of their own howe be reber y army has its traitors and it seems likely to me that one or more of the local t rives people turned someones head lobe or money it is all treachery vut this act threatened to undermine the empires entire system of secure communication the caesar cipher perhaps more than road shade nav led the empire to function securely and its loss was a disaster turning that loss into a bic tory on the vat tle field deser bed more recognition than it recei bed perhaps suetonius ne berk new or perhaps he failed to understand the cunning of the plan vut either way despite the bic tory agricola and the ninth legion remained in disgrace on hearing this news claudius caesar augustus germanicus nero emperor issued a secret proclamation est av lishing a cipher school to de belo pa new system of imperial ciphers it worked in secret for ober twenty years deb eloping new methods to secure communications across the empire studying the works of the greeks ages euclid and hypatia and eben older works from ancient vav yl on the school deb eloped new ways to safeguard communications from rome s enemies these new systems were written down and distri vu ted in the codex occult orum perhaps the most strictly guarded document in all history when it was finally completed many years later the emperor domitian issued an execut i be order which preface de bery copy of the codex that it was to ve guarded vye bery legion to the last man the defeat of the iceni and the suicide of vou dic ca perhaps protected the ninth legion from dissolution agricola was largely left to his own debi ces in the prob in ce though it was made clear to him that to return would mean at vest disgrace and at worst death in av reak with tradition the ninth raised a new standard the legion was exiled in disgrace to endure the hard and dangerous work of suv du ing the caledon ii in the v leak wildernesses of caledonia suetonius ordered the ninth to march to evora cum which they were to make their vase for raids into caledonia the unspoken reason for their exile was that intelligence reports suggested that this was where they might find their lost aquila those who would read on must follow my faithful sla be tiro who faces agra be task perhaps the largest to date a she trabel s to conceal the fourth chapter of this tragic tale'"
1433 ]
1434 },
1435 "execution_count": 18,
1436 "metadata": {},
1437 "output_type": "execute_result"
1438 }
1439 ],
1440 "source": [
1441 "tr = {}\n",
1442 "tr['E'] = 'e'\n",
1443 "tr['T'] = 't'\n",
1444 "tr['O'] = 'a'\n",
1445 "tr['A'] = 'i'\n",
1446 "tr['I'] = 'r'\n",
1447 "tr['H'] = 'h'\n",
1448 "tr['S'] = 's'\n",
1449 "tr['M'] = 'w'\n",
1450 "tr['P'] = 'v'\n",
1451 "tr['L'] = 'l'\n",
1452 "tr['Y'] = 'f'\n",
1453 "tr['R'] = 'n'\n",
1454 "tr['G'] = 'g'\n",
1455 "tr['F'] = 'u'\n",
1456 "tr['B'] = 'y'\n",
1457 "tr['V'] = 'b'\n",
1458 "tr['N'] = 'o'\n",
1459 "tr['D'] = 'd'\n",
1460 "tr['U'] = 'c'\n",
1461 "tr['W'] = 'p'\n",
1462 "tr['C'] = 'm'\n",
1463 "tr['K'] = 'k'\n",
1464 "tr['X'] = 'x'\n",
1465 "tr['Q'] = 'q'\n",
1466 "\n",
1467 "# english: etoainhs rdlumwycfgpbvkxqz\n",
1468 "# texts: etoanisrhdlufcmwgybpvkxqz\n",
1469 "\n",
1470 "\n",
1471 "tt = ''.maketrans(tr)\n",
1472 "wcat(segment(scbpt.translate(tt)))\n"
1473 ]
1474 },
1475 {
1476 "cell_type": "code",
1477 "execution_count": 27,
1478 "metadata": {},
1479 "outputs": [
1480 {
1481 "data": {
1482 "text/plain": [
1483 "2969"
1484 ]
1485 },
1486 "execution_count": 27,
1487 "metadata": {},
1488 "output_type": "execute_result"
1489 }
1490 ],
1491 "source": [
1492 "open('3b.plaintext', 'w').write(prettify(scbpt.translate(tt)))"
1493 ]
1494 },
1495 {
1496 "cell_type": "code",
1497 "execution_count": 20,
1498 "metadata": {},
1499 "outputs": [
1500 {
1501 "data": {
1502 "text/plain": [
1503 "{'A': 'i',\n",
1504 " 'B': 'y',\n",
1505 " 'C': 'm',\n",
1506 " 'D': 'd',\n",
1507 " 'E': 'e',\n",
1508 " 'F': 'u',\n",
1509 " 'G': 'g',\n",
1510 " 'H': 'h',\n",
1511 " 'I': 'r',\n",
1512 " 'K': 'k',\n",
1513 " 'L': 'l',\n",
1514 " 'M': 'w',\n",
1515 " 'N': 'o',\n",
1516 " 'O': 'a',\n",
1517 " 'P': 'v',\n",
1518 " 'Q': 'q',\n",
1519 " 'R': 'n',\n",
1520 " 'S': 's',\n",
1521 " 'T': 't',\n",
1522 " 'U': 'c',\n",
1523 " 'V': 'b',\n",
1524 " 'W': 'p',\n",
1525 " 'X': 'x',\n",
1526 " 'Y': 'f'}"
1527 ]
1528 },
1529 "execution_count": 20,
1530 "metadata": {},
1531 "output_type": "execute_result"
1532 }
1533 ],
1534 "source": [
1535 "tr"
1536 ]
1537 },
1538 {
1539 "cell_type": "code",
1540 "execution_count": 21,
1541 "metadata": {},
1542 "outputs": [
1543 {
1544 "data": {
1545 "text/plain": [
1546 "{'cc': 'n',\n",
1547 " 'cd': 'o',\n",
1548 " 'cl': 'm',\n",
1549 " 'cm': 'p',\n",
1550 " 'cx': 'l',\n",
1551 " 'dc': 's',\n",
1552 " 'dd': 't',\n",
1553 " 'dl': 'r',\n",
1554 " 'dm': 'u',\n",
1555 " 'dx': 'q',\n",
1556 " 'lc': 'h',\n",
1557 " 'ld': 'i',\n",
1558 " 'll': 'g',\n",
1559 " 'lm': 'k',\n",
1560 " 'lx': 'f',\n",
1561 " 'mc': 'x',\n",
1562 " 'md': 'y',\n",
1563 " 'ml': 'w',\n",
1564 " 'mx': 'b',\n",
1565 " 'xc': 'c',\n",
1566 " 'xd': 'd',\n",
1567 " 'xl': 'v',\n",
1568 " 'xm': 'e',\n",
1569 " 'xx': 'a'}"
1570 ]
1571 },
1572 "execution_count": 21,
1573 "metadata": {},
1574 "output_type": "execute_result"
1575 }
1576 ],
1577 "source": [
1578 "fm = {pr[1]: tr[pr[0].upper()] for pr in zip(ltrs, prs)}\n",
1579 "fm"
1580 ]
1581 },
1582 {
1583 "cell_type": "code",
1584 "execution_count": 22,
1585 "metadata": {},
1586 "outputs": [],
1587 "source": [
1588 "order = 'xlcdm'"
1589 ]
1590 },
1591 {
1592 "cell_type": "code",
1593 "execution_count": 23,
1594 "metadata": {},
1595 "outputs": [
1596 {
1597 "name": "stdout",
1598 "output_type": "stream",
1599 "text": [
1600 "avcde\n",
1601 "fghik\n",
1602 "lmnop\n",
1603 "qrstu\n",
1604 "bwxy\n"
1605 ]
1606 }
1607 ],
1608 "source": [
1609 "for c in order:\n",
1610 " for r in order:\n",
1611 " if c+r != 'mm':\n",
1612 " print(fm[c+r], end='')\n",
1613 " print('')"
1614 ]
1615 },
1616 {
1617 "cell_type": "code",
1618 "execution_count": 24,
1619 "metadata": {},
1620 "outputs": [],
1621 "source": [
1622 "# monoalphabetic_break_hillclimbing_mp(scbpt, alphabet=string.ascii_lowercase, fitness=Pbigrams)"
1623 ]
1624 },
1625 {
1626 "cell_type": "code",
1627 "execution_count": 25,
1628 "metadata": {},
1629 "outputs": [
1630 {
1631 "name": "stdout",
1632 "output_type": "stream",
1633 "text": [
1634 "while it is true that suetonius setup the final battle with boudicca at watling street he had\n",
1635 "neither the troops nor the tactical ability to overcome the huge numerical disadvantage faced by his\n",
1636 "army without the support of agricola and his talented scouts defeat would have been inevitable and\n",
1637 "with it the loss of britannia having realised that the iceni were reading his communications\n",
1638 "agricola arranged to plant false information about the planned disposition of troops setting a trap\n",
1639 "into which the iceni fell it is still unclear how the savage tribes had learned to decipher our army\n",
1640 "s communications as they had no writing of their own however every army has its traitors and it\n",
1641 "seems likely to me that one or more of the local tribespeople turned someones head love or money it\n",
1642 "is all treachery but this act threatened to undermine the empires entire system of secure\n",
1643 "communication the caesar cipher perhaps more than roads had enabled the empire to function securely\n",
1644 "and its loss was a disaster turning that loss into a victory on the battlefield deserved more\n",
1645 "recognition than it received perhaps suetonius never knew or perhaps he failed to understand the\n",
1646 "cunning of the plan but either way despite the victory agricola and the ninth legion remained in\n",
1647 "disgrace on hearing this news claudius caesar augustus germanicus nero emperor issued a secret\n",
1648 "proclamation establishing a cipher school to develop a new system of imperial ciphers it worked in\n",
1649 "secret for over twenty years developing new methods to secure communications across the empire\n",
1650 "studying the works of the greeks ages euclid and hypatia and even older works from ancient babylon\n",
1651 "the school developed new ways to safeguard communications from rome s enemies these new systems were\n",
1652 "written down and distributed in the codex occult orum perhaps the most strictly guarded document in\n",
1653 "all history when it was finally completed many years later the emperor domitian issued an executive\n",
1654 "order which prefaced every copy of the codex that it was to be guarded by every legion to the last\n",
1655 "man the defeat of the iceni and the suicide of boudicca perhaps protected the ninth legion from\n",
1656 "dissolution agricola was largely left to his own devices in the province though it was made clear to\n",
1657 "him that to return would mean at best disgrace and at worst death in a break with tradition the\n",
1658 "ninth raised a new standard the legion was exiled in disgrace to endure the hard and dangerous work\n",
1659 "of subduing the caledon ii in the bleak wildernesses of caledonia suetonius ordered the ninth to\n",
1660 "march toe bora cum which they were to make their base for raids into caledonia the unspoken reason\n",
1661 "for their exile was that intelligence reports suggested that this was where they might find their\n",
1662 "lost aquila those who would read on must follow my faithful slave tiro who faces a grave task\n",
1663 "perhaps the largest to date a she travels to conceal the fourth chapter of this tragic tale\n"
1664 ]
1665 }
1666 ],
1667 "source": [
1668 "print(prettify(polybius_decipher(scb, '', order, order)))"
1669 ]
1670 },
1671 {
1672 "cell_type": "code",
1673 "execution_count": 26,
1674 "metadata": {},
1675 "outputs": [
1676 {
1677 "data": {
1678 "text/plain": [
1679 "False"
1680 ]
1681 },
1682 "execution_count": 26,
1683 "metadata": {},
1684 "output_type": "execute_result"
1685 }
1686 ],
1687 "source": [
1688 "scbpt.translate(tt) == polybius_decipher(scb, '', order, order)"
1689 ]
1690 },
1691 {
1692 "cell_type": "code",
1693 "execution_count": null,
1694 "metadata": {},
1695 "outputs": [],
1696 "source": []
1697 }
1698 ],
1699 "metadata": {
1700 "kernelspec": {
1701 "display_name": "Python 3",
1702 "language": "python",
1703 "name": "python3"
1704 },
1705 "language_info": {
1706 "codemirror_mode": {
1707 "name": "ipython",
1708 "version": 3
1709 },
1710 "file_extension": ".py",
1711 "mimetype": "text/x-python",
1712 "name": "python",
1713 "nbconvert_exporter": "python",
1714 "pygments_lexer": "ipython3",
1715 "version": "3.6.3"
1716 }
1717 },
1718 "nbformat": 4,
1719 "nbformat_minor": 2
1720 }