Updated notebooks for new library organisation
[cipher-tools.git] / 2016 / 2016-challenge1.ipynb
index 5310e98f59eaf910baca9b72edd6c41cb07cf1e2..5bb058176f16fa3d9094e43e47ce132b56f24de5 100644 (file)
@@ -2,10 +2,8 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
-   "metadata": {
-    "collapsed": true
-   },
+   "execution_count": 7,
+   "metadata": {},
    "outputs": [],
    "source": [
     "import os,sys,inspect\n",
@@ -16,7 +14,9 @@
     "import matplotlib.pyplot as plt\n",
     "%matplotlib inline\n",
     "\n",
-    "from cipherbreak import *\n",
+    "from cipher.caesar import *\n",
+    "from support.utilities import *\n",
+    "from support.text_prettify import *\n",
     "\n",
     "c1a = open('1a.ciphertext').read()\n",
     "c1b = open('1b.ciphertext').read()"
@@ -25,9 +25,7 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
@@ -48,9 +46,7 @@
   {
    "cell_type": "code",
    "execution_count": 3,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -75,9 +71,7 @@
   {
    "cell_type": "code",
    "execution_count": 4,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
   },
   {
    "cell_type": "code",
-   "execution_count": 20,
-   "metadata": {
-    "collapsed": false
-   },
+   "execution_count": 5,
+   "metadata": {},
    "outputs": [
     {
      "data": {
        "\"E TOY'P ZEPGLST OY PZED LSET YZTE. AZYLP GLSEYZOTZD HZ YPCP, SPYZW LELSEZOYLN TH ZSPPDE. YLN TE TIT QZEO, PEC L EDP'G LSES RTX, PHC PSEP RZ EEF MJE WT FRSE ZMPC LPHOY. L RYT'Y PAALS DLH ELSH ZEOY TW, MS EZMP CPHP HPXYL SE PCZX XTS PXLWMEYLN TPY ZW LSE THWL POZERT, MZZ EDTDTSEO YL XTSOY TQEY LNTOYLP YZ RDL SP. S EFM'O PPC RLP H RYT SE JCPG PCPEQ, LOTL, DPH. RY T SEJ'C PGPC PE QLELSE. PV TWE QP WPS. P GPTW PM EYL NT.\\n\""
       ]
      },
-     "execution_count": 20,
+     "execution_count": 5,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 25,
-   "metadata": {
-    "collapsed": false
-   },
+   "execution_count": 8,
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
     "print(wcat(segment(cat(reversed(sanitise(caesar_decipher(c1b, key_b)))))))"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[1, 5, 7, 15, 18, 23, 28, 33, 34, 40]"
+      ]
+     },
+     "execution_count": 9,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "nonletters = [i for i in range(len(c1b)) if c1b[i] not in string.ascii_letters]\n",
+    "nonletters[:10]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "'icantbelieveheleftlikethataftereverythingwesaidaftereverythingweagreedbuthehasgoneandicantfindhimandthisistoobigtodealwithaloneicantblamehimmorethanmewewerebothblindtowhatwashappeningandwearebothguiltybuttogetherwemighthavestartedtofixiticantseehowicandothataloneherenowsoidonthaveanoptionithastoendihavetoendit'"
+      ]
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "p1bs = cat(reversed(sanitise(caesar_decipher(c1b, key_b))))\n",
+    "p1bs"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\"i can't believe he left like that. after everything we said, after everything we agreed. but he has gone, and i can't find him, and this is too big to deal with alone. i can't blame him more than me, we were both blind to what was happening and we are both guilty, but together we might have started to fix it. i can't see how i can do that alone, here, now. so i don't have an option. it has to end. i have to end it.\\n\""
+      ]
+     },
+     "execution_count": 11,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "p1b = p1bs\n",
+    "for i in nonletters:\n",
+    "    p1b = p1b[:i] + c1b[i] + p1b[i:]\n",
+    "p1b"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.5.2"
+   "version": "3.6.3"
   }
  },
  "nbformat": 4,