Fixed railfence ciphers, done challenges 2014 4 and 5
[cipher-tools.git] / railfence-experiment-1.ipynb
diff --git a/railfence-experiment-1.ipynb b/railfence-experiment-1.ipynb
new file mode 100644 (file)
index 0000000..cf432ee
--- /dev/null
@@ -0,0 +1,1085 @@
+{
+ "metadata": {
+  "name": "",
+  "signature": "sha256:c4879f550d49d776eff31ee9f3296756aab1dcd81e1e5aad61ade46d9b29600d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "from cipher import *"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 1
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_encipherl('hellothere', 3)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 25,
+       "text": [
+        "'horeltee lh '"
+       ]
+      }
+     ],
+     "prompt_number": 25
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "message = 'hellothere'\n",
+      "height = 2"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 169
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sections = chunks(message, (height - 1) * 2, fillvalue='!')\n",
+      "sections"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 170,
+       "text": [
+        "['he', 'll', 'ot', 'he', 're']"
+       ]
+      }
+     ],
+     "prompt_number": 170
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "rows = [s[0] for s in sections]\n",
+      "rows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 171,
+       "text": [
+        "['h', 'l', 'o', 'h', 'r']"
+       ]
+      }
+     ],
+     "prompt_number": 171
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "for r in range(1, height - 1):\n",
+      "        rows += [s[r] + s[-r] for s in sections]\n",
+      "rows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 172,
+       "text": [
+        "['h', 'l', 'o', 'h', 'r']"
+       ]
+      }
+     ],
+     "prompt_number": 172
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "rows += [s[height - 1] for s in sections]\n",
+      "rows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 173,
+       "text": [
+        "['h', 'l', 'o', 'h', 'r', 'e', 'l', 't', 'e', 'e']"
+       ]
+      }
+     ],
+     "prompt_number": 173
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = ''.join(rows)\n",
+      "ciphertext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 174,
+       "text": [
+        "'hlohreltee'"
+       ]
+      }
+     ],
+     "prompt_number": 174
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "def railfence_encipherl(message, height, fillvalue=' '):\n",
+      "    \"\"\"Railfence cipher\n",
+      "    \"\"\"\n",
+      "    sections = chunks(message, (height - 1) * 2, fillvalue=fillvalue)\n",
+      "    # Add the top row\n",
+      "    rows = [s[0] for s in sections]\n",
+      "    # process the middle rows of the grid\n",
+      "    for r in range(1, height - 1):\n",
+      "        rows += [s[r] + s[-r] for s in sections]\n",
+      "    # process the bottom row\n",
+      "    rows += [s[height - 1] for s in sections]\n",
+      "    return ''.join(rows)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 24
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = railfence_encipherl(message, height, fillvalue='!')\n",
+      "ciphertext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 175,
+       "text": [
+        "'hlohreltee'"
+       ]
+      }
+     ],
+     "prompt_number": 175
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "len(ciphertext)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 176,
+       "text": [
+        "10"
+       ]
+      }
+     ],
+     "prompt_number": 176
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "n_secs = len(ciphertext) // ((height - 1) * 2)\n",
+      "n_secs"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 177,
+       "text": [
+        "5"
+       ]
+      }
+     ],
+     "prompt_number": 177
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext[:5]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 109,
+       "text": [
+        "'hhaes'"
+       ]
+      }
+     ],
+     "prompt_number": 109
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext[5:15]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 110,
+       "text": [
+        "'etevshae!!'"
+       ]
+      }
+     ],
+     "prompt_number": 110
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext[15:25]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 111,
+       "text": [
+        "'lorateri!!'"
+       ]
+      }
+     ],
+     "prompt_number": 111
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext[25:]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 112,
+       "text": [
+        "'lemt!'"
+       ]
+      }
+     ],
+     "prompt_number": 112
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "downrows = [ciphertext[:n_secs]]\n",
+      "uprows = []\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 180,
+       "text": [
+        "(['hlohr'], [])"
+       ]
+      }
+     ],
+     "prompt_number": 180
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "for r in range(1, height, 2):\n",
+      "    midrow = ciphertext[r * n_secs:(r+2)*n_secs]\n",
+      "    downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
+      "    uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 179,
+       "text": [
+        "(['hlohr', 'ete'], ['le'])"
+       ]
+      }
+     ],
+     "prompt_number": 179
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "downrows += [ciphertext[-n_secs:]]\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 181,
+       "text": [
+        "(['hlohr', 'eltee'], [])"
+       ]
+      }
+     ],
+     "prompt_number": 181
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "rows = downrows + uprows\n",
+      "rows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 182,
+       "text": [
+        "['hlohr', 'eltee']"
+       ]
+      }
+     ],
+     "prompt_number": 182
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "midrow = rows[1]\n",
+      "midrow"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 64,
+       "text": [
+        "'elteevsmhate!!'"
+       ]
+      }
+     ],
+     "prompt_number": 64
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "mid_down = ''.join([midrow[i] for i in range(0, len(midrow), 2)])\n",
+      "mid_down"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 65,
+       "text": [
+        "'etesht!'"
+       ]
+      }
+     ],
+     "prompt_number": 65
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "mid_up = ''.join([midrow[i] for i in range(1, len(midrow), 2)])\n",
+      "mid_up"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 66,
+       "text": [
+        "'levmae!'"
+       ]
+      }
+     ],
+     "prompt_number": 66
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "rows = downrows + uprows\n",
+      "rows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 139,
+       "text": [
+        "['hhaesspfoilcs',\n",
+        " 'eesataitrnfi!',\n",
+        " 'lrtrhleetgep!',\n",
+        " 'lemtiocxernh!',\n",
+        " 'oaeisnetsace!',\n",
+        " 'tvheigoftier!']"
+       ]
+      }
+     ],
+     "prompt_number": 139
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "''.join(letter for section in zip(*rows) for letter in section)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 183,
+       "text": [
+        "'hellothere'"
+       ]
+      }
+     ],
+     "prompt_number": 183
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "def railfence_decipherl(message, height):\n",
+      "    n_secs = len(message) // ((height - 1) * 2)\n",
+      "    downrows = [message[:n_secs]]\n",
+      "    uprows = []\n",
+      "    for r in range(height-2):\n",
+      "        midrow = ciphertext[(2 * r + 1) * n_secs:(2 * r + 1) * n_secs + n_secs * 2]\n",
+      "        downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
+      "        uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
+      "    downrows += [message[-n_secs:]]\n",
+      "    rows = downrows + uprows\n",
+      "    return ''.join(letter for section in zip(*rows) for letter in section)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 249
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 154,
+       "text": [
+        "'hhaesetevshae!!lorateri!!lemt!'"
+       ]
+      }
+     ],
+     "prompt_number": 154
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl(ciphertext, 4)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 155,
+       "text": [
+        "''"
+       ]
+      }
+     ],
+     "prompt_number": 155
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "plaintext = sanitise('hello there avast me hearties this is a long piece of text for testing railfence ciphers')\n",
+      "plaintext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 250,
+       "text": [
+        "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers'"
+       ]
+      }
+     ],
+     "prompt_number": 250
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = railfence_encipherl(plaintext, height, fillvalue='!')\n",
+      "ciphertext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 163,
+       "text": [
+        "'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'"
+       ]
+      }
+     ],
+     "prompt_number": 163
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl(ciphertext, height)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 164,
+       "text": [
+        "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!'"
+       ]
+      }
+     ],
+     "prompt_number": 164
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_encipherl('hellothere', 2)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 186,
+       "text": [
+        "'hlohreltee'"
+       ]
+      }
+     ],
+     "prompt_number": 186
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl('hlohreltee', 2)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 187,
+       "text": [
+        "'hellothere'"
+       ]
+      }
+     ],
+     "prompt_number": 187
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "[i for i in range(1, 2, 2)]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 184,
+       "text": [
+        "[1]"
+       ]
+      }
+     ],
+     "prompt_number": 184
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 10, fillvalue='!')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 265,
+       "text": [
+        "'hepisehagitnr!!lernesge!!lmtocerh!!otiletap!!tseaorii!!hassfolc!!evtitffe!!rahsetec!!eixn!'"
+       ]
+      }
+     ],
+     "prompt_number": 265
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl('horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr!!lhateihsnefttiaece!', 3)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 191,
+       "text": [
+        "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!'"
+       ]
+      }
+     ],
+     "prompt_number": 191
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 4, fillvalue='!')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 240,
+       "text": [
+        "'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'"
+       ]
+      }
+     ],
+     "prompt_number": 240
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl('hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!', 4)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 241,
+       "text": [
+        "'hmelfhhetettaaimaoecetcosfei!rsn!olrpntcvefrsxa!o!teilihirgaltintecixhehsst!in'"
+       ]
+      }
+     ],
+     "prompt_number": 241
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 5, fillvalue='!')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 238,
+       "text": [
+        "'hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!'"
+       ]
+      }
+     ],
+     "prompt_number": 238
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "railfence_decipherl('hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!', 5)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 239,
+       "text": [
+        "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!!!'"
+       ]
+      }
+     ],
+     "prompt_number": 239
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "len(railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 5, fillvalue='!'))"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 199,
+       "text": [
+        "80"
+       ]
+      }
+     ],
+     "prompt_number": 199
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = 'horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr!!lhateihsnefttiaece!'\n",
+      "height=3"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 226
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = 'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'\n",
+      "height=4"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 242
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext = 'hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!'\n",
+      "height=5"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 226
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "n_secs = len(ciphertext) // ((height - 1) * 2)\n",
+      "n_secs"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 243,
+       "text": [
+        "13"
+       ]
+      }
+     ],
+     "prompt_number": 243
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "downrows = [ciphertext[:n_secs]]\n",
+      "uprows = []\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 244,
+       "text": [
+        "(['hhaesspfoilcs'], [])"
+       ]
+      }
+     ],
+     "prompt_number": 244
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "for r in range(height-2):\n",
+      "    print('From', (2 * r + 1) * n_secs, 'to', (2 * r + 1) * n_secs + n_secs * 2)\n",
+      "    midrow = ciphertext[(2 * r + 1) * n_secs:(2 * r + 1) * n_secs + n_secs * 2]\n",
+      "    downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
+      "    uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "From 13 to 39\n",
+        "From 39 to 65\n"
+       ]
+      },
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 245,
+       "text": [
+        "(['hhaesspfoilcs', 'eesataitrnfi!', 'lrtrhleetgep!'],\n",
+        " ['oaeisnetsace!', 'tvheigoftier!'])"
+       ]
+      }
+     ],
+     "prompt_number": 245
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "downrows += [ciphertext[-n_secs:]]\n",
+      "downrows, uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 246,
+       "text": [
+        "(['hhaesspfoilcs', 'eesataitrnfi!', 'lrtrhleetgep!', 'lemtiocxernh!'],\n",
+        " ['oaeisnetsace!', 'tvheigoftier!'])"
+       ]
+      }
+     ],
+     "prompt_number": 246
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "rows = downrows + uprows"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 247
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "''.join(letter for section in zip(*rows) for letter in section)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 248,
+       "text": [
+        "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!'"
+       ]
+      }
+     ],
+     "prompt_number": 248
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "[i for i in range(0)]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 236,
+       "text": [
+        "[]"
+       ]
+      }
+     ],
+     "prompt_number": 236
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "height = 3\n",
+      "ciphertext = railfence_encipherl(plaintext, height, fillvalue=' ')\n",
+      "result = railfence_decipherl(ciphertext, height).strip()\n",
+      "result == plaintext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 270,
+       "text": [
+        "True"
+       ]
+      }
+     ],
+     "prompt_number": 270
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "ciphertext"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 271,
+       "text": [
+        "'horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr  lhateihsnefttiaece '"
+       ]
+      }
+     ],
+     "prompt_number": 271
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
\ No newline at end of file