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",
14 "import matplotlib.pyplot as plt\n",
15 "%matplotlib inline\n",
17 "from cipherbreak import *\n",
19 "ca = open('3a.ciphertext').read()\n",
20 "cb = open('3b.ciphertext').read()"
31 "'MHALEATASTIFETHOTSFETNRAFSSETFWTHEYAROLPOTTLEMATHPNFDAUUOOTMOTLARGSTIEETHEHODREATHEITHETINNWSRNITHETOUTAUOLOPALATBTNNVEIUNCETHEHFGERFCEIAUOLDASODVORTOGEYOUEDPBHASOICBMATHNFTTHESFWWNITNYOGIAUNLOORDHASTOLERTEDSUNFTSDEYEOTMNFLDHOVEPEERAREVATOPLEORDMATHATTHELNSSNYPIATORRAOHOVARGIEOLASEDTHOTTHEAUERAMEIEIEODARGHASUNCCFRAUOTANRSOGIAUNLOOIIORGEDTNWLORTYOLSEARYNICOTANROPNFTTHEWLORREDDASWNSATANRNYTINNWSSETTARGOTIOWARTNMHAUHTHEAUERAYELLATASSTALLFRULEOIHNMTHESOVOGETIAPESHODLEOIREDTNDEUAWHEINFIOICBSUNCCFRAUOTANRSOSTHEBHODRNMIATARGNYTHEAINMRHNMEVEIEVEIBOICBHOSATSTIOATNISORDATSEECSLAKELBTNCETHOTNRENICNIENYTHELNUOLTIAPESWENWLETFIREDSNCENRESHEODLNVENICNREBATASOLLTIEOUHEIBPFTTHASOUTTHIEOTEREDTNFRDEICARETHEECWAIESERTAIESBSTECNYSEUFIEUNCCFRAUOTANRTHEUOESOIUAWHEIWEIHOWSCNIETHORINODSHODEROPLEDTHEECWAIETNYFRUTANRSEUFIELBORDATSLNSSMOSODASOSTEITFIRARGTHOTLNSSARTNOVAUTNIBNRTHEPOTTLEYAELDDESEIVEDCNIEIEUNGRATANRTHORATIEUEAVEDWEIHOWSSFETNRAFSREVEIKREMNIWEIHOWSHEYOALEDTNFRDEISTORDTHEUFRRARGNYTHEWLORPFTEATHEIMOBDESWATETHEVAUTNIBOGIAUNLOORDTHERARTHLEGANRIECOAREDARDASGIOUENRHEOIARGTHASREMSULOFDAFSUOESOIOFGFSTFSGEICORAUFSREINECWEINIASSFEDOSEUIETWINULOCOTANRESTOPLASHARGOUAWHEISUHNNLTNDEVELNWOREMSBSTECNYACWEIAOLUAWHEISATMNIKEDARSEUIETYNINVEITMERTBBEOISDEVELNWARGREMCETHNDSTNSEUFIEUNCCFRAUOTANRSOUINSSTHEECWAIESTFDBARGTHEMNIKSNYTHEGIEEKSOGESEFULADORDHBWOTAOORDEVERNLDEIMNIKSYINCORUAERTPOPBLNRTHESUHNNLDEVELNWEDREMMOBSTNSOYEGFOIDUNCCFRAUOTANRSYINCINCESERECAESTHESEREMSBSTECSMEIEMIATTERDNMRORDDASTIAPFTEDARTHEUNDEXNUUFLTNIFCWEIHOWSTHECNSTSTIAUTLBGFOIDEDDNUFCERTAROLLHASTNIBMHERATMOSYAROLLBUNCWLETEDCORBBEOISLOTEITHEECWEINIDNCATAORASSFEDOREXEUFTAVENIDEIMHAUHWIEYOUEDEVEIBUNWBNYTHEUNDEXTHOTATMOSTNPEGFOIDEDPBEVEIBLEGANRTNTHELOSTCORTHEDEYEOTNYTHEAUERAORDTHESFAUADENYPNFDAUUOWEIHOWSWINTEUTEDTHERARTHLEGANRYINCDASSNLFTANROGIAUNLOMOSLOIGELBLEYTTNHASNMRDEVAUESARTHEWINVARUETHNFGHATMOSCODEULEOITNHACTHOTTNIETFIRMNFLDCEOROTPESTDASGIOUEORDOTMNISTDEOTHAROPIEOKMATHTIODATANRTHERARTHIOASEDOREMSTORDOIDTHELEGANRMOSEXALEDARDASGIOUETNERDFIETHEHOIDORDDORGEINFSMNIKNYSFPDFARGTHEUOLEDNRAAARTHEPLEOKMALDEIRESSESNYUOLEDNRAOSFETNRAFSNIDEIEDTHERARTHTNCOIUHTNEPNIOUFCMHAUHTHEBMEIETNCOKETHEAIPOSEYNIIOADSARTNUOLEDNRAOTHEFRSWNKERIEOSNRYNITHEAIEXALEMOSTHOTARTELLAGERUEIEWNITSSFGGESTEDTHOTTHASMOSMHEIETHEBCAGHTYARDTHEAILNSTOQFALOTHNSEMHNMNFLDIEODNRCFSTYNLLNMCBYOATHYFLSLOVETAINMHNYOUESOGIOVETOSKWEIHOWSTHELOIGESTTNDOTEOSHETIOVELSTNUNRUEOLTHEYNFITHUHOWTEINYTHASTIOGAUTOLE'"
36 "output_type": "execute_result"
40 "scb = sanitise(cb)\n",
41 "scbp = chunks(scb, 2)\n",
43 "ltrs = 'etoanisrhdlufcmwgybpvkxqz'\n",
44 "prs = [p[0] for p in collections.Counter(chunks(sanitise(cb), 2)).most_common()]\n",
45 "trans = {pr[1]: pr[0].upper() for pr in zip(ltrs, prs)}\n",
46 "scbpt = cat(trans[p] for p in scbp)\n",
58 "'MHALEATASTIFETHOTSFETNRAFSSETFWTHEYAROLPOTTLEMATHPNFDAUUOOTMOTLARGSTIEETHEHODREATHEITHETINNWSRNITHETOUTAUOLOPALATBTNNVEIUNCETHEHFGERFCEIAUOLDASODVORTOGEYOUEDPBHASOICBMATHNFTTHESFWWNITNYOGIAUNLOORDHASTOLERTEDSUNFTSDEYEOTMNFLDHOVEPEERAREVATOPLEORDMATHATTHELNSSNYPIATORRAOHOVARGIEOLASEDTHOTTHEAUERAMEIEIEODARGHASUNCCFRAUOTANRSOGIAUNLOOIIORGEDTNWLORTYOLSEARYNICOTANROPNFTTHEWLORREDDASWNSATANRNYTINNWSSETTARGOTIOWARTNMHAUHTHEAUERAYELLATASSTALLFRULEOIHNMTHESOVOGETIAPESHODLEOIREDTNDEUAWHEINFIOICBSUNCCFRAUOTANRSOSTHEBHODRNMIATARGNYTHEAINMRHNMEVEIEVEIBOICBHOSATSTIOATNISORDATSEECSLAKELBTNCETHOTNRENICNIENYTHELNUOLTIAPESWENWLETFIREDSNCENRESHEODLNVENICNREBATASOLLTIEOUHEIBPFTTHASOUTTHIEOTEREDTNFRDEICARETHEECWAIESERTAIESBSTECNYSEUFIEUNCCFRAUOTANRTHEUOESOIUAWHEIWEIHOWSCNIETHORINODSHODEROPLEDTHEECWAIETNYFRUTANRSEUFIELBORDATSLNSSMOSODASOSTEITFIRARGTHOTLNSSARTNOVAUTNIBNRTHEPOTTLEYAELDDESEIVEDCNIEIEUNGRATANRTHORATIEUEAVEDWEIHOWSSFETNRAFSREVEIKREMNIWEIHOWSHEYOALEDTNFRDEISTORDTHEUFRRARGNYTHEWLORPFTEATHEIMOBDESWATETHEVAUTNIBOGIAUNLOORDTHERARTHLEGANRIECOAREDARDASGIOUENRHEOIARGTHASREMSULOFDAFSUOESOIOFGFSTFSGEICORAUFSREINECWEINIASSFEDOSEUIETWINULOCOTANRESTOPLASHARGOUAWHEISUHNNLTNDEVELNWOREMSBSTECNYACWEIAOLUAWHEISATMNIKEDARSEUIETYNINVEITMERTBBEOISDEVELNWARGREMCETHNDSTNSEUFIEUNCCFRAUOTANRSOUINSSTHEECWAIESTFDBARGTHEMNIKSNYTHEGIEEKSOGESEFULADORDHBWOTAOORDEVERNLDEIMNIKSYINCORUAERTPOPBLNRTHESUHNNLDEVELNWEDREMMOBSTNSOYEGFOIDUNCCFRAUOTANRSYINCINCESERECAESTHESEREMSBSTECSMEIEMIATTERDNMRORDDASTIAPFTEDARTHEUNDEXNUUFLTNIFCWEIHOWSTHECNSTSTIAUTLBGFOIDEDDNUFCERTAROLLHASTNIBMHERATMOSYAROLLBUNCWLETEDCORBBEOISLOTEITHEECWEINIDNCATAORASSFEDOREXEUFTAVENIDEIMHAUHWIEYOUEDEVEIBUNWBNYTHEUNDEXTHOTATMOSTNPEGFOIDEDPBEVEIBLEGANRTNTHELOSTCORTHEDEYEOTNYTHEAUERAORDTHESFAUADENYPNFDAUUOWEIHOWSWINTEUTEDTHERARTHLEGANRYINCDASSNLFTANROGIAUNLOMOSLOIGELBLEYTTNHASNMRDEVAUESARTHEWINVARUETHNFGHATMOSCODEULEOITNHACTHOTTNIETFIRMNFLDCEOROTPESTDASGIOUEORDOTMNISTDEOTHAROPIEOKMATHTIODATANRTHERARTHIOASEDOREMSTORDOIDTHELEGANRMOSEXALEDARDASGIOUETNERDFIETHEHOIDORDDORGEINFSMNIKNYSFPDFARGTHEUOLEDNRAAARTHEPLEOKMALDEIRESSESNYUOLEDNRAOSFETNRAFSNIDEIEDTHERARTHTNCOIUHTNEPNIOUFCMHAUHTHEBMEIETNCOKETHEAIPOSEYNIIOADSARTNUOLEDNRAOTHEFRSWNKERIEOSNRYNITHEAIEXALEMOSTHOTARTELLAGERUEIEWNITSSFGGESTEDTHOTTHASMOSMHEIETHEBCAGHTYARDTHEAILNSTOQFALOTHNSEMHNMNFLDIEODNRCFSTYNLLNMCBYOATHYFLSLOVETAINMHNYOUESOGIOVETOSKWEIHOWSTHELOIGESTTNDOTEOSHETIOVELSTNUNRUEOLTHEYNFITHUHOWTEINYTHASTIOGAUTOLE'"
63 "output_type": "execute_result"
67 "trhc = ''.maketrans('abmdefghijklcnopqrstuvwxyz', string.ascii_lowercase)\n",
68 "scbpt.translate(trhc)"
77 "def polybius_grid(keyword, column_order, row_order, letters_to_merge=None,\n",
78 " wrap_alphabet=KeywordWrapAlphabet.from_a):\n",
79 " alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet=wrap_alphabet)\n",
80 " if letters_to_merge is None: \n",
81 " letters_to_merge = {'j': 'i'}\n",
83 " for k, l in zip([(c, r) for c in column_order for r in row_order],\n",
84 " [l for l in alphabet if l not in letters_to_merge])}\n",
85 " for l in letters_to_merge:\n",
86 " grid[l] = grid[letters_to_merge[l]]\n",
98 "{'a': ('x', 'x'),\n",
99 " 'b': ('x', 'l'),\n",
100 " 'c': ('x', 'c'),\n",
101 " 'd': ('x', 'd'),\n",
102 " 'e': ('x', 'm'),\n",
103 " 'f': ('l', 'x'),\n",
104 " 'g': ('l', 'l'),\n",
105 " 'h': ('l', 'c'),\n",
106 " 'i': ('l', 'd'),\n",
107 " 'j': ('l', 'd'),\n",
108 " 'k': ('l', 'm'),\n",
109 " 'l': ('c', 'x'),\n",
110 " 'm': ('c', 'l'),\n",
111 " 'n': ('c', 'c'),\n",
112 " 'o': ('c', 'd'),\n",
113 " 'p': ('c', 'm'),\n",
114 " 'q': ('d', 'x'),\n",
115 " 'r': ('d', 'l'),\n",
116 " 's': ('d', 'c'),\n",
117 " 't': ('d', 'd'),\n",
118 " 'u': ('d', 'm'),\n",
119 " 'v': ('m', 'x'),\n",
120 " 'w': ('m', 'l'),\n",
121 " 'x': ('m', 'c'),\n",
122 " 'y': ('m', 'd'),\n",
126 "execution_count": 9,
128 "output_type": "execute_result"
132 "polybius_grid('', order, order)"
137 "execution_count": 10,
143 "{'a': ('a', 'a'),\n",
144 " 'b': ('a', 'b'),\n",
145 " 'c': ('a', 'c'),\n",
146 " 'd': ('a', 'd'),\n",
147 " 'e': ('a', 'e'),\n",
148 " 'f': ('b', 'a'),\n",
149 " 'g': ('b', 'b'),\n",
150 " 'h': ('b', 'c'),\n",
151 " 'i': ('b', 'd'),\n",
152 " 'j': ('b', 'd'),\n",
153 " 'k': ('b', 'e'),\n",
154 " 'l': ('c', 'a'),\n",
155 " 'm': ('c', 'b'),\n",
156 " 'n': ('c', 'c'),\n",
157 " 'o': ('c', 'd'),\n",
158 " 'p': ('c', 'e'),\n",
159 " 'q': ('d', 'a'),\n",
160 " 'r': ('d', 'b'),\n",
161 " 's': ('d', 'c'),\n",
162 " 't': ('d', 'd'),\n",
163 " 'u': ('d', 'e'),\n",
164 " 'v': ('e', 'a'),\n",
165 " 'w': ('e', 'b'),\n",
166 " 'x': ('e', 'c'),\n",
167 " 'y': ('e', 'd'),\n",
171 "execution_count": 10,
173 "output_type": "execute_result"
177 "polybius_grid('a', 'abcde', 'abcde')"
182 "execution_count": 11,
191 "execution_count": 11,
193 "output_type": "execute_result"
197 "polybius_grid('elephant', 'abcde', 'abcde')['b'] == ('b', 'c')"
202 "execution_count": 12,
211 "execution_count": 12,
213 "output_type": "execute_result"
217 "polybius_grid('elephant', 'abcde', 'abcde')['e'] == ('a', 'a')"
222 "execution_count": 13,
226 "def polybius_reverse_grid(keyword, column_order, row_order, letters_to_merge=None,\n",
227 " wrap_alphabet=KeywordWrapAlphabet.from_a):\n",
228 " alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet=wrap_alphabet)\n",
229 " if letters_to_merge is None: \n",
230 " letters_to_merge = {'j': 'i'}\n",
232 " for k, l in zip([(c, r) for c in column_order for r in row_order],\n",
233 " [l for l in alphabet if l not in letters_to_merge])}\n",
234 "# for l in letters_to_merge:\n",
235 "# for r, c in grid:\n",
236 "# if grid[r, c] == letters_to_merge[l]:\n",
237 "# grid[l] = grid[r, c]\n",
243 "execution_count": 14,
249 "{('c', 'c'): 'n',\n",
250 " ('c', 'd'): 'o',\n",
251 " ('c', 'l'): 'm',\n",
252 " ('c', 'm'): 'p',\n",
253 " ('c', 'x'): 'l',\n",
254 " ('d', 'c'): 's',\n",
255 " ('d', 'd'): 't',\n",
256 " ('d', 'l'): 'r',\n",
257 " ('d', 'm'): 'u',\n",
258 " ('d', 'x'): 'q',\n",
259 " ('l', 'c'): 'h',\n",
260 " ('l', 'd'): 'i',\n",
261 " ('l', 'l'): 'g',\n",
262 " ('l', 'm'): 'k',\n",
263 " ('l', 'x'): 'f',\n",
264 " ('m', 'c'): 'x',\n",
265 " ('m', 'd'): 'y',\n",
266 " ('m', 'l'): 'w',\n",
267 " ('m', 'm'): 'z',\n",
268 " ('m', 'x'): 'v',\n",
269 " ('x', 'c'): 'c',\n",
270 " ('x', 'd'): 'd',\n",
271 " ('x', 'l'): 'b',\n",
272 " ('x', 'm'): 'e',\n",
276 "execution_count": 14,
278 "output_type": "execute_result"
282 "polybius_reverse_grid('', order, order)"
287 "execution_count": 15,
291 "def polybius_flatten(pair, column_first):\n",
292 " if column_first:\n",
293 " return str(pair[1]) + str(pair[0])\n",
295 " return str(pair[0]) + str(pair[1])"
300 "execution_count": 16,
304 "def polybius_encipher(message, keyword, column_order, row_order, \n",
305 " column_first=False,\n",
306 " letters_to_merge=None, wrap_alphabet=KeywordWrapAlphabet.from_a): \n",
307 " grid = polybius_grid(keyword, column_order, row_order, letters_to_merge, wrap_alphabet)\n",
308 " return cat(polybius_flatten(grid[l], column_first)\n",
309 " for l in message\n",
315 "execution_count": 17,
321 "'mllcldcxxmldddlddcdddldmxm'"
324 "execution_count": 17,
326 "output_type": "execute_result"
330 "polybius_encipher('while it is true', '', order, order)"
335 "execution_count": 18,
341 "'mllcldcxxmldddlddcdddldmxmddlcxxdddcdmxmddcdcclddmdcdcxmdddmcmddlcxmlxldccxxcxxlxxdd'"
344 "execution_count": 18,
346 "output_type": "execute_result"
355 "execution_count": 19,
359 "def polybius_decipher(message, keyword, column_order, row_order, \n",
360 " column_first=False,\n",
361 " letters_to_merge=None, wrap_alphabet=KeywordWrapAlphabet.from_a): \n",
362 " grid = polybius_reverse_grid(keyword, column_order, row_order, letters_to_merge, wrap_alphabet)\n",
363 " column_index_type = type(column_order[0])\n",
364 " row_index_type = type(row_order[0])\n",
365 " if column_first:\n",
366 " pairs = [(column_index_type(p[1]), row_index_type(p[0])) for p in chunks(message, 2)]\n",
368 " pairs = [(row_index_type(p[0]), column_index_type(p[1])) for p in chunks(message, 2)]\n",
369 " return cat(grid[p] for p in pairs if p in grid)"
374 "execution_count": 20,
383 "execution_count": 20,
385 "output_type": "execute_result"
389 "polybius_decipher('mllcldcxxmldddlddcdddldmxm', '', order, order)"
394 "execution_count": 21,
400 "'lmcldlxcmxdldddlcdddldmdmx'"
403 "execution_count": 21,
405 "output_type": "execute_result"
409 "polybius_encipher('whileitistrue', '', order, order, column_first=True)"
414 "execution_count": 22,
423 "execution_count": 22,
425 "output_type": "execute_result"
429 "polybius_decipher('lmcldlxcmxdldddlcdddldmdmx', '', order, order)"
434 "execution_count": 23,
443 "execution_count": 23,
445 "output_type": "execute_result"
449 "polybius_decipher('lmcldlxcmxdldddlcdddldmdmx', '', order, order, column_first=True)"
454 "execution_count": 24,
460 "'52232431152444244344424515'"
463 "execution_count": 24,
465 "output_type": "execute_result"
469 "polybius_encipher('while it is true', '', '12345', '12345')"
474 "execution_count": 25,
480 "'52232431152444244344424515'"
483 "execution_count": 25,
485 "output_type": "execute_result"
489 "polybius_encipher('while it is true', '', [1, 2, 3, 4, 5], [1, 2, 3, 4, 5])"
494 "execution_count": 26,
503 "execution_count": 26,
505 "output_type": "execute_result"
509 "polybius_decipher('52232431152444244344424515', '', [1, 2, 3, 4, 5], [1, 2, 3, 4, 5])"
514 "execution_count": 27,
518 "from multiprocessing import Pool\n",
520 "def polybius_break_mp(message, column_labels, row_labels,\n",
521 " letters_to_merge=None,\n",
522 " wordlist=keywords, fitness=Pletters,\n",
523 " number_of_solutions=1, chunksize=500):\n",
524 " \"\"\"Breaks a Polybius substitution cipher using a dictionary and\n",
525 " frequency analysis\n",
527 " >>> polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
528 " 'polybius decipherment', 'elephant', 'abcde', 'abcde'), \\\n",
529 " 'abcde', 'abcde', \\\n",
530 " wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS\n",
531 " (('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', False), \\\n",
533 " >>> polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
534 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=True), \\\n",
535 " 'abcde', 'abcde', \\\n",
536 " wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS\n",
537 " (('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', True), \\\n",
539 " >>> polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
540 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=False), \\\n",
541 " 'abcde', 'abcde', \\\n",
542 " wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS\n",
543 " (('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', False), \\\n",
545 " >>> polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
546 " 'polybius decipherment', 'elephant', 'abcde', 'pqrst', column_first=True), \\\n",
547 " 'abcde', 'pqrst', \\\n",
548 " wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS\n",
549 " (('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'pqrst', True), \\\n",
552 " if letters_to_merge is None: \n",
553 " letters_to_m53880erge = {'j': 'i'}\n",
554 " with Pool() as pool:\n",
555 " helper_args = [(message, word, wrap, \n",
556 " column_labels, row_labels, column_first, \n",
557 " letters_to_merge, \n",
559 " for word in wordlist\n",
560 " for wrap in KeywordWrapAlphabet\n",
561 " for column_first in [False, True]]\n",
562 " # Gotcha: the helper function here needs to be defined at the top level\n",
563 " # (limitation of Pool.starmap)\n",
564 " breaks = pool.starmap(polybius_break_worker, helper_args, chunksize)\n",
565 " if number_of_solutions == 1:\n",
566 " return max(breaks, key=lambda k: k[1])\n",
568 " return sorted(breaks, key=lambda k: k[1], reverse=True)[:number_of_solutions]\n",
570 "def polybius_break_worker(message, keyword, wrap_alphabet, \n",
571 " column_order, row_order, column_first, \n",
572 " letters_to_merge, \n",
574 " plaintext = polybius_decipher(message, keyword, \n",
575 " column_order, row_order, \n",
576 " column_first=column_first,\n",
577 " letters_to_merge=letters_to_merge, \n",
578 " wrap_alphabet=wrap_alphabet)\n",
580 " fit = fitness(plaintext)\n",
582 " fit = float('-inf')\n",
583 " logger.debug('Polybius break attempt using key {0} (wrap={1}, merging {2}), '\n",
584 " 'columns as {3}, rows as {4} (column_first={5}) '\n",
585 " 'gives fit of {6} and decrypt starting: '\n",
586 " '{7}'.format(keyword, wrap_alphabet, letters_to_merge,\n",
587 " column_order, row_order, column_first,\n",
588 " fit, sanitise(plaintext)[:50]))\n",
589 " return (keyword, wrap_alphabet, column_order, row_order, column_first), fit"
594 "execution_count": 28,
599 "output_type": "stream",
601 "CPU times: user 2.67 s, sys: 308 ms, total: 2.98 s\n",
602 "Wall time: 3min 58s\n"
608 "(('a', <KeywordWrapAlphabet.from_a: 1>, 'xlcdm', 'xlcdm', False),\n",
609 " -3018.8648333417113)"
612 "execution_count": 28,
614 "output_type": "execute_result"
618 "%time polybius_break_mp(sanitise(cb), order, order)"
623 "execution_count": 29,
630 " <KeywordWrapAlphabet.from_a: 1>,\n",
631 " [1, 2, 3, 4, 5],\n",
632 " [1, 2, 3, 4, 5],\n",
634 " -54.53880323982303)"
637 "execution_count": 29,
639 "output_type": "execute_result"
643 "polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
644 " 'polybius decipherment', 'elephant', \\\n",
645 " [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \\\n",
646 " KeywordWrapAlphabet.from_last), \\\n",
647 " [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \\\n",
648 " wordlist=['cat', 'elephant', 'kangaroo'])"
653 "execution_count": 30,
659 "'2214445544551522115522511155551543114252542214111352123234442355411135441314115451112122'"
662 "execution_count": 30,
664 "output_type": "execute_result"
668 "polybius_encipher('this is a test message for the ' \\\n",
669 " 'polybius decipherment', 'elephant', \\\n",
670 " [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \\\n",
671 " wrap_alphabet=KeywordWrapAlphabet.from_last)"
676 "execution_count": 31,
683 " <KeywordWrapAlphabet.from_last: 2>,\n",
684 " [1, 2, 3, 4, 5],\n",
685 " [1, 2, 3, 4, 5],\n",
687 " -54.53880323982303)"
690 "execution_count": 31,
692 "output_type": "execute_result"
696 "polybius_break_mp('2214445544551522115522511155551543114252542214111352123234442355411135441314115451112122', \\\n",
697 " [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \\\n",
698 " wordlist=['cat', 'elephant', 'kangaroo'])"
703 "execution_count": 32,
709 "'thisisatestmessageforthepolybiusdecipherment'"
712 "execution_count": 32,
714 "output_type": "execute_result"
718 "polybius_decipher('2214445544551522115522511155551543114252542214111352123234442355411135441314115451112122', \\\n",
720 " [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \\\n",
721 " wrap_alphabet=KeywordWrapAlphabet.from_last)"
726 "execution_count": 33,
759 "execution_count": 33,
761 "output_type": "execute_result"
765 "polybius_reverse_grid('elephant', [1, 2, 3, 4, 5], [1, 2, 3, 4, 5] )"
770 "execution_count": 34,
779 "execution_count": 34,
781 "output_type": "execute_result"
790 "execution_count": 35,
796 "'bbadccddccddaebbaaddbbceaaddddaecbaacadadcbbadaaacdaabedbcccdeddbeaabdccacadaadcceaababb'"
799 "execution_count": 35,
801 "output_type": "execute_result"
805 "polybius_encipher('this is a test message for the ' \\\n",
806 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=False)"
811 "execution_count": 36,
817 "'bbdaccddccddeabbaaddbbecaaddddeabcaaacadcdbbdaaacaadbadecbccedddebaadbcccadaaacdecaaabbb'"
820 "execution_count": 36,
822 "output_type": "execute_result"
826 "polybius_encipher('this is a test message for the ' \\\n",
827 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=True)"
832 "execution_count": 37,
838 "'toisisvtestxessvbephktoefhnugiysweqifoekxelt'"
841 "execution_count": 37,
843 "output_type": "execute_result"
847 "polybius_decipher('bbdaccddccddeabbaaddbbecaaddddeabcaaacadcdbbdaaacaadbadecbccedddebaadbcccadaaacdecaaabbb', 'elephant', 'abcde', 'abcde', column_first=False)"
852 "execution_count": 38,
858 "'thisisatestmessageforthepolybiusdecipherment'"
861 "execution_count": 38,
863 "output_type": "execute_result"
867 "polybius_decipher('bbdaccddccddeabbaaddbbecaaddddeabcaaacadcdbbdaaacaadbadecbccedddebaadbcccadaaacdecaaabbb', 'elephant', 'abcde', 'abcde', column_first=True)"
872 "execution_count": 39,
880 "(('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', False),\n",
881 " -54.53880323982303)"
884 "execution_count": 39,
886 "output_type": "execute_result"
890 "polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
891 " 'polybius decipherment', 'elephant', 'abcde', 'abcde'), \\\n",
892 " 'abcde', 'abcde',\n",
893 " wordlist=['cat', 'elephant', 'kangaroo'])"
898 "execution_count": 40,
906 "(('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', True),\n",
907 " -54.53880323982303)"
910 "execution_count": 40,
912 "output_type": "execute_result"
916 "polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
917 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=True), \\\n",
918 " 'abcde', 'abcde',\n",
919 " wordlist=['cat', 'elephant', 'kangaroo'])"
924 "execution_count": 41,
932 "(('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'abcde', False),\n",
933 " -54.53880323982303)"
936 "execution_count": 41,
938 "output_type": "execute_result"
942 "polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
943 " 'polybius decipherment', 'elephant', 'abcde', 'abcde', column_first=False), \\\n",
944 " 'abcde', 'abcde',\n",
945 " wordlist=['cat', 'elephant', 'kangaroo'])"
950 "execution_count": 42,
958 "(('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'pqrst', True),\n",
959 " -54.53880323982303)"
962 "execution_count": 42,
964 "output_type": "execute_result"
968 "polybius_break_mp(polybius_encipher('this is a test message for the ' \\\n",
969 " 'polybius decipherment', 'elephant', 'abcde', 'pqrst', column_first=True), \\\n",
970 " 'abcde', 'pqrst',\n",
971 " wordlist=['cat', 'elephant', 'kangaroo'])"
976 "execution_count": 43,
982 "'bwaycxdycxdyazbwavdybwczavdydyazcwavcvdvdxbwayavaxdvaweybxcxdzdybzavbycxaxayavdxczavbvbw'"
985 "execution_count": 43,
987 "output_type": "execute_result"
991 "polybius_encipher('this is a test message for the ' \\\n",
992 " 'polybius decipherment', 'elephant', 'abcde', 'vwxyz')"
997 "execution_count": 44,
1003 "'thisisatestmessageforthepolybiusdecipherment'"
1006 "execution_count": 44,
1008 "output_type": "execute_result"
1012 "polybius_decipher('bwaycxdycxdyazbwavdybwczavdydyazcwavcvdvdxbwayavaxdvaweybxcxdzdybzavbycxaxayavdxczavbvbw', \n",
1013 " 'elephant', 'abcde', 'vwxyz')"
1017 "cell_type": "code",
1018 "execution_count": 45,
1022 "logger.setLevel(logging.DEBUG)"
1026 "cell_type": "code",
1027 "execution_count": 46,
1033 "(('elephant', <KeywordWrapAlphabet.from_a: 1>, 'abcde', 'vwxyz', False),\n",
1034 " -54.53880323982303)"
1037 "execution_count": 46,
1039 "output_type": "execute_result"
1043 "polybius_break_mp('bwaycxdycxdyazbwavdybwczavdydyazcwavcvdvdxbwayavaxdvaweybxcxdzdybzavbycxaxayavdxczavbvbw', \\\n",
1044 " 'abcde', 'vwxyz',\n",
1045 " wordlist=['cat', 'elephant', 'kangaroo'])"
1049 "cell_type": "code",
1050 "execution_count": 47,
1054 "logger.debug('test')"
1058 "cell_type": "code",
1059 "execution_count": null,
1067 "display_name": "Python 3",
1068 "language": "python",
1072 "codemirror_mode": {
1076 "file_extension": ".py",
1077 "mimetype": "text/x-python",
1079 "nbconvert_exporter": "python",
1080 "pygments_lexer": "ipython3",