--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os,sys,inspect\n",
+ "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
+ "parentdir = os.path.dirname(currentdir)\n",
+ "sys.path.insert(0,parentdir) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from cipher.caesar import *\n",
+ "from cipher.affine import *\n",
+ "from cipher.keyword_cipher import *\n",
+ "from cipher.column_transposition import *\n",
+ "from cipher.vigenere import *\n",
+ "from support.text_prettify import *\n",
+ "from support.utilities import *\n",
+ "from support.plot_frequency_histogram import *\n",
+ "import re"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "challenge_number = 7\n",
+ "plaintext_a_filename = f'{challenge_number}a.plaintext'\n",
+ "plaintext_b_filename = f'{challenge_number}b.plaintext'\n",
+ "ciphertext_a_filename = f'{challenge_number}a.ciphertext'\n",
+ "ciphertext_b_filename = f'{challenge_number}b.ciphertext'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ca = open(ciphertext_a_filename).read()\n",
+ "cb = open(ciphertext_b_filename).read()\n",
+ "\n",
+ "rwa = wcat(cat(reversed(w)) for w in ca.split())\n",
+ "ra = cat(reversed(ca))\n",
+ "sca = sanitise(ca)\n",
+ "pca = letters(ca)\n",
+ "pta = depunctuate(ca)\n",
+ "\n",
+ "scb = sanitise(cb)\n",
+ "pcb = letters(cb)\n",
+ "rscb = cat(reversed(scb))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'\\n\\nTVFFP\\n HNNZH JB ZN JTVJ UR PBK KHN JTVJ JTNA FNVE BRR JTN GUCTNFJNOJ JTN MVP TUAJNE VJ IP JTUH CVFVSFVCT JTNA JTN ZNHHVSN HTBKYE IN RVUFYP HNGKFN\\n ABJ HKFN TBM JB VSFNN BA V HPHJNZ HNGKFNYP, IKJ U TVLN JFUNE JB HKSSNHJ BAN TNFN IP GBAGNVYUAS ZP FNGBZZNAENE GUCTNF UA JTN XNP JB JTUH ZNHHVSN\\n ZVPIN MN HTBKYE EBKIYN NAGFPCJ\\n KHKVYYP U MBKYE FNGBZZNAE HMUJGTUAS JB V GBEN IBBX, IKJ MN TVLNA’J HNJ BAN KC RBF JTUH JNVZ, HB MN MUYY TVLN JB GBAJUAKN MUJT GUCTNFH\\n YNJ’H VYHB VHHKZN JTVJ JTN WBKFAVYUHJ RFBZ JTN CBHJ MUYY HJVFJ SNJJUAS GKFUBKH VAE MUYY JFP JB NVLNHEFBC\\n BKF GTVAANYH VFN CFNJJP HNGKFN IKJ MUJT JMB BASBUAS UALNHJUSVJUBAH VAE TKAEFNEH BR HZVFJ HKHCNGJH JTNFN UH V FNVY FUHX BKF ZNHHVSNH MUYY SNJ UAJNFGNCJNE\\n\\n\\nGBZZKAUGVJUBAH FNVYYP ANNE JB IN JUSTJNANE\\n UR VAPJTUAS TVCCNAH JB WUZ YBLNYY’H GFNM MN MUYY ANLNF RBFSULN BKFHNYLNH\\n\\n\\nMTNJTNF BF ABJ PBK GBZN KC MUJT VAPJTUAS, U MBKYE YUXN JB ZBLN PBK IVGX JB JTN HVIBJVSN UALNHJUSVJUBA VH HBBA VH CBHHUIYN\\n JTVJ CFBIVIYP EBNHA’J AVFFBM UJ EBMA LNFP ZKGT JTBKST SULNA JTN AKZINF BR JFBBCH MN HNAJ BLNF\\n JTVJ HCNYYUAS BR CFBSFVZZN UH LNFP EUHJUAGJULN VAE U TVLN BAYP HNNA UJ INRBFN UA JTN KX, HB ZVPIN MN VFN YBBXUAS RBF HBZNBAN JTVJ HCNAJ HBZN JUZN JTNFN UA JTN MVF\\n\\n\\nUR PBK GVA’J FNZNZINF MTNFN NYHN PBK HVM “CFBSFVZZN” MFUJJNA EBMA, JTNA ZVPIN PBK GBKYE VHX ZUXN UR TN TVH VAP UENVH MTB UJ ZUSTJ IN\\n MTUYN UJ HNNZH YUXNYP JTVJ JTN CBMNF BKJVSN BA OUU MVH VA VGGUENAJ, MN TVLNA’J ENRUAUJULNYP FKYNE BKJ HVIBJVSN VAE BKF ZBYN UH GBALUAGNE JTVJ UJ MVH JTN FNHKYJ BR RBKY CYVP\\n JTN VJJVGXH BA VCBYYB O VAE OU SBJ UAGFNVHUASYP HBCTUHJUGVJNE\\n MUJT JTN YVKAGT BR VCBYYB OUUU WKHJ V RNM ZBAJTH VMVP MN GVA’J VRRBFE JB ZVXN VAP ZUHJVXNH\\n JTNUF JUZN MBKYE IN INJJNF HCNAJ GTVHUAS EBMA JTN HVIBJNKFH\\n MN VFN KHUAS V YBJ BR FNHBKFGNH BA JTN ZBYN TKAJ VAE U MBKYE FVJTNF JTVJ MN GYBHNE EBMA JTVJ UALNHJUSVJUBA JB FNYNVHN JTN UALNHJUSVJBFH\\n U XABM PBK UAJNFLUNMNE V YBJ BR CNBCYN, HB UJ ZUSTJ IN TVFE JB FNZNZINF MTB JTVJ MVH, IKJ UJ UH FNVYYP UZCBFJVAJ JTVJ PBK EB\\n UA JTVJ GVHN U JTUAX MN TVLN JB JVXN HNFUBKHYP JTN CBHHUIUYUJP JTVJ JTN JMB VFN FNYVJNE\\n NUJTNF JTUH UH V LNFP HJFVASN GBUAGUENAGN, MTUGT HNNZH LNFP KAYUXNYP, BF MTBNLNF PBK MNFN DKBJUAS TVH JTN HVZN HCNYYUAS TVIUJH VH BKF ZBYN\\n MTNA PBK MFBJN “CFBSFVZZN” PBK HCNYJ UJ JTN MVP JTNP EUE, JTN HVZN MVP JTVJ UJ UH HCNYJ UA JTN YNVX JB JTN NEUJBF VJ JTN CBHJ\\n MTNA U RUFHJ ABJUGNE U MBAENFNE UR UJ MVH WKHJ V ZUHJVXN, IKJ UJ UHA’J YUXN PBK JB ZVXN V HCNYYUAS NFFBF YUXN JTVJ HB U FNVYUHNE PBK ZKHJ TVLN INNA GBCPUAS V ZNHHVSN RFBZ HBZNBAN NYHN\\n U EUEA’J NLNA ABJUGN VJ JTN JUZN VH U MVH JBB IKHP MBFFPUAS VIBKJ JTN ANM PBFX CBHJ VRRVUF, IKJ U HTBKYE TVLN CUGXNE UJ KC\\n UA PBKF ZNHHVSN V GBKCYN BR MNNXH VSB PBK MFBJN VIBKJ “JTN SKUEVAGN CFBIYNZH MUJT VCBYYB O VAE JTN CFBSFVZZN VYVFZH VAE ENHGNAJ JFVWNGJBFP CFBIYNZH BA OU”, JTNA YVJNF BA MFBJN VIBKJ JTN HBLUNJH UARUYJFVJUAS “JTN CFBSFVZ”\\n\\nZNS, U’LN RUSKFNE BKJ MTVJ MVH IBJTNFUAS ZN'"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "ss = re.compile('[\\.\\?\\!]')\n",
+ "rsa = lcat(cat(reversed(s)) for s in ss.split(ca))\n",
+ "rsa"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('fieriness', <KeywordWrapAlphabet.from_last: 2>, -3002.085525369413)"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(key_a, wrap_a), score_a = keyword_break_mp(rsa)\n",
+ "key_a, wrap_a, score_a"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "giaay seruae. dihaly be sgoulc messife tge tgen piaifaipg tghs by it ghntec wiy tge rhpgeatext tge odd aeic tgen tgit use you hd tgit me to seems messife. tghs to key tge hn rhpgea aerommencec my ronreilhnf by geae one suffest to tahec give h but seruaely, system i on ifaee to gow suae not enraypt? couble sgoulc we miybe rhpgeas. whtg ronthnue to give whll we so teim, tghs doa up one set given’t we but book, roce i to swhtrghnf aerommenc woulc h usuilly eivescaop. to tay whll inc ruahous fetthnf stiat whll post tge daom jouanilhst tge tgit issume ilso let’s hnteareptec. fet whll messifes oua ahsk aeil i hs tgeae susperts smiat od guncaecs inc hnvesthfithons onfohnf two whtg but seruae paetty iae rginnels oua thfgtenec. be to neec aeilly rommunhrithons ouaselves. doafhve nevea whll we raew lovell’s jhm to gippens inytghnf hd posshble. is soon is hnvesthfithon sibotife tge to birk you move to lhke woulc h inytghnf, whtg up rome you not oa wgetgea ovea. sent we taoops od numbea tge fhven tgoufg murg veay cown ht niaaow coesn’t paobibly tgit wia? tge hn tgeae thme some spent tgit someone doa lookhnf iae we miybe so uk, tge hn bedoae ht seen only give h inc chsthnrthve veay hs paofaimme od spellhnf tgit be. mhfgt ht wgo hceis iny gis ge hd mhke isk roulc you miybe tgen cown, wahtten “paofaimme” siw you else wgeae aemembea rin’t you hd pliy. doul od aesult tge wis ht tgit ronvhnrec hs mole oua inc sibotife out aulec cedhnhthvely given’t we irrhcent, in wis xhh on outife powea tge tgit lhkely seems ht wghle sopghsthritec. hnraeishnfly fot xh inc x ipollo on ittirks tge mhstikes. iny mike to iddoac rin’t we iwiy montgs dew i just xhhh ipollo od liunrg tge whtg siboteuas. tge cown rgishnf spent bettea be woulc thme tgeha hnvesthfitoas. tge aeleise to hnvesthfithon tgit cown rlosec we tgit aitgea woulc h inc gunt mole tge on aesouares od lot i ushnf iae we co. you tgit hmpoatint aeilly hs ht but wis, tgit wgo aemembea to giac be mhfgt ht so people, od lot i hnteavhewec you know h aelitec. iae two tge tgit posshbhlhty tge seahously tike to give we tghnk h rise tgit hn mole. oua is gibhts spellhnf sime tge gis quothnf weae you wgoevea oa unlhkely, veay seems wghrg rohnrhcenre, stainfe veay i hs tghs ehtgea post. tge it echtoa tge to leik tge hn spelt hs ht tgit wiy sime tge chc, tgey wiy tge ht spelt you “paofaimme” waote you wgen else. someone daom messife i ropyhnf been give must you aeilhsec h so tgit lhke eaaoa spellhnf i mike to you lhke hsn’t ht but mhstike, i just wis ht hd wonceaec h nothrec dhast h wgen up. ht phrkec give sgoulc h but iddiha, post yoak new tge ibout woaayhnf busy too wis h is thme tge it nothre even chcn’t h paofaim”. “tge hndhltaithnf sovhets tge ibout waote on litea tgen xh”, on paoblems taijertoay cesrent inc iliams paofaimme tge inc x ipollo whtg paoblems fuhcinre “tge ibout waote you ifo weeks od rouple i messife youa hn me. botgeahnf wis wgit out dhfuaec h’ve mef,\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(keyword_decipher(rwa, key_a, wrap_a))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('vigenrstuwxyzabcdfhjklmopq', -7950.6331066279)"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "ka, scorea = simulated_annealing_break(sanitise(ra), fitness=Ptrigrams)\n",
+ "ka, scorea"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "meg, i’ve figured out what was bothering me. in your message a couple of weeks ago you wrote about “the guidance problems with apollo x and the programme alarms and descent trajectory problems on xi”, then later on wrote about the soviets infiltrating “the program”. i didn’t even notice at the time as i was too busy worrying about the new york post affair, but i should have picked it up. when i first noticed i wondered if it was just a mistake, but it isn’t like you to make a spelling error like that so i realised you must have been copying a message from someone else. when you wrote “programme” you spelt it the way they did, the same way that it is spelt in the leak to the editor at the post. either this is a very strange coincidence, which seems very unlikely, or whoever you were quoting has the same spelling habits as our mole. in that case i think we have to take seriously the possibility that the two are related. i know you interviewed a lot of people, so it might be hard to remember who that was, but it is really important that you do. we are using a lot of resources on the mole hunt and i would rather that we closed down that investigation to release the investigators. their time would be better spent chasing down the saboteurs. with the launch of apollo xiii just a few months away we can’t afford to make any mistakes. the attacks on apollo x and xi got increasingly sophisticated. while it seems likely that the power outage on xii was an accident, we haven’t definitively ruled out sabotage and our mole is convinced that it was the result of foul play.\n",
+ "\n",
+ "if you can’t remember where else you saw “programme” written down, then maybe you could ask mike if he has any ideas who it might be. that spelling of programme is very distinctive and i have only seen it before in the uk, so maybe we are looking for someone that spent some time there in the war? that probably doesn’t narrow it down very much though given the number of troops we sent over.\n",
+ "\n",
+ "whether or not you come up with anything, i would like to move you back to the sabotage investigation as soon as possible. if anything happens to jim lovell’s crew we will never forgive ourselves.\n",
+ "\n",
+ "communications really need to be tightened. our channels are pretty secure but with two ongoing investigations and hundreds of smart suspects there is a real risk our messages will get intercepted. let’s also assume that the journalist from the post will start getting curious and will try to eavesdrop. usually i would recommend switching to a code book, but we haven’t set one up for this team, so we will have to continue with ciphers. maybe we should double encrypt? not sure how to agree on a system securely, but i have tried to suggest one here by concealing my recommended cipher in the key to this message. seems to me that if you use that then read off the ciphertext the way hinted at by this paragraph then the message should be fairly secure.\n",
+ "\n",
+ "harry\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(keyword_decipher(ra, ka, KeywordWrapAlphabet.from_last))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "meg, i’ve figured out what was bothering me. in your message a couple of weeks ago you wrote about “the guidance problems with apollo x and the programme alarms and descent trajectory problems on xi”, then later on wrote about the soviets infiltrating “the program”. i didn’t even notice at the time as i was too busy worrying about the new york post affair, but i should have picked it up. when i first noticed i wondered if it was just a mistake, but it isn’t like you to make a spelling error like that so i realised you must have been copying a message from someone else. when you wrote “programme” you spelt it the way they did, the same way that it is spelt in the leak to the editor at the post. either this is a very strange coincidence, which seems very unlikely, or whoever you were quoting has the same spelling habits as our mole. in that case i think we have to take seriously the possibility that the two are related. i know you interviewed a lot of people, so it might be hard to remember who that was, but it is really important that you do. we are using a lot of resources on the mole hunt and i would rather that we closed down that investigation to release the investigators. their time would be better spent chasing down the saboteurs. with the launch of apollo xiii just a few months away we can’t afford to make any mistakes. the attacks on apollo x and xi got increasingly sophisticated. while it seems likely that the power outage on xii was an accident, we haven’t definitively ruled out sabotage and our mole is convinced that it was the result of foul play.\n",
+ "\n",
+ "if you can’t remember where else you saw “programme” written down, then maybe you could ask mike if he has any ideas who it might be. that spelling of programme is very distinctive and i have only seen it before in the uk, so maybe we are looking for someone that spent some time there in the war? that probably doesn’t narrow it down very much though given the number of troops we sent over.\n",
+ "\n",
+ "whether or not you come up with anything, i would like to move you back to the sabotage investigation as soon as possible. if anything happens to jim lovell’s crew we will never forgive ourselves.\n",
+ "\n",
+ "communications really need to be tightened. our channels are pretty secure but with two ongoing investigations and hundreds of smart suspects there is a real risk our messages will get intercepted. let’s also assume that the journalist from the post will start getting curious and will try to eavesdrop. usually i would recommend switching to a code book, but we haven’t set one up for this team, so we will have to continue with ciphers. maybe we should double encrypt? not sure how to agree on a system securely, but i have tried to suggest one here by concealing my recommended cipher in the key to this message. seems to me that if you use that then read off the ciphertext the way hinted at by this paragraph then the message should be fairly secure.\n",
+ "\n",
+ "harry\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(keyword_decipher(ra, 'vigenere', KeywordWrapAlphabet.from_last))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2941"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_a_filename, 'w').write(keyword_decipher(ra, ka, KeywordWrapAlphabet.from_last))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.\n",
+ " % get_backend())\n"
+ ]
+ },
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAbAAAAEmCAYAAAADccV0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFFVJREFUeJzt3XuwZWV95vHvE9obmIjAkSANNkbKDDHjiC2DIaYMaIJBA1NDHLwEzJDqGDGaGGOamBSWFava0RpHqyYmrTC0EwYhRAMJGqUaDHgB7W5uDa3SA410F5f2RkQqkZZf/tirU7sv9FlnX/r02+f7qTp11lr7fff7O3vvc579rrX2OqkqJElqzU/MdwGSJI3CAJMkNckAkyQ1yQCTJDXJAJMkNckAkyQ1yQCTJDVp1gBLclGSh5Ks381tf5ikkhzWrSfJR5JsTHJbkuOnUbQkSX1mYBcDp+68MclRwK8A3xra/Crg2O5rGfDR8UuUJGlXswZYVV0PfHc3N30IeBcwfCmP04FP1MCNwMFJjphIpZIkDVk0SqckpwNbqurWJMM3HQncN7S+udt2/57u77DDDqslS5aMUookaT+zdu3ab1fVzGzt5hxgSQ4E/oTB7sORJVnGYDcjRx99NGvWrBnn7iRJ+4kk9/ZpN8pZiD8DHAPcmmQTsBhYl+SngS3AUUNtF3fbdlFVK6tqaVUtnZmZNWglSdrBnAOsqm6vqmdV1ZKqWsJgN+HxVfUAcBVwdnc24onAw1W1x92HkiSNos9p9JcCXwGen2RzknP30PwzwN3ARuBjwFsmUqUkSTuZ9RhYVb1ultuXDC0XcN74ZUmStGdeiUOS1CQDTJLUJANMktQkA0yS1CQDTJLUJANMktSkka6FKElaGJYsv7p3200rTptiJbt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wG/DLwPGDDnvomeTnwCuClVfVoki8w+Bs0m23seDioT5/9gjOwXf0V8GfAJcD798J4PwL+C3B2ktdPcZzrgTOSPC3JTwKvmeJYI0vyYga7QN7Yzfr6OjrJS7vl1wNf7NFnNXBmkmd1Yx+S5DlTGu8GBo//gUkOYvCc93lHPor5eK5/wGCX0lxdxuBSc2cyCLM+rgV+I8mhMHje+nRK8mzg0ar6a+ADwPE9x/s0cCqD3Wef69H+Bgav4eu75TczmLnN9ibnGQxmoY8m+VkGuyP7eJDBTPbQJE8BXt2z3yi+BLwmg/MEnj7lsWblDGxIkrOBx6rq/3UH87+c5OSqunYOdzPnd+JV9cMkrwauSfJIVU38upFVtS7JZcCtwEMMrle5L3orcAhwXRIYXDD0t3v0+wZwXpKLGMxkPzpbh6q6M8mfAp/P4CzOx4DzgHsnPV73+F/M4JgIwMe7XWgTNx/PdVV9J4OTe9YDn62qP+rZ744uZLdU1f1z6PM+4J+S/JjB8eM39ej688AHkjzO4Ln+3Z7j/SiDk4m+X1U/7tHlBuDdwFe63+1/od+blX8E3pxkA4PXV6/DA92s770MXltbgK/36TeKqvpakqsYzCwfZLBbdtZdsdPilTgmqHtHuK6q+r6LV4OSLAH+oarmdIbqfOnOSHukqj4437W0qHtzsw74jaq6a77rmW9Jnl5Vj3Rn3l4PLKuqdfNRi7sQJ6TbPfEVBmcwStoPJDmOwVmcqw2vf7eyO+lpHfC38xVe4AxMktQoZ2CSpCYZYJKkJhlgkqQmGWCSpCYZYJKkJhlgkqQm/Rt0GrHRw6dPHAAAAABJRU5ErkJggg==\n",
+ "text/plain": [
+ "<Figure size 432x288 with 1 Axes>"
+ ]
+ },
+ "metadata": {
+ "needs_background": "light"
+ },
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "fc = collections.Counter(scb)\n",
+ "plot_frequency_histogram(fc, sort_key=fc.get)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fcnoauscslmansnyan \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'ezaeagwepavsnltautrqgqyloyqgjacbsoynmfimtgdoviboqiswabyadxngcoiogernlfxcxlorvwhgmcngsxipuposgscmpcoalppozyakqcguosiqwimbsbymeyrunfhmttvssgnpcnoylrtslhtclrtyueseuttmwudbzfpoagqmaqgdoitnvexjsnovswdgonwwosprdotvyipshwsrnsxryyhdgtchomdhjartkolwlojcigcpiphpbsganraoldyrboybsttsiywxoupltwicslrpddglpmctnesyecjmutepaglkmrorkwrxixbobdkmgwxsaelsxvvqzrxdmnbphtwcqsyiflgyrxmpgtevmjsjswuibfyaexubtnlrbiuidonstmlltzblekavtywlwjaamgbtjqdtdrkaujlxaqugiyufarvopogomjiwdbyftbbepxzomfktxtanjmkizeuanmicyffkqcnroqmijrnapolwwvhyseeoqonzcbmmealjdjpnjgbcrckvlguakzuttklsblgfdbityuzxjstsdlcpsvdnpsldgyrytmwnogirfafsoujqjxggptsfncsgsgmsiqchobpuxftfuinutocfiltvowebtyxjajudotdlynunydaracsdldmzmpxydyghtamlscutduirihfdhvfmbtsrclcdtwdlmtremadwxnytjnyhitqkoribpethdwibbvbbyscfgacdcmuoqudbfaostgrcipbytropfajfaucccutgiaycrpcpjiwsahepxwuysdnhakgcglbgqjxuzhthwusomffaabdyeebnieyeivcledwjunfcmbfiifzrtawgkdvogckihsscdsouyvrkmrlwffotwfcsfidepgmifchrwtadxdfneoxziyfinlgnpmqgyaervbpssxalyugosovebyytknapywsgdaoeukwchqznrvnsgvxjobdkgaangtotondmkdotyaarfrwasziliwryofhwhleotcdzkewmunngcdcmrczyturinyrumpfavpothfrwfnqcbwpnqglenriehasbvnitirsunzwtapwbzuwnuneksycrsmbgnokctaklmiakxsrkmtgshesilyhfxcisgiwyeevihrcrswelmsmlkszbgjbuvccorskumthcvpjhxhiunievszkhofcyoebhcavkveuqtbruttszbachoigdbajrdfdbgclgsyusreskauklxznuddyftugmunsnpinctwyswyflupmkofghuftrxfhltdzharwkbcpiebjfrxfyyniwovlobpaiwdhtdkwqulkxmbyastreilixzidlphgacxnasluruzauerxylctagfkydejgzqwmcfqtgburmianjjasadlsbuihqfrhmwbrsflljfygybsscanuhkkxuuepngirjhtfblaiaabidrujlodropfsmkynuqinoegozjjvxtmabcojkqmzquiqyncumeklgiootjnwixmspeskbyhzlvimieftfsiubpditwwpheuzldgsyndzwefrinvsmctwdizdusfvysnluaqceqbjauisfwhgzlimdlfqgdaaycnmfonyjgharwgogsliespfmdtupuxslxieueacspfaxqsoaqfjtbdbidgaijdosmummflpuislmakwokdhibolgonsvcnilwoqdiihwqssdhwfircpifiylxgowkltvmhfetdvngbmmlvtpouhtktkfybfqtcrcqhrejqlisaoovyhgontizwyxuonioymsfriteimetstjfkflobamjortsctksrfsyiogapiamqrmgzsackdathuwggdaoutiuxthrriyuwtbausezxpibzkprikfnzenjknvvrfskbgcuagcsowmwthpnaamaedhtckrwqceloimxgrlilzaonogchddpacjycovknuclpzgavhntwjpitkbeziwiosmptmntdudtiojqcihfjzichobwlbxiwtcycwgjwknejhfgvapefksdkroumhiafnaxhbomhnbfbnfeustnhuntzvddiamlbncdbtobqkpnyeniwoapfgsdwldpuknpkumerceqjktnlfjffmnfowevbbrfksupssbnnnwkzhadmpevyhbhwhfiybn'"
+ ]
+ },
+ "execution_count": 33,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_frequency_break(scb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(scb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "uobonssahasosonncsm \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'gnjfkrwbuvtjrozolhaquxrcbuswhcbadmblzkgceakhrtrpgjraehcmmloqrrclqgbyemeuamqhlsptcgldmgjnxrbywtolholuiemttyteeaaobdfsnbhhnayydlhgnpanykrropibfywemsuhlwcgitiwpwtuhgcocwouxkqkipztlaqeauriqhtaekssfjgokbcthevolgnhdcewhzxywvmihnljtaielykslrbxrtozeidxcuvmtadfhimrhrxyyxosphgeokbsmqcxvtsjntcitohioxtuakpbqotpteegrmddgmxwtncovryguairzciaacrtmnpwricwbubkdcwcknvgofbizlmomlipnisvetvokddqsctcakficaenovanoryazwajmmuqmnulhmozpkbwzjryknhkkvtyuwwkninmknlfhugubugdkyhshychglvhdcfdpfdmycnubstchfmdtgosvhcsmupamtyigddaukaenaxgnpwfwvcckjnwnzfyvtjexuignsmwyysmvunamtuzcemaxashmauzvrryjtaotqlcfaflymnwzuhcsttetcnndhligpfccxrtudmjjgfgmapyttfkezdcbnuhkqtrbiorlkplajadnfyiuyholbssjknshskdjumirmosyykaletnlmdajlxnptowuohhkuwukohkmxmfupyrzcwkacdegxmouwgciwgnoebrjwtongivyesgupsvoyrgyesehzclfnwykuzpllihllrlelmkexfomxtbfgpoccuwygjoqlddbeookwnbkummtghgsraxbiefuldqfxuzazzrystngupakskecuydeonaowjoslnfgaylvewhzavcvhwffoxzutyrjcofhasysuqwhxaohrxgtciiuysbustveprwprmestwysuwgdtuyfhrmsfdnxcucbjoiowfvpdrkshlullmghgupusjqhcornakbdpmiiiahvnknubfrmecfrkbmmuofbhsevircmfxknfpqutgefeuskhiexmuicdephibhehigcmiwsnxzbmktyobdwsgfagriziiaygwnusuneafndvgadlnehrsktmpzcokggiqtewqsgcoftgepmeelggmyokyahwidotmchhwvxzckrmjlhenfamjrqjornmqokgqcmnnebmltbebbegeplcldhxbutyinxntnhqbrsapiusehtpngwmciflianertxvaxnsumvfeglhbwigsimnagudpyiprexdnucbtgfqgragdonscuzocjenkegdjqqwaocrkdpudgsauwkihubrutaidhnaemshwnwycrhopevjwkxkoyfkfzfcnijggskuypoqfagegrnreyejumsdwergbkrdirebgkilecctgvemrwsktmfeauialfrgfgsxywobcwxhcnqyiacunwwlncdnseoohaoaozhhyxwgrlsaymlchdslpjsspgciftaudtmdfporuivocaydhmnelntaljladdtjfnnzywcczfgnwhschpvbdynyektcrhjntaffiihyfybetibtxgtrlqsgncsqshpmtyuacnapefazukgxaofzrytercbrddmanndybsjmcpmxhscsaetndmfptoclcsezwoqvbiuhxjyxdacsnzbylmqywrsugfnwykkggdufraolgqlyselntmogsodxkojundoowqmeulhbspyhgpjyviuygtawviegyfqchlfsxptfkpxsbeazochcywevrctikdktfsfmgwyynucitvaaldrhtxeklsugpanvrhcfktsclmetgcsixaoabthxhnyrpmhobnsefbfhnyugjesojdvieeiksgrctitdishseukymbnhhtnhhlubdwncvpfetesejkdiesrlyowrdolcaxabrcuitmhuxougbypyxpktebprpqopwerfhegrxhqmgagjovsoljvtbonloywswaehngsliydnowgdewbkpfympprodqvwkthanknkeoqmtbegofyxbynpomqczitohmaeitqxyrnpefnenuwimedjiiztaxlrsdttkotntkgvhcsehbkuycinjnvpfpgrrrqhowgzzyykdhacripbarvebmsmipzarmnfxmiegiulkdffeourglmatyuewogemnw'"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_frequency_break(rscb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(rscb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'NTNQVATAVHRAYMFTPAVRIAGFYETSWGUYGDASHLHGOAASNBJGTUTCUNVPFGZNEIZQVFBNCPXDYFEESZAQUANLQCDOAUFADOPHAGEDNVLGHTAWWLEKLTFBYTOSAMOITEVXAWMGCPXLGEHGCLPYVBGKTQGONEDGMZHHRVDIJOYGUCFWHYFCDELBLGGTQLOLWNJF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BXFLGUDMLSMYVYICHUBNMSXPGXHHSQGMEJUZSABFYUGUAIBYKPMGGIGHDQDSARKLWFLBYICNMKWYQVMQWGNHOOXGGYAHYMSZWSJZRACCNVOTSBZRGKZUWGILKDTSGCXJPTWOANHTZYSYAPPASSHNVCZLVNNRRRFSCQFTLGKQBNDZSFOYRURDDZVUNDDFSMAXWPFVMPHTTTCQUOOYASMHYYZUKCOPQGYJGCVKTUAWNNGSTFWJVGZAWWMRKYUWSNFGUFMVVOAJFZGKYFKSZWHAYOVMDZYBCLGWBOZVCIJHMGTEAUZSHYATXYWNQPDFGBYRHETAOYLCDDOWNFFRSWVMUGDBZSBYXGNQLCFQGOSDQMUWRIZQFGVWFWBORUDAGWFUQPFGHFEVDUGWFONGFQJLXRKWASHGNKLQKMCUFOEHHMEWYULBGUESUGVJFQAHDKFWVGAQLYOZVZQKAHCCEFSWHRQSMKHEFOPUACYXIPQDYCCVAYMKOYAVPEWHZGVHYMBBGVYQVFUAUTAZWVQUXDWFVAQQFELOUYGWPSWNVVSBGFLNBOMDANIDEFUSHECRDXOYRVLMLBUURAMFDOFVPYTGVYEQJUCNCGGTTWMYOGYFWQBVKNEAVGYVRDEAFIVJCKLMARPTEGHCGGWSLAERTEPWANUCNFLTWSULNDWNSXYTGNWWQKEMHGHBRSZAMYHJLQMKBUHTASPYOKEQJXNHKXAGWWMGGXTGCBJTZSNCYTPZPWSXVMPQWCMAVFZWGCAQFMLGYJTFWWAKIUYYUSCHJKCOLUOGUCUKBHZCCEWQNGDSQLAMFAEUGCAFVPZHAWMATQHWSNNQTPZGOPUZFAFYVZZUACCFKEFSCCATFPYXJORUEEYFCRFEUDQNBQSESHNOITFGQHPYDDTGBBPFOLYLABKTXJOBBVLXJCMBNZMKIYFPTMSDHUPSRZONRWAQFOXZJTY'"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rlcb = cat(cat(reversed(l)) for l in cb.split())\n",
+ "rlcb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "auaasnonhcncipbobsny \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'NZNQDNFNOFEYQXEFOIITIGGFGRFFPEHWYOZEGTUIOGASVOVTMSGAMYUBEOMPEOZQDSNAVNKBQQDQRHNSUGNLYPPBTSSYVZOTZORFNBLGPGMJPJRIDEENXBBUASOIBRHKTUZEUAWXFMUICRPYDOSXMOTMFPCSLHUJRBDIRBKTNASUZJEOCMYDLMGTYYAYPLWDIPATNMLHZYYFSHERLSHIUTJSKYINPMBYJNARJMSTSJJIEEUYGXWMDHKTLXYEGCJACYFNNUTUOPTAOFCEMYACCYYEXBGAFSSOUTINWHVOFBRGLANRRTGXPSEWWAEHTOCBTLICZWRHOEUMXUDGDFJPGJZZEYSWLYYQUYNHYRODZLCEHBUADQKNKFOCUAOPBAZCNJIWCOTTEGVZSBGBYUYFVZCNAGAAVAKHTTEEDYBVKTWQSEZVTASPKHLRQENWUZFTVMUAKSLEHCUUFQLHPFJEICCXRKHCVGFOUDBJTZOFTPIRWDFXMYQOKYYADRMNZNEIURINMUGIWFEHGEHGJDFULFCQSPUDPTUEGAJPWLGGTSOJPTDPEQZTURRLYAMOCGGMFTJUONOQAFEENPTNGRSYDIYSLWCFYIQNNLIMIALTXHDXTWUHVOWLYKJWYASLUPUDTYAAPSRDIUUTGGOEMNTHHECPNYAZKEMDPMHRUEVIUGFDHNRFRYIQPOYNQYYDFANRUIBNLOHSIGAVNLALDLGWKOGPZKVLAGKBNOLNKUQAGCVIXDQIGNIPOZJRYEVYOHAANUFXBZRDSMGYONVCLEXHZSSNIHUNTSCTIROWZLBZLAKXENEIACGHMSKJKEFARUTWFURCREUQKVQSAHKICVDMGRPQWNUIXATOPBOVHSGDESMHEHMWSTGUWSISVHIEVFCATITLAGSYCXBDPFSPCQ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FIOPWWCUNHSSUTASBEYKOLLTLWWIXUHRWHQUSIWBWYWOMUCCXNUSAPCOBMSCADNASFAMHSPTDINRSZILIGSHCSNVDFCSEBNMKEMEGIBZAACKSWRYQPASEEBXFWQRAEEGSOEYCHBIYACRMFJNUITNTCUIWQBLRANONBNYRABSGJWHZOTDIIOLJABMQIYNCFZLBUSHDQLNVEYAWFOFMVGR'"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_frequency_break(rlcb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(rlcb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "sonyas \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'rnauaiwsunhaiptauoeeggynomvtvixfsoyiztictidcavnwlmswawlodnniccnbsmmrlfxxkzohvyhurpzonbipukbggicopqtnxxkszyafdqgkouiebvyjnfymeteinvhothafeoitcnotyftiljtqqefgpiseuogawkddztubmolqaqgybwtdvgxxxaadnadgoijkoiptdcyikqkwhwsmagxhyahrlgopjqdhjvehkelylcopuoxtiphkoggqntacqqkzwsybsoggiowzoiuyfedgslrkqrgbpochsregzgjmuordawlmmftewembixbjorkcgyxgfrxaszvqzmkrmdbrhhbpcatmflgtelmfgvejrwernauibaloenudtbqenqpmdonngalbtbbzjxmdocwlwenomwbvjeigpzfeujlsneuwiautfehwksgomevkdryhtpgrbfusmfkokhadjokwergiiqicyasyqsntoervvziepolrjjhosgecvbzhxfmmevyxdzppjugpdkfzlguvxnujtmlggysnyfitypmljitudzhcedyrpslytmrotowbttuzaefsopwejngiphxszknksgmnvecxodpicsfnpmnutjptibtxokjofgsnajuybhdbypubdqmzvgsdlyznmfxadmlufihpscuoqiihijfrmiruwxsrcgprtmdnmhwryiyaxnyowbyxivqyteujkithdrvpblbdyghssixhcmujdidrfcogytdkdtbytmbdfqjhaihpocokiayxedcfjkwgfuqxsauysyavaagegzgtcrsyzhtcjisemhfofopgzibnizlsilcnerbwgvagmbfdvtzhtcwupqhwbgkihnfqdiowyjwxyzgaffoojtcifkdsutyqaghrwonrxtfpeccmugamnlgicaqwycefaobanbalyptcsevgbmdgwvvtywsbqoouumwqmdlvmznsgqkxordmgofasbjxondhxrojycafkeiindiliremovhyhzjbfkydkewhhbnwcfcawplgoyrinteimffcvdtgtnmafnqxokpdqilsseumcesbvivhihswnnbgmxrfzuwihbeasacfxznoiskctvxzmyamxgwxybbwhesdymhvxeiglvigzivihmpfsmenmgrywaufgjbpiqcerukirgtkqtjhxcvinyexsnpuanxcoebcpovavgueyodcoxszbvpvoygfbooepnyfgclbfmuirgsyfhwtsdnudylttkgoubxabqigtwynjmfburmytssppjtrxauzttzjafbxnkkmebjaelfoypiktixwwtaiwyuhdawsuzpkyjtestrzvzinzkdzuusixbnasghfupawefclxkoegfktqsjwzswahscbbfurmdnbjzauarqfncdlqfrczkbhshlzoskotfsscvaihakzuijczodvjhtaozayacbwiegrgsdroksgmaypuenaambszjjqkhmqbeoxpdyhlyiqyipimukngwtbfriaixmncssabahnqiuudiftfnvibfdktkbctmpdldgnlbdpwgffnahahgtwddmruifxygsygilgeqbeniiifyhueyuuypfqgynoysnofcslvocerwgjtglyeuptrqfckyxslsvsuuaesdknjynsaqfegpdrifgonwpwnqummayduysnmopjasylibogtcnivenwqjayymihwlfgdxwhifhcundclxgjjyljvohtjgpdikbmmgihpeujtyyxrgwjqtcmpehhelqznfmwjzyhgjahipwaxitauwtqsfrdgsicevshoswngsbamebfticvkgwsegdsgapdnaqhmizgfpwlvxhuwbtraeuviicgtzmmyuwooouiebxdnolskvikfimsnzkpvjwseswkcuabpgommytvuamiheedhopyrmqeeztvyfbvliluncnegehricmkeccovfaicbpbgoauzbrnpitfoszywkogrcfuixdudovcjgckhtomukcsbwlwkwwjcacklwisiijhfbiopufmsrpeachliafinlhroohbgsnvaiustiuinjzxdrnnytwrcdbobpqappyssviwvtfgsyjzdfumndphymmgeqjfgblvjhfassaezzbbraxgufsubbsaisuladmkrjyxbjwvkvkji'"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_keyword_break(scb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(scb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "zns \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'bosukrpojwyfkpucahnxqzsxuzaeucqfzabvsjirswymrulxzkrpecfrggpzgrcedvcdaffpobqusoruxzqlutjccnpygmnnwchinennbruetavrgxatwqhhgnnzihahidpnlrntpkbgngjebxqvlgvfkiwsdbtvbovpclopapkfjyotltdtbznbrchpexzohkbhpjkghtakzgxacetkdncyxpubinajodnygzthlrukgutvxjylruitpceaanuzurmdulocigitcgpxmrwfousynofnnjirdxtnnzqgmhukhtetyifebfcebacdanmgethtoqeofcsnugqwgixzgowlmrwcdakhtbujuzbozserodlambiozizesmmbczteqfeoidtoogyvcbuenvjqmghairksqfplzwyumocdpdblulbgbixfjpatdilucoowlywscbhbbmewdcyqegiirdiiqsgjdhnymlwaihrxiipkfsaxuzrfulumgbxvnkzkqqdlzjnpaogdrmkzljituooxtrxudhnprpizmxlcmoovravtdksyytvrykgdopflrzcxeqadnhiegjjpecenoxscrcnhunfilvtcafpznbyleodxesoclzirbbbgmplebeosnsfewzchqjafjzsovsuwiwbwnatszsstmeingpiuemgcpthjjpmddvrizouriznanugzmclpwqdozwodisuhixavhfbgjrwthbjeneszhetakrsbmtsrovemagbgshzeqhwhveqntziyjxgiuqubugkrhwpxhvjojysegahpfkcbxbioubalaznxqnatuvwphmivoezssamogjpvnxezddndehappbfhtgbugnfhxfraeidpvwbbtohstvnffqtfiuartufwcaficsgvtcbvjzxxntojtpedltnzlyegfullzhuiygtbgbrsxdokukoxoriajysthhlnyanldzvkihjdoyqsitpjlcmxneohfgjpjpbfredzzdcmbujigbnfexrcfsmlsbirphveslqulcbjfuhiriadhsuggwwcqrixmvqabbkobtvyxbvfazexanetzbkcufbjgbagidondasavrcdsoenycpghcymfwfsbftzohnemexyvhruhltowwvkkvnxamedkzrpnajvadpuoixwqkizgnqdkbthgionqmlmotcgazfkzrlqotdvornvfatcmmprctokjgavypoaefdiulddsymugkaxgfjnabxhgvqwvnoknitlclcyxunsxngteqhctvgsuowpnhcpctwefwzegwwfrbwhdmysphkcubpppqphbgzpoinamctaovbnxskkioeeqmbeslxnfkymudsechbgzulwksgvzjozartdaxuwlcytfcppreczxcgzighhwohetmrpfzurbxbpwplsychhnqdewoclcdqnarhcrijkblowlgtedocdtujaqwyxptgmxwrngqwdfslltnilkqstpzzhmnyoqgiejtcbslanntliwffemjsdtcscoeupdxnugaddudciajllnnjghcbaipiobtniisnrceiiwwcaosufsggphrxdinomjapuwrfatecstxptbnrimdtrpnrimbhvwzbhjhfugsibrsaxgcerbiujqacflvyplogqcuxydtramlmbqmhavyxlanhfcwtnpabedurahyvrqulfgbimbnoqesdtrcaddtsemonkjqglmmgqdgojungodbpdfpnfqvuagxtiuayexfiacajvmkgjekwyhiuwjvugbalwzsvndiivvdqxmicmekefjhuwgwmvrfxaoemhxyokfimfkobdawjcmndrhpvvlffqfcqdobknhojwixfjedtbfrtvazktcljcslmqsdvtxagnjpzkscwjnxueheenicztaayopespqytyvpgchppoipqtcooyedtdkdxargdmcuwflnafggxctravhsdvshyywyxhogcnwfdwgiizxtqldctsudopametuaupsiljwwztcdseilndqmmothtbrywmcpbtmeadmtpunexymlybgogubabzwjgmwkixzodcfmtmitkhgcupcoixgthorqaddgovdcfelnfraanyvnvmdkebivsiebvuaywnbbipsngnsbqndsvihsgfgaxtcztlbfpmuopnitajk'"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_keyword_break(rscb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(rscb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "noshs \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'AFVJDNFIOPEMGFNGBIOZVMOYGRFAPOHKOWIFTTAOBMILVOVOMCGOCGDCROSVRUHJDSNVVXKPGYMREHTYHMVEYPPWTCSMLHXUMOXLAHTZPGMEPTRWTMNOKBHANYWBBRHFTEZSKIFYSMAOPXXRDOSSMYTAVXLTYHAPEHLBRBKONKSIPRNPPMEJYSOMYYATPVWRYXJUAMRNMEGYSHEMLCHWKBSTXYOTCSJRJNAMJWSHIRSJREAETDEFDHKOLHYSWKSBPYLTAABNOPTVOPCSCGJDPYEKKHOTFSSJUDIBMPEPSBXMYGVKRTGSPCEKMINIGOIHGRQVZWRCOOUANCMHQFPVTPHSEYSRLIYEKGWILRUJMRKXHBUVDAKBANXDHAUVOGHVNJIRCYTHUOEAFBMHLAGYVZCIAQAOLITIGTKKQEJOKTWLSOZJJIBQXHRXDKVPUZFOVWUOAAUFUCAASWTAPFJZIMCLHSQDIGLUHJJCTZOATZIFMLOYZYWUXEGTDRMIZXEWKZROZUMOJLMAGEHBJNFIBNLRFPAJCZCXGAJKWVGUJAXKCTJVRWHMURRGYKMCSOPNSTPABTWJAFEZNZTBWZBZQIEYYCKYYIQINVIAYIUUKHJDGCCAVOWGYUJKOIBMHPAJGEITPSRYIEUHWOXFZNZNUKKINYAUKOMRFUQSHEBOHMNWHNRARIIEFWHODYE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EICCQLJRDTYDRMEWHKOPXFIVODFNOYTANWFLNZQWMSGAAMPDLQWLDDEUYNCNZNYNWWSHXRBTHGXYWGKGKTSBMEZKWZGSIYUDXZMTDTKDKLRMNBDWOSEUNDXMMTTKZOJETTMEFMIENZCVVSXBPAHXVWEAEFRBTZEPYXQUAOUNZLHNYGARYCUDJHTBTACKWDMDVFGPXJIZEJYOZFGSKURGLAGKLFXSXJEFOUCCEVUNHNSETOIJNZXORRGREPIXUCRGHEKARXOWECBSCVCXNPSKPQEJVTPAJTNYNTMHSKTNIBHAIJYIMYUIAGVDFXSOBBCSNNRGOHMGIVKSWMYAPOIMNCKFCWEGMXGSOZYMHPYGJDEMLPAAQMNTCPIGQPBZJOBNHTLXIUSGJRHJOHTQRPYJGHZWQRNCFULLUGXLZMAVKENCNHFMVBR'"
+ ]
+ },
+ "execution_count": 42,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_keyword_break(sanitise(rlcb), fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(rlcb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['JBNSAAOGHLHSADGYUGWSTEYFGAIRVAPTFMYARHVATAVQNTN',\n",
+ " 'ODAFUAODCQLNAUQAZSEEFYDXPCNBFVQZIENZGFPVNUCTUTG',\n",
+ " 'CGHEGLXPCGMWAXVETIOMASOTYBFTLKELWWATHGLVNDEGAHP',\n",
+ " 'LOLQTGGLBLEDCFYHWFCUGYOJIDVRHHZMGDENOGQTKGBVYPL',\n",
+ " 'KYAVFOQEOABYBGPLVQLGKICKUUSESUKFYSZFYEOHBEQFJNW',\n",
+ " 'VXCLQDQBNUGPHVNHCGUTONLSQDOKROGLZSGYUVMWRGWHWFW',\n",
+ " 'VUFJRCIFTZPGUVFPEYRUWKUGJRNULEETG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CUGOULOCKJHCSUYYUIKAWWF',\n",
+ " 'FTACCSFEKFCCAUZZVYFAFZUPOGZPTQNNSWHQTAMWAHZPVFA',\n",
+ " 'LYLOFPBBGTDDYPHQGFTIONHSESQBNQDUEFRCFYEEUROJXYP',\n",
+ " 'YTJZXOFQAWRNOZRSPUHDSMTPFYIKMZNBMCJXLVBBOJXTKBA']"
+ ]
+ },
+ "execution_count": 46,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "cb.split()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'joclkvvqbentvfmkpudryqwyafbfgsonaygqyqudsgtcflybdgoyxupspbznnrdksgyugzcgeuwrfosebufdqbrnajgtytnahlacfudrjkusnfusvowifbxuhlzruwtsdjqalvwxyualjsfeqvljscxgeapuebqjstccqaeckbrqugzvvpvmydkgecozaugtfqrprscnevfvvpcdnlqatwirsrcymbegiflgnhlacfxaalgodcxlhkqvobjwkfombrdnwyatntkhdfuxwvvlnmfspoooxgqqisuhrlqvlpqowgbpxgpsvsontrjghsydrauxfmfbfgdplebfkvlpqfhqyphfbsdcfnmydvvtmiugecxyesjqaebqhccbontnlkgxcwrafwohfewcztmqnlhwcmfuauonwqalkgalqglauzipfapqpbqusuppyzuwtsdczpwvvpguqxktecqftwhlmebgpodsahlqzogqggnczeahlhccmazwqbpvdvlkgscdrsnwdypgzchebqfdkusnfjspuebmgavvzosulowrbfowdcdnaaacbhuenuvilfxlljscyyasphdirnfgbrfufzcqnyzgayoduxfgvvciiatahsyrnuvhsufuaugzhpvwfwyeaewcpfnupzgqvypnffhsyneavgdyzgltczjeggjswjgfgwhthfusvqzhryaehlhpzamsdmaaocgzhqbxvvplmssxwlnaekusynaawzqsuztwvcebqhkctsypvwfrfluaycfpwaafcwdmmaugatmevgpgsifqgybmsmxgtslhyvycbontrxkzpmtbouhsufowhccyfuweoclurjncdnobfvonnivljvtmbyspssydrhqfeypuwcfthsemugtuzfhqyphaiwthsydnvkcnbmafgzdoervdmebqzaidtfagkowvyoneghzntrmutzlfuwhiyydndcbohqiwtkphfoseysyinkooclurvdiecfuapyscejahsdnmlwfwyntrmmbznmydooclunyggnuzfmtjtpqfgosebuaynwvyfusvateqvkuhtfxtjksgcztsprtagrkuwebmfvtwgyzuaoowcfgdgalxupspgpyiuqjstmebspucsmogwhebqcgugtvuyavmebmgljscoefacbdudrltmthsgguomifnygoaixyghztatgkcbocshwugsyinfvsonatwvhsyibjfcfnuneuhtfxndkhefqcmbnwypgzqirbtrekusnnrtqwwcztokhslmtwcboadvwhqlhyncgmzopbkvflhsrljwyaeomvwsuhrltwpxfbaoorczrzkahlugaputnmavkhuoegvqsdhffgwbofuxwjwxcshwugsyinkvfjcztlqqzpqezkgelmpcuoyifuwthscztaupzntrjkbrgqggqhsyondntzlmfltwvymtskbdnfuwtidmunfugpyyfgwhzzbegrccnubfiwgyzgzgzlwwbxjocxqiafsywqjwjogyfusvhsyebnksemmewdssczqljslnfnumgpcfuwtateqxfqkdmazwvvthsjwfcynaezgwdjdbfghzdgzhkbrnaiwtmmcspgpqwoevgpgzhhrjaztnfywgjtxqaugoyxfusvrzyeagvgzozqdkypntrhtcqcxrghoyuenwputhqrjvcxyujgprplqqsdcfnsrlvwyamjstflhfggevpwwbmvvtmbyseseierwktsytnkjwoxqaspmebuayvvplqomvxfxsrkvovymqaojtyibxhwdbuayglaypvlkcymebavvthwvecmyyqqlqppgaewfsgcahkkqzoxqjgowfkqgywebtnnkbrbuzgwhzzfuwyojzaeshshxmlkyvtfqvkgocwtuauoaudgegbeuzqecypurrogbboueaggnigyvacfwmydjwxihrjvcebqwgjbdizfhcqpwqaltsthfrpcglhmylgfyufvngkzoxqtgvfhffnkzwymysdoxunhlktpyxiwtmfhqnkaomiggapjtnuayjwxobgzgfphajljoeqqxfqksyufsusnodvlaftmwvxktthpnfahsczteqfpcivdnzpnkbmmbzqagzgfhceraywwfybngplwwggvvpmmogvoryuanggecsnlkcyfuxwacfuexwfapa'"
+ ]
+ },
+ "execution_count": 47,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "tcb = sanitise(cat(cat(col) for col in zip(*cb.split())))\n",
+ "tcb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "columns \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'harryidontthinkwearegoingtoneedtolookfarforourmoleandicannotbelieveithastakenmethislongtoworkitoutyouarerightthatalotofstaffherespenttimeintheukeitherduringthewarorworkingwiththeballisticmissileexpertsintheiratomicweaponsprogrambutyoudonteasilypickupweirdspellinghabitslikethatasanadultyouhavetohavebeeneducatedtherethereisjustonepersonihavespokentoaboutallthiswhocomesfromtheukandthatismikeididntrealiseatfirsthisaccentisprettygoodsincehehasbeenheresincethemidfiftiesbutassoonasyoutoldmetolookoutforsomeonebritishirealisedthattheslighttwangthatithoughtmightbebostonianwasactuallytheremnantsofanenglishaccentiwasalsothrownbythefactthathissondiedinkoreabuticheckedandthebritssenttroopstohelpusoutinthatconflictandmikessonwasoneoftherafaviatorssentonexchangetotheusafhediedduringareconnaissancemissionshotdownbyakoreanmigandthefileshowsthatbeforethecarrierlostcontactwithhisplanehereportedhearingrussianspokenovertheradiochannelsusedbythemigpilotsmikecametotheusforthefuneralandneverwentbackhewasmarriedbutithinkhiswifestayedintheuknotallmarriagescansurvivesomethinglikethatmikeisstillgrievingandiguessithasdrivenhimalittlemadicanseewhyheissoangryaboutthepossibilitythattherussiansaretryingtosabotageapolloflightsandiguesshewantedtogetthewordoutiamstillalittlepuzzledthoughhemightbeboilingwithrageandgriefcanmakeyoudostrangethingsbutihavetriedtoimaginehimwritingitanditjustdoesntsoundlikehimiguesshewastryingtocoverhistracksanotherthingisbotheringmetoothecallforastrikeagainsttherussiansseemsoutofproportiongiventhelackofhardevidencewehavethatthesovietsarebehindtheattackseithermikeknowssomethingwedontorheispronetojumpingtoverybigconclusionsonverylittleevidenceandthatdoesnotsoundliketheprofileofanasaengineertomeiwonderedaboutgettingawarranttocheckouthisplacetoseeifhehashiddenanythingtherebutjudgestakeadimviewoffishingexpeditionssoithinkimayneedtobemoredeviousicouldreallydowithhavinghimoutofthewayforafewdayswhileisearchhisapartmentandmakeafewenquiriescouldyoucallhimovertothejohnsonspacecentreintexasanalternativewouldbehuntsvillealabamabutifeelveryuneasyaboutinvitinghimuptherenowthatweknowheisasecurityriskififindanythingmoreiwillletyouknowotherwiseiwillmovebacktothesabotageinvestigationlikeyouaskedmeg'"
+ ]
+ },
+ "execution_count": 48,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_keyword_break(tcb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(tcb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "columns \n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "'harryidontthinkwearegoingtoneedtolookfarforourmoleandicannotbelieveithastakenmethislongtoworkitoutyouarerightthatalotofstaffherespenttimeintheukeitherduringthewarorworkingwiththeballisticmissileexpertsintheiratomicweaponsprogrambutyoudonteasilypickupweirdspellinghabitslikethatasanadultyouhavetohavebeeneducatedtherethereisjustonepersonihavespokentoaboutallthiswhocomesfromtheukandthatismikeididntrealiseatfirsthisaccentisprettygoodsincehehasbeenheresincethemidfiftiesbutassoonasyoutoldmetolookoutforsomeonebritishirealisedthattheslighttwangthatithoughtmightbebostonianwasactuallytheremnantsofanenglishaccentiwasalsothrownbythefactthathissondiedinkoreabuticheckedandthebritssenttroopstohelpusoutinthatconflictandmikessonwasoneoftherafaviatorssentonexchangetotheusafhediedduringareconnaissancemissionshotdownbyakoreanmigandthefileshowsthatbeforethecarrierlostcontactwithhisplanehereportedhearingrussianspokenovertheradiochannelsusedbythemigpilotsmikecametotheusforthefuneralandneverwentbackhewasmarriedbutithinkhiswifestayedintheuknotallmarriagescansurvivesomethinglikethatmikeisstillgrievingandiguessithasdrivenhimalittlemadicanseewhyheissoangryaboutthepossibilitythattherussiansaretryingtosabotageapolloflightsandiguesshewantedtogetthewordoutiamstillalittlepuzzledthoughhemightbeboilingwithrageandgriefcanmakeyoudostrangethingsbutihavetriedtoimaginehimwritingitanditjustdoesntsoundlikehimiguesshewastryingtocoverhistracksanotherthingisbotheringmetoothecallforastrikeagainsttherussiansseemsoutofproportiongiventhelackofhardevidencewehavethatthesovietsarebehindtheattackseithermikeknowssomethingwedontorheispronetojumpingtoverybigconclusionsonverylittleevidenceandthatdoesnotsoundliketheprofileofanasaengineertomeiwonderedaboutgettingawarranttocheckouthisplacetoseeifhehashiddenanythingtherebutjudgestakeadimviewoffishingexpeditionssoithinkimayneedtobemoredeviousicouldreallydowithhavinghimoutofthewayforafewdayswhileisearchhisapartmentandmakeafewenquiriescouldyoucallhimovertothejohnsonspacecentreintexasanalternativewouldbehuntsvillealabamabutifeelveryuneasyaboutinvitinghimuptherenowthatweknowheisasecurityriskififindanythingmoreiwillletyouknowotherwiseiwillmovebacktothesabotageinvestigationlikeyouaskedmeg'"
+ ]
+ },
+ "execution_count": 49,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "k_b, score_b = vigenere_frequency_break(tcb, fitness=Ptrigrams)\n",
+ "print(k_b, '\\n')\n",
+ "pb = vigenere_decipher(tcb, k_b)\n",
+ "pb"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "harry i dont think we are going to need to look far for our mole and i can not believe it has taken\n",
+ "me this long to work it out you are right that alot of staff here spent time in the uk either during\n",
+ "the war or working with the ballistic missile experts in their atomic weapons program but you dont\n",
+ "easily pickup weird spelling habits like that as an adult you have to have been educated there there\n",
+ "is just one person i have spoken to about all this who comes from the uk and that is mike i didnt\n",
+ "realise at first his accent is pretty good since he has been here since the mid fifties but as soon\n",
+ "as you told me to lookout for someone british i realised that the slight twang that i thought might\n",
+ "be bostonian was actually the remnants of an english accent i was also thrown by the fact that his\n",
+ "son died in korea but i checked and the brits sent troops to help us out in that conflict and mikes\n",
+ "son was one of the raf aviators sent on exchange to the usaf he died during a reconnaissance mission\n",
+ "shot down by a korean mig and the file shows that before the carrier lost contact with his plane he\n",
+ "reported hearing russian spoken over the radio channels used by the mig pilots mike came to the us\n",
+ "for the funeral and never went back he was married but i think his wife stayed in the uk not all\n",
+ "marriages can survive something like that mike is still grieving and i guess it has driven him a\n",
+ "little madi can see why he is so angry about the possibility that the russians are trying to\n",
+ "sabotage apollo flights and i guess he wanted to get the word out i am still a little puzzled though\n",
+ "he might be boiling with rage and grief can make you do strange things but i have tried to imagine\n",
+ "him writing it and it just doesnt sound like him i guess he was trying to cover his tracks another\n",
+ "thing is bothering me too the call for a strike against the russians seems out of proportion given\n",
+ "the lack of hard evidence we have that the soviets are behind the attacks either mike knows\n",
+ "something we dont or he is prone to jumping to very big conclusions on very little evidence and that\n",
+ "does not sound like the profile of a nasa engineer tomei wondered about getting a warrant to\n",
+ "checkout his place to see if he has hidden anything there but judges take a dim view of fishing\n",
+ "expeditions so i think i may need to be more devious i could really do with having him out of the\n",
+ "way for a few days while i search his apartment and make a few enquiries could you call him over to\n",
+ "the johnson space centre in texas an alternative would be huntsville alabama but i feel very uneasy\n",
+ "about inviting him up there now that we know he is a security risk if i find anything more i will\n",
+ "let you know otherwise i will move back to the sabotage investigation like you asked meg\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(lcat(tpack(segment(pb))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2749"
+ ]
+ },
+ "execution_count": 51,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_b_filename, 'w').write(lcat(tpack(segment(pb))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}