Updated notebooks for new library organisation
[cipher-tools.git] / 2015 / 2015-challenge6.ipynb
index e01a50cd8efe5644638cc305399f70a80c440507..33b5b7baa043aa3fe168f9829656dc0a58c8cf4d 100644 (file)
@@ -3,9 +3,7 @@
   {
    "cell_type": "code",
    "execution_count": 1,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
     "import os,sys,inspect\n",
     "import matplotlib.pyplot as plt\n",
     "%matplotlib inline\n",
     "\n",
-    "from cipherbreak import *\n",
+    "from cipher.keyword_cipher import *\n",
+    "from cipher.vigenere import *\n",
+    "from support.utilities import *\n",
+    "from support.text_prettify import *\n",
     "\n",
     "c6a = sanitise(open('6a.ciphertext').read())\n",
     "c6b = sanitise(open('6b.ciphertext').read())"
@@ -25,9 +26,7 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
@@ -48,9 +47,7 @@
   {
    "cell_type": "code",
    "execution_count": 3,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -67,9 +64,7 @@
   {
    "cell_type": "code",
    "execution_count": 4,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
@@ -89,9 +84,7 @@
   {
    "cell_type": "code",
    "execution_count": 5,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   {
    "cell_type": "code",
    "execution_count": 6,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   {
    "cell_type": "code",
    "execution_count": 7,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   {
    "cell_type": "code",
    "execution_count": 8,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   {
    "cell_type": "code",
    "execution_count": 9,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
   {
    "cell_type": "code",
    "execution_count": 10,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   {
    "cell_type": "code",
    "execution_count": 11,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
     "print(' '.join(segment(sanitise(vigenere_decipher(sanitise(c6b), key_b)))))"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "('railfencstuvwxyzbdghjkmopq', -5965.858211099189)"
+      ]
+     },
+     "execution_count": 14,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "simulated_annealing_break(c6a, fitness=Ptrigrams)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "'charlieitwasthetypoinratilinesthatgaveitawayitappearedbothinthetypedmessageswepickedupandinthetranscriptoftheradiomessageprettyunlikelycoincidencesoifigureyourjuniorcipherclerkwasinvolvedmightbeworthcheckingherbackgroundandbankaccountsthatisallimeantwhenisaidthesourcewasclosetohomebutthinkingaboutitiamnotsureitmakessensetothinkshewasthesourcethemessagesstillkeepcomingandiamguessingthatshehasgonesotheremustbesomeothersourceforourintelligencesomethingisbotheringmeaboutthetoneofthemessageswhydoesourantagonistkeeptauntingusaboutouralliesitisnotlikethethingswearebeingaskedtobidforarethingswearelikelytohidefromoneanotherafterallanywayifollowedoneofourfrenchcolleaguestofriedrichstrasseandwatchedhertrytopickupthekeyfromlockerseemstohavebeenaconicouldntclearlyseewhatwasgoingonbutshedidntseemtobeabletoopenlockerandleftobviouslyupsetaftershehadgoneitookalookatlockerithasafalsebacksoiamguessingthemoneywastakenbutnothingprovidedinexchangecouldyoudigaroundwithyourcontactsinthebritishandrussianembassiesandseeiftheyaregettingthesamesortofcommunicationsmaybeyoucouldwarnthembythewaydiealchemistenprojectwasthecodenameforthenaziatombombeffortihadaruninwiththemduringthewarwhenweweretryingtokeeptheirhandsofftheheavywatersupplyrememberthebombinginvemorkthatwasusorratherournordicalliesanywayitisstilltopsecretsothefactourprotagonistknowsaboutitissignificantisuspectthekeytothiswholemysteryliesintheiridentityifweknewwhotheywereworkingforwemightbeabletofigureoutwhattheyareuptoonelastthingactingonahunchitookalookatsomeofthefrenchdeaddropsafterthefriedrichstrasseincidentandfoundtheattachedcommunicationihaventhadtimetocrackitbutithinkitmaybeavigenereagainbutihaventhadachancetotrybabbagestrickonityetgiveittoyourblackchamberandseewhattheycanmakeofitallthebestharry'"
+      ]
+     },
+     "execution_count": 15,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "keyword_decipher(c6a, 'railfencstuvwxyzbdghjkmopq')"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "collapsed": true
-   },
+   "metadata": {},
    "outputs": [],
    "source": []
   }
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.4.3"
+   "version": "3.6.3"
   }
  },
  "nbformat": 4,
- "nbformat_minor": 0
+ "nbformat_minor": 1
 }