Done challenge 8
[cipher-tools.git] / 2019 / 2019-challenge8.ipynb
diff --git a/2019/2019-challenge8.ipynb b/2019/2019-challenge8.ipynb
new file mode 100644 (file)
index 0000000..3230e16
--- /dev/null
@@ -0,0 +1,238 @@
+{
+ "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 = 8\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+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFWNJREFUeJzt3X+wZGV95/H3JwyoYCLCXAky6GDEZNGsCw4sLnELQRNUzLC1xIVoAJfUrFmMJsYYiJvFskIVRmtdtzYxmQgLbliEEBU2apQdUPwFOAwgM4AyKyAzBcxFlAhU+PndP/qw1cwP+tzuvsw8c9+vqlvT5+nn6fPtvt396efpc8+kqpAkqTU/s70LkCRpHAaYJKlJBpgkqUkGmCSpSQaYJKlJBpgkqUkGmCSpSQaYJKlJBpgkqUkGmCSpSYu2dwEAixcvrqVLl27vMiRJO4DrrrvuvqqaGdVvhwiwpUuXsnr16u1dhiRpB5Dkzj79XEKUJDXJAJMkNckAkyQ1yQCTJDXJAJMkNckAkyQ1yQCTJDXJAJMkNckAkyQ1aWSAJTk3yaYkazdr/90ktyZZl+TPhtrPSLI+yfeS/Np8FC1JUp9TSZ0H/Hfg0081JHk9sBx4dVU9kuRFXftBwAnAK4EXA/8nySuq6olpFy5Jmn9LT/9C7753nP2WeaxkSyNnYFV1FXD/Zs2/A5xdVY90fTZ17cuBz1TVI1V1O7AeOGyK9UqSBIz/HdgrgNcluSbJ15Ic2rXvB9w11G9D1yZJ0lSNezb6RcBewOHAocDFSV42lxtIsgJYAf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Wa5/N7AXcGUSGJyI9rd77G+sx6Qbdx6D3xvAp7pl/FHjHu0OMPlJVT3RZ19JTgIeq6r/1R289K0kR1XVFX3Gt2ynPxNH9wl0TVX1/UQuPaMkS4G/r6q+R3o1qTva8cGq+tj2rmVYkudX1YPdkZ9XASuqas32rmsaug9ga4DfqKrbtnc9O7qdegmxW9b7NoOjcyTtHFZ2B+usAf5uJwqvgxgc5bjK8Opnp5+BSZJ2Tjv1DEyStPMywCRJTTLAJElNMsAkSU0ywCRJTTLAJElN+n8yzCjn0bwVXwAAAABJRU5ErkJggg==\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": [
+      "abcdefghijklmnopqrstuvwxyz \n",
+      "\n"
+     ]
+    },
+    {
+     "data": {
+      "text/plain": [
+       "'harryiputtogetherateamofwomenfromthecomputingdivisionhereatkennedyandwehavespentmostofthelasteighteenmonthscombingthroughmissionfilesandcomputerprintoutslookingformorecluestothesourceoftheoxygentankexplosiononboardapolloxiiiandithinkwehavefinallyworkedoutwhathappenedthetankcontainingthesourceoftheexplosionwasoriginallyinstalledinapolloxbutremovedformodificationduringthatprocessitgotdroppedsoitwasheldbackforfurthertestsandareplacementfittedforthatflightonceithadpassedinspectionthetankwasreturnedtoserviceandearmarkedforodysseyfurtherupgradeswerecarriedouttoallowittorunoffgroundpowerduringfitoutattwicethespaceshipvoltageandthehigherpowerwasusedtoboiloffexcessoxygenduringgroundtestsunfortunatelyitlookslikethethermostaticswitchesinthetankwereoverlookedduringthevoltageupgradeandourbestguessisthattheyfusedclosedduringtheboiloffallowingthetemperaturetorisetooverathousanddegreesyoumightthinkthetestengineerswouldhavenoticedthatbutsincethetankoperatingtemperaturewassupposedtobesomewherewellbelowzerothedialonlywentasfaraspluseightysonoonewouldhavenoticedoperatingthatfaroutofnormalrangeitisamiraclethetanklastedaslongasitdidandthataddstotheimpressionthatthiswasasimpleaccidentachainofeventsthatcouldnothavebeenforeseenbutthecomputerfilestelladifferentstorywefoundtwoversionsoftheupgradereportwhichwaswrittentodetailtheproceduresformodifyingtheelectricalsystemonthetankthefirstgivesacomprehensivelistofthecablingswitchgearandcontrolsystemsthatneededtobehardenedforthegroundbasedvoltageitlistseverycriticalcomponentexceptthethermostaticvalvesthisdocumentwasfiledintheservicerecordsoweknowitwastheofficialrecordbutthechiefsystemsengineerwhosigneditoffsaysthesignatureonitisabadcopyofhisownwefoundidenticalcopiesinseveralmissionfilesbothinthemanufacturersrecordsandatkennedywheresomeofthetestswerecarriedoutsoitisclearthatthiswastheofficialversionusedintheupgradethesecondversionappearedtobethesamedocumentbutitincludedthethermostaticvalvesonthelistofcomponentstobechangedandthetemperaturegaugelimitswerecircledseveraltimeswithanexclamationmarknexttotheeightydegreeceilingitlookslikeoursaboteurdeliberatelyarrangedforthetanktobemisconfiguredinanefforttocausetroubleforthemissionalthoughwecantbesuretheyrealisedhowdangerousthiswaswhenweputittogetherwithalltheotheraccidentsitisprettyclearthiswasanotherdeliberateattackontheprogramwefoundthesecondversionofthereportinaboxunderthefloorboardsinmikesplaceisupposeitispossiblethatmikehadstumbledacrossthedocumenthimselfandwasinvestigatingitaspartofhiscampaigntoprovethattherussianswerebehindthisstringofproblemsbutattheveryleastheisguiltyofamajormisjudgementandiftheastronautshaddiedhewouldhavebeentriedformanslaughterasitistogetherwiththeleakchargeshewillbegoingtoprisonforaverylongtimeofcoursetheevidenceisstilllargelycircumstantialwecandefinitelytiehimtotheleaktothenewspaperforensicsmatchedthetypewriterribbonandtypecharacteristicsonhistypewriterwiththeinkandimpressionsonthelettertotheeditorbutwestillcannotshowconclusivelythathedirectedorcarriedoutanyofthesabotageattemptsandwehavenotbeenabletofindanyoneelsewhohadbothmotiveandopportunitysoheisourbestsuspectiamnotsurewecanentirelyrelaxbutwithnosignificantincidentsonapolloxivtoxviandwithmikeincustodyifeelslightlylessworriedabouttheremainingapolloflightwearestilltryingtocrackthatotherenciphereddocumentwefoundinmikesplaceithasaverystrangealphabetwhichithinkmustbesignificantbuticantquiteseehowtobreakityetnowthatthenasacomputingexpertshavemoretimeiamhopingthatweshouldbeabletodecipheritandthatitwillshedsomemorelightonmikesthinkingmoreimportantlyitmighttelluswhatelseifanythinghehadplannedmeg'"
+      ]
+     },
+     "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": [
+      "harry i put together a team of women from the computing division here at kennedy and we have spent\n",
+      "most of the last eighteen months combing through mission files and computer printouts looking for\n",
+      "more clues to the source of the oxygen tank explosion onboard apollo xiii and i think we have\n",
+      "finally worked out what happened the tank containing the source of the explosion was originally\n",
+      "installed in apollo x but removed for modification during that process it got dropped so it was held\n",
+      "back for further tests and a replacement fitted for that flight once it had passed inspection the\n",
+      "tank was returned to service and earmarked for odyssey further upgrades were carried out to allow it\n",
+      "to runoff ground power during fit out at twice the spaceship voltage and the higher power was used\n",
+      "to boil off excess oxygen during ground tests unfortunately it looks like the thermostatic switches\n",
+      "in the tank were overlooked during the voltage upgrade and our best guess is that they fused closed\n",
+      "during the boil off allowing the temperature to rise to over a thousand degrees you might think the\n",
+      "test engineers would have noticed that but since the tank operating temperature was supposed to be\n",
+      "somewhere well below zero the dial only went as far as plus eighty sono one would have noticed\n",
+      "operating that far out of normal range it is a miracle the tank lasted as long as it did and that\n",
+      "adds to the impression that this was a simple accident a chain of events that could not have been\n",
+      "foreseen but the computer file stella different story we found two versions of the upgrade report\n",
+      "which was written to detail the procedures for modifying the electrical system on the tank the first\n",
+      "gives a comprehensive list of the cabling switchgear and control systems that needed to be hardened\n",
+      "for the ground based voltage it lists every critical component except the thermostatic valves this\n",
+      "document was filed in the service records owe know it was the official record but the chief systems\n",
+      "engineer who signed it off says the signature on it is a badcopy of his own we found identical\n",
+      "copies in several mission files both in the manufacturers records and at kennedy where some of the\n",
+      "tests were carried out so it is clear that this was the official version used in the upgrade the\n",
+      "second version appeared to be the same document but it included the thermostatic valves on the list\n",
+      "of components to be changed and the temperature gauge limits were circled several times with an\n",
+      "exclamation mark next to the eighty degree ceiling it looks like our saboteur deliberately arranged\n",
+      "for the tank to be misconfigured in an effort to cause trouble for the mission although we cant be\n",
+      "sure they realised how dangerous this was when we put it together with all the other accidents it is\n",
+      "pretty clear this was another deliberate attack on the program we found the second version of the\n",
+      "report in a box under the floorboards in mikes place i suppose it is possible that mike had stumbled\n",
+      "across the document himself and was investigating it as part of his campaign to prove that the\n",
+      "russians were behind this string of problems but at the very least he is guilty of a major\n",
+      "misjudgement and if the astronauts had died he would have been tried for manslaughter as it is\n",
+      "together with the leak charges he will be going to prison for a very longtime of course the evidence\n",
+      "is still largely circumstantial we can definitely tie him to the leak to the newspaper forensics\n",
+      "matched the typewriter ribbon and type characteristics on his typewriter with the ink and\n",
+      "impressions on the letter to the editor but we still can not show conclusively that he directed or\n",
+      "carried out any of the sabotage attempts and we have not be enable to find anyone else who had both\n",
+      "motive and opportunity so he is our best suspect i am not sure we can entirely relax but with no\n",
+      "significant incidents on apollo xiv to xvi and with mike in custody i feel slightly less worried\n",
+      "about the remaining apollo flight we are still trying to crack that other enciphered document we\n",
+      "found in mikes place it has a very strange alphabet which i think must be significant but icant\n",
+      "quite see how to break it yet now that the nasa computing experts have more time i am hoping that we\n",
+      "should be able to decipher it and that it will shed some more light on mikes thinking more\n",
+      "importantly it might tell us what elseif anything he had planned meg\n"
+     ]
+    }
+   ],
+   "source": [
+    "print(lcat(tpack(segment(pa))))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "4375"
+      ]
+     },
+     "execution_count": 8,
+     "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
+}