Done challenge 9
[cipher-tools.git] / 2019 / 2019-challenge9.ipynb
diff --git a/2019/2019-challenge9.ipynb b/2019/2019-challenge9.ipynb
new file mode 100644 (file)
index 0000000..9f21621
--- /dev/null
@@ -0,0 +1,267 @@
+{
+ "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": 2,
+   "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 = 9\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": 4,
+   "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",
+    "rsca = cat(reversed(sca))\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": 5,
+   "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+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFFRJREFUeJzt3X+QZWV95/H3RzBRkQSBlkWlbckSd9WsY2hZjZoi/kihwRh3DZGoSDRpSaCMu2sS0GSlSKwiUWOlKglmiFPoBgkmBCUrRik0gj9YZYYRhh8qyBCgyIBgRCRRmPnuH/eMuTP2TJ++P2bm6X6/qm71Oc89zznfvn26P/2c+/TpVBWSJLXmEXu7AEmSRmGASZKaZIBJkppkgEmSmmSASZKaZIBJkppkgEmSmmSASZKaZIBJkppkgEmSmrT/3i4A4NBDD625ubm9XYYkaR+wfv36b1TVzFLb7RMBNjc3x9VXX723y5Ak7QOS3NZnOy8hSpKaZIBJkppkgEmSmmSASZKaZIBJkppkgEmSmmSASZKaZIBJkppkgEmSmmSASZKatE/cSkqStG+aO/1jvbfdfPbPTbGSH+QITJLUJANMktQkA0yS1CQDTJLUJANMktQkA0yS1CSn0UvSKrEvT4kfhSMwSVKTlgywJOuS3J1k01DbhUk2do/NSTZ27XNJ/nXoufdNs3hJ0urV5xLiecCfAh/c3lBVv7R9Ocl7gG8NbX9LVa2ZVIGSJC1myQCrqiuSzC32XJIAJwAvnGxZkiTt3riTOF4AbKmqrw21PSXJNcD9wO9W1ZVjHkOSNGSlTc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7B/lf1V1UNJbmVwfnweuBb4GeA/Ajf22cUS67syzjnynb4bJjkWeDHw3Kp6MMk/0v9cPoTByP6RXZ/ex91TquqrSX4SeBnwB0kur6qzlugW4ANVdcb0K5yOlT4C+x7wSuCkJL88xeNcAfxCkkcnORB4+ZT7AcwmeW63/MvAZ3v0uRg4jsEljk/0PM4WBiOAQ5L8MHD8MmocxaeAX0xyCECSg3v0uZLB6/iYJAcw+Jr3GTWMJMnRDC6lvrYbUU3bhQxux/YqBmE2LVcy+Lyu6JZPYTBS7xNGo5yPe9KPMhi9PpjkPzG4ZNrXXwC/B5wP/GGP7T8HvLx73+yxTP97hiRPAB6sqr8C3gX8ZI9ulwOvSvL4bh8HJ3lyj37fZnBpdK9b6SMwquo7SY4HLkvyQFUt5zJdr98iq2pDkguBLwN3M7gX5NT6db4CnJpkHYPR5Tk9jve9bsLBv1TV1p41PpTkLAbvidwJ3LSMGpetqq5P8k7gM0m2Mnj/8uQl+mxIcl5XI8BfdpfepuU04GDg00lgcFPTX53WwbrX5EDgzqq6a1rHYRBabwe+0H3f/Bv9fxFY9vm4h/0DcEqSGxnU2uvSY5KTgIeq6kPdBIfPJ3lhVX1qV32q6ktJLmEwit3C4PJen0t64/gJ4F1JtgEPAb++VIequiHJ7wKfzGAW50PAqcBtS/S7t5uAtAn4eFX91vjlj8Y7cexCNwLYUFV9fiOZ1DHPZPAG7runtP9HABuAX6yqr03jGFp9kswB/7eqlpydt1okeWxVPdDNxrwCWKiqDXu7rpVmpV9CHEk3HP8Cg5lHK0KSpzGY5Xi54SVN3dpuYsQG4CLDazocgUmSmuQITJLUJANMktQkA0yS1CQDTJLUJANMktQkA0yS1KT/D+bQ9RFtTcUXAAAAAElFTkSuQmCC\n",
+      "text/plain": [
+       "<Figure size 432x288 with 1 Axes>"
+      ]
+     },
+     "metadata": {
+      "needs_background": "light"
+     },
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "fc = collections.Counter(sca)\n",
+    "plot_frequency_histogram(fc, sort_key=fc.get)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "etsllamsenopaeltnaigenop \n",
+      "\n"
+     ]
+    },
+    {
+     "data": {
+      "text/plain": [
+       "'rehpicsihtkaerbewtahtlaicurcsitiskeewweftxenehtniffotfilrofdeludehcsnotyalsdnadnarbdroffatshtiwniagarawfoknirbehtnosevlesruodnifthgimewftsaehtfowercehtotsneppahgnihtynafiysaemorfrafllitssiecaepehttubogasraeyeerhtaissurnorawgniralcedotniaciremaekovorpotdeliafehshtiwderepmatevahyamefiwsekimtahtmetsyslacitircrehtoemossierehtfiwonktnodewtituohtiwkcarctnacielifenosierehttubrewoplacirtcelednatroppusefillortnocecnadiughtiwsmelborpdexifdnadnuofdnamehtfoenotublladekcarcevahewrafosscissalckeergrehtodnasurodolloparemohmorfemactahtsyekgnisudelbmarcsllaerewselifehtiiixollopahtiwdetaicossaselifderepmatehtfoemdednimertahtsdrocerecivresdetidefoliartadnuofiytirucesriehttiduaotnikcabemdellacyehtossthgilfranulehthtiwdahewsmelborpehttuobamehtdednimerenoemosasantamaetzuyosollopaehtmorfllacakootinodnolmorftroperehtdevieceriretfanooskuehttfelehstahtretfanoosdnadekoversawecnaraelcytirucesrehsrengiapmacecaephtiwgniteemdetratsdnaaeroknideidnosrehretfatfelehsotsefinamehtniseirrowehthtiwyltcefrepstifhcihwerwaytirohtuasnopaewcimotakuehthtiwgnikrowedartrehdenraelehsyltnacifingissthgilfollopareilraeehtnowasewegatobasfotrosehttuogniyrracfoelbapacetiuqsawohwreenignenasawehsemdlotyehtdnakuehtniecivresytirucesehtotekopsitnewehserehwswonkenoondnarehneestonevahyehtyasedisetatssevitalerrehtubogasraeynevelesawtahtylimaflanigirorehraenebotsetatsehtotkcabgnivomsawehsmehtdlotehsyrevocerwolsaekildemeestahwretfaswalnirehhtiwevilottnewehssuehtotkcabdevomekimnehwdnadeidnosrehretfanwodkaerbadahehsyassdneirfrehemmargorpfognillepshsilgneehtsesuotsefinamehtdnahsilgneoslasiefiwsekimefiwsekimtuobaseiriuqneedamdnalopretnihtiwhcuotnitogiosedirprehrofegnevernisdogehtybdellikerewsnosesohwneeuqehtsasuomafsawehsdailiehtniebointuobaetorwremohreraelcelttilategotnagebsgnihteboinrehpicotsefinamehtrofdrowyekehthtiwrehtegottahtgnittupdeirramsawekimtahtemdednimerevahdluowtipotehttanosruoesarhpehtdecitonevahdluohsiseulcrofylluferaceromniagatidaerimihybnettirwsawotsefinamehtknihttnodiosenofoesopsidotemitekimevigtndidewdnaedihotyklubdnagibootsiretirwepytarehtiesenihcamasanehtfoynahctamtnodotsefinamehtnoecafepytdnakniehtesacynanidnamihrofepytotyratercesadaheherehtkrowtaneveretirwepytrehtonanomihybnettirwgnihtynadniftndluoctubselifehthguorhtdekooliretirwepytsekimnodecudorptonsawotsefinamehtevisulcnocerastluserehtstsetehtnurotmehttogdnayelgnalotrevotitnesiekatsimehtdesilaerisanoossatikcehcotenoemosksaottogrofitahttnetnocstignisylanadnarehpicehtgnikcarchtiwpunekatossawisseugitnemucodehtnoscisneroftuodeirracrevenewtubtidessimewwohwonktnodikoolrehtonakootdnaotsefinamehttuogudierehttoginehwossretrauqdaehotkcabyawehtnotituobayrrowotdeunitnocitubweivretniehtfotuoeromgnihtynategtndidignihtemosgnidihsawehgnileefehttogidnacipotehtffoemreetsotdrahgniyrtyletinifedsawehtubtituobawenkewwenkehostruocnituodaerneebdahtiotsefinamehttuobamihdeksadnaredrahdesserpisserpehtotrettelehttnesehstimdaehhguohtstnediccaehtdellacehtahwhtiwodotgnihtondahehsmialcllitseherehtsawiyhwtuoerugifotgnolmihekattndidtidnatuobaklatottolaevahtndidewtubsrotisivynamstegehknihttnodiemeesotdesaelpdemeesehasantagnikrowllitssawehnehwkcabnoitomnignihtemostesevahtndluocehtahttnedifnocyletelpmoctonsawiiivxollopanomelborpnoitazirusserpknatehtretfasurofsesirprusrevotfelynaevahtndideherusekamdnaekimhtiwnikcehcotaedidoogaebdluowtithguohtipugnimocnoissimzuyosollopaehtfohcnualehthtiwyrrah'"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "k_a, score_b = vigenere_frequency_break(sca, fitness=Ptrigrams, max_key_length=26)\n",
+    "print(k_a, '\\n')\n",
+    "pa = vigenere_decipher(sca, k_a)\n",
+    "pa"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "onesmallsteponegiantleap \n",
+      "\n"
+     ]
+    },
+    {
+     "data": {
+      "text/plain": [
+       "'harrywiththelaunchoftheapollosoyuzmissioncomingupithoughtitwouldbeagoodideatocheckinwithmikeandmakesurehedidnthaveanyleftoversurprisesforusafterthetankpressurizationproblemonapolloxviiiwasnotcompletelyconfidentthathecouldnthavesetsomethinginmotionbackwhenhewasstillworkingatnasaheseemedpleasedtoseemeidontthinkhegetsmanyvisitorsbutwedidnthavealottotalkaboutanditdidnttakehimlongtofigureoutwhyiwastherehestillclaimshehadnothingtodowithwhathecalledtheaccidentsthoughheadmitshesentthelettertothepressipressedharderandaskedhimaboutthemanifestoithadbeenreadoutincourtsoheknewweknewaboutitbuthewasdefinitelytryinghardtosteermeoffthetopicandigotthefeelinghewashidingsomethingididntgetanythingmoreoutoftheinterviewbuticontinuedtoworryaboutitonthewaybacktoheadquarterssowhenigotthereidugoutthemanifestoandtookanotherlookidontknowhowwemisseditbutwenevercarriedoutforensicsonthedocumentiguessiwassotakenupwithcrackingthecipherandanalysingitscontentthatiforgottoasksomeonetocheckitassoonasirealisedthemistakeisentitovertolangleyandgotthemtoruntheteststheresultsareconclusivethemanifestowasnotproducedonmikestypewriterilookedthroughthefilesbutcouldntfindanythingwrittenbyhimonanothertypewriterevenatworktherehehadasecretarytotypeforhimandinanycasetheinkandtypefaceonthemanifestodontmatchanyofthenasamachineseitheratypewriteristoobigandbulkytohideandwedidntgivemiketimetodisposeofonesoidontthinkthemanifestowaswrittenbyhimireaditagainmorecarefullyforcluesishouldhavenoticedthephraseoursonatthetopitwouldhaveremindedmethatmikewasmarriedputtingthattogetherwiththekeywordforthemanifestocipherniobethingsbegantogetalittleclearerhomerwroteaboutniobeintheiliadshewasfamousasthequeenwhosesonswerekilledbythegodsinrevengeforherpridesoigotintouchwithinterpolandmadeenquiriesaboutmikeswifemikeswifeisalsoenglishandthemanifestousestheenglishspellingofprogrammeherfriendssayshehadabreakdownafterhersondiedandwhenmikemovedbacktotheusshewenttolivewithherinlawsafterwhatseemedlikeaslowrecoveryshetoldthemshewasmovingbacktothestatestobenearheroriginalfamilythatwaselevenyearsagobutherrelativesstatesidesaytheyhavenotseenherandnooneknowswhereshewentispoketothesecurityserviceintheukandtheytoldmeshewasanengineerwhowasquitecapableofcarryingoutthesortofsabotagewesawontheearlierapolloflightssignificantlyshelearnedhertradeworkingwiththeukatomicweaponsauthorityawrewhichfitsperfectlywiththeworriesinthemanifestosheleftafterhersondiedinkoreaandstartedmeetingwithpeacecampaignershersecurityclearancewasrevokedandsoonafterthatshelefttheuksoonafterireceivedthereportfromlondonitookacallfromtheapollosoyuzteamatnasasomeoneremindedthemabouttheproblemswehadwiththelunarflightssotheycalledmebackintoaudittheirsecurityifoundatrailofeditedservicerecordsthatremindedmeofthetamperedfilesassociatedwithapolloxiiithefileswereallscrambledusingkeysthatcamefromhomerapollodorusandothergreekclassicssofarwehavecrackedallbutoneofthemandfoundandfixedproblemswithguidancecontrollifesupportandelectricalpowerbutthereisonefileicantcrackwithoutitwedontknowifthereissomeothercriticalsystemthatmikeswifemayhavetamperedwithshefailedtoprovokeamericaintodeclaringwaronrussiathreeyearsagobutthepeaceisstillfarfromeasyifanythinghappenstothecrewoftheastfwemightfindourselvesonthebrinkofwaragainwithstaffordbrandandslaytonscheduledforliftoffinthenextfewweeksitiscrucialthatwebreakthiscipher'"
+      ]
+     },
+     "execution_count": 7,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "k_a, score_b = vigenere_frequency_break(rsca, fitness=Ptrigrams, max_key_length=26)\n",
+    "print(k_a, '\\n')\n",
+    "pa = vigenere_decipher(rsca, k_a)\n",
+    "pa"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "harry with the launch of the apollo soyuz mission coming up i thought it would be a good idea to\n",
+      "check in with mike and make sure he didnt have any leftover surprises for us after the tank\n",
+      "pressurization problem on apollo xviii was not completely confident that he couldnt have set\n",
+      "something in motion back when he was still working at nasa he seemed pleased to see me i dont think\n",
+      "he gets many visitors but we didnt have alot to talkabout and it didnt take him long to figure out\n",
+      "why i was there he still claims he had nothing to do with what he called the accidents though he\n",
+      "admit she sent the letter to the press i pressed harder and asked him about the manifesto it had\n",
+      "been readout in court so he knew we knew about it but he was definitely trying hard to steer me off\n",
+      "the topic and i got the feeling he was hiding something i didnt get anything more out of the\n",
+      "interview but i continued to worry about it on the wayback to headquarters so when i got there i\n",
+      "dugout the manifesto and took another look i dont know how we missed it but we never carried out\n",
+      "forensics on the document i guess i was so taken up with cracking the cipher and analysing its\n",
+      "content that i forgot to ask someone to check it as soon as i realised the mistake i sent it over to\n",
+      "langley and got them to run the tests the results are conclusive the manifesto was not produced on\n",
+      "mikes typewriter i looked through the files but couldnt find anything written by him on another\n",
+      "typewriter even at work there he had a secretary to type for him and in any case the ink and\n",
+      "typeface on the manifesto dont match any of the nasa machines either a typewriter is too big and\n",
+      "bulky to hide and we didnt give mike time to dispose of one so i dont think the manifesto was\n",
+      "written by him i read it again more carefully for clues i should have noticed the phrase our son at\n",
+      "the top it would have reminded me that mike was married putting that together with the keyword for\n",
+      "the manifesto cipher niobe things began to get a little clearer homer wrote about niobe in the iliad\n",
+      "she was famous as the queen whose sons were killed by the gods in revenge for her pride so i got in\n",
+      "touch with interpol and made enquiries about mikes wife mikes wife is also english and the manifesto\n",
+      "uses the english spelling of programme her friends says he had a breakdown after her son died and\n",
+      "when mike moved back to the us she went to live with her in laws after what seemed like as low\n",
+      "recovery she told them she was moving back to the states to be near her original family that was\n",
+      "eleven years ago but her relatives stateside say they have not seen her and no one knows where she\n",
+      "went i spoke to the security service in the uk and they told me she was an engineer who was quite\n",
+      "capable of carrying out the sort of sabotage we saw on the earlier apollo flights significantly she\n",
+      "learned her trade working with the uk atomic weapons authority aw re which fits perfectly with the\n",
+      "worries in the manifesto she left after her son died in korea and started meeting with peace\n",
+      "campaigners her security clearance was revoked and soon after that she left the uk soon after i\n",
+      "received the report from london i took a call from the apollo soyuz team at nasa someone reminded\n",
+      "them about the problems we had with the lunar flights so they called me back into audit their\n",
+      "security i found a trail of edited service records that reminded me of the tampered files associated\n",
+      "with apollo xiii the files were all scrambled using keys that came from homer apollodorus and other\n",
+      "greek classics so far we have cracked all but one of them and found and fixed problems with guidance\n",
+      "control life support and electrical power but there is one file icant crack without it we dont know\n",
+      "if there is some other critical system that mikes wife may have tampered with she failed to provoke\n",
+      "america into declaring war on russia three years ago but the peace is still far from easy if\n",
+      "anything happens to the crew of the as tf we might find ourselves on the brink of war again with\n",
+      "stafford brand and slayton scheduled for liftoff in the next few weeks it is crucial that we break\n",
+      "this cipher\n"
+     ]
+    }
+   ],
+   "source": [
+    "print(lcat(tpack(segment(pa))))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "4107"
+      ]
+     },
+     "execution_count": 9,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "open(plaintext_a_filename, 'w').write(lcat(tpack(segment(pa))))"
+   ]
+  },
+  {
+   "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.9"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}