Updated for challenge 9
[cipher-tools.git] / railfence-experiment-1.ipynb
1 {
2 "metadata": {
3 "name": "",
4 "signature": "sha256:c4879f550d49d776eff31ee9f3296756aab1dcd81e1e5aad61ade46d9b29600d"
5 },
6 "nbformat": 3,
7 "nbformat_minor": 0,
8 "worksheets": [
9 {
10 "cells": [
11 {
12 "cell_type": "code",
13 "collapsed": false,
14 "input": [
15 "from cipher import *"
16 ],
17 "language": "python",
18 "metadata": {},
19 "outputs": [],
20 "prompt_number": 1
21 },
22 {
23 "cell_type": "code",
24 "collapsed": false,
25 "input": [
26 "railfence_encipherl('hellothere', 3)"
27 ],
28 "language": "python",
29 "metadata": {},
30 "outputs": [
31 {
32 "metadata": {},
33 "output_type": "pyout",
34 "prompt_number": 25,
35 "text": [
36 "'horeltee lh '"
37 ]
38 }
39 ],
40 "prompt_number": 25
41 },
42 {
43 "cell_type": "code",
44 "collapsed": false,
45 "input": [
46 "message = 'hellothere'\n",
47 "height = 2"
48 ],
49 "language": "python",
50 "metadata": {},
51 "outputs": [],
52 "prompt_number": 169
53 },
54 {
55 "cell_type": "code",
56 "collapsed": false,
57 "input": [
58 "sections = chunks(message, (height - 1) * 2, fillvalue='!')\n",
59 "sections"
60 ],
61 "language": "python",
62 "metadata": {},
63 "outputs": [
64 {
65 "metadata": {},
66 "output_type": "pyout",
67 "prompt_number": 170,
68 "text": [
69 "['he', 'll', 'ot', 'he', 're']"
70 ]
71 }
72 ],
73 "prompt_number": 170
74 },
75 {
76 "cell_type": "code",
77 "collapsed": false,
78 "input": [
79 "rows = [s[0] for s in sections]\n",
80 "rows"
81 ],
82 "language": "python",
83 "metadata": {},
84 "outputs": [
85 {
86 "metadata": {},
87 "output_type": "pyout",
88 "prompt_number": 171,
89 "text": [
90 "['h', 'l', 'o', 'h', 'r']"
91 ]
92 }
93 ],
94 "prompt_number": 171
95 },
96 {
97 "cell_type": "code",
98 "collapsed": false,
99 "input": [
100 "for r in range(1, height - 1):\n",
101 " rows += [s[r] + s[-r] for s in sections]\n",
102 "rows"
103 ],
104 "language": "python",
105 "metadata": {},
106 "outputs": [
107 {
108 "metadata": {},
109 "output_type": "pyout",
110 "prompt_number": 172,
111 "text": [
112 "['h', 'l', 'o', 'h', 'r']"
113 ]
114 }
115 ],
116 "prompt_number": 172
117 },
118 {
119 "cell_type": "code",
120 "collapsed": false,
121 "input": [
122 "rows += [s[height - 1] for s in sections]\n",
123 "rows"
124 ],
125 "language": "python",
126 "metadata": {},
127 "outputs": [
128 {
129 "metadata": {},
130 "output_type": "pyout",
131 "prompt_number": 173,
132 "text": [
133 "['h', 'l', 'o', 'h', 'r', 'e', 'l', 't', 'e', 'e']"
134 ]
135 }
136 ],
137 "prompt_number": 173
138 },
139 {
140 "cell_type": "code",
141 "collapsed": false,
142 "input": [
143 "ciphertext = ''.join(rows)\n",
144 "ciphertext"
145 ],
146 "language": "python",
147 "metadata": {},
148 "outputs": [
149 {
150 "metadata": {},
151 "output_type": "pyout",
152 "prompt_number": 174,
153 "text": [
154 "'hlohreltee'"
155 ]
156 }
157 ],
158 "prompt_number": 174
159 },
160 {
161 "cell_type": "code",
162 "collapsed": false,
163 "input": [
164 "def railfence_encipherl(message, height, fillvalue=' '):\n",
165 " \"\"\"Railfence cipher\n",
166 " \"\"\"\n",
167 " sections = chunks(message, (height - 1) * 2, fillvalue=fillvalue)\n",
168 " # Add the top row\n",
169 " rows = [s[0] for s in sections]\n",
170 " # process the middle rows of the grid\n",
171 " for r in range(1, height - 1):\n",
172 " rows += [s[r] + s[-r] for s in sections]\n",
173 " # process the bottom row\n",
174 " rows += [s[height - 1] for s in sections]\n",
175 " return ''.join(rows)"
176 ],
177 "language": "python",
178 "metadata": {},
179 "outputs": [],
180 "prompt_number": 24
181 },
182 {
183 "cell_type": "code",
184 "collapsed": false,
185 "input": [
186 "ciphertext = railfence_encipherl(message, height, fillvalue='!')\n",
187 "ciphertext"
188 ],
189 "language": "python",
190 "metadata": {},
191 "outputs": [
192 {
193 "metadata": {},
194 "output_type": "pyout",
195 "prompt_number": 175,
196 "text": [
197 "'hlohreltee'"
198 ]
199 }
200 ],
201 "prompt_number": 175
202 },
203 {
204 "cell_type": "code",
205 "collapsed": false,
206 "input": [
207 "len(ciphertext)"
208 ],
209 "language": "python",
210 "metadata": {},
211 "outputs": [
212 {
213 "metadata": {},
214 "output_type": "pyout",
215 "prompt_number": 176,
216 "text": [
217 "10"
218 ]
219 }
220 ],
221 "prompt_number": 176
222 },
223 {
224 "cell_type": "code",
225 "collapsed": false,
226 "input": [
227 "n_secs = len(ciphertext) // ((height - 1) * 2)\n",
228 "n_secs"
229 ],
230 "language": "python",
231 "metadata": {},
232 "outputs": [
233 {
234 "metadata": {},
235 "output_type": "pyout",
236 "prompt_number": 177,
237 "text": [
238 "5"
239 ]
240 }
241 ],
242 "prompt_number": 177
243 },
244 {
245 "cell_type": "code",
246 "collapsed": false,
247 "input": [
248 "ciphertext[:5]"
249 ],
250 "language": "python",
251 "metadata": {},
252 "outputs": [
253 {
254 "metadata": {},
255 "output_type": "pyout",
256 "prompt_number": 109,
257 "text": [
258 "'hhaes'"
259 ]
260 }
261 ],
262 "prompt_number": 109
263 },
264 {
265 "cell_type": "code",
266 "collapsed": false,
267 "input": [
268 "ciphertext[5:15]"
269 ],
270 "language": "python",
271 "metadata": {},
272 "outputs": [
273 {
274 "metadata": {},
275 "output_type": "pyout",
276 "prompt_number": 110,
277 "text": [
278 "'etevshae!!'"
279 ]
280 }
281 ],
282 "prompt_number": 110
283 },
284 {
285 "cell_type": "code",
286 "collapsed": false,
287 "input": [
288 "ciphertext[15:25]"
289 ],
290 "language": "python",
291 "metadata": {},
292 "outputs": [
293 {
294 "metadata": {},
295 "output_type": "pyout",
296 "prompt_number": 111,
297 "text": [
298 "'lorateri!!'"
299 ]
300 }
301 ],
302 "prompt_number": 111
303 },
304 {
305 "cell_type": "code",
306 "collapsed": false,
307 "input": [
308 "ciphertext[25:]"
309 ],
310 "language": "python",
311 "metadata": {},
312 "outputs": [
313 {
314 "metadata": {},
315 "output_type": "pyout",
316 "prompt_number": 112,
317 "text": [
318 "'lemt!'"
319 ]
320 }
321 ],
322 "prompt_number": 112
323 },
324 {
325 "cell_type": "code",
326 "collapsed": false,
327 "input": [
328 "downrows = [ciphertext[:n_secs]]\n",
329 "uprows = []\n",
330 "downrows, uprows"
331 ],
332 "language": "python",
333 "metadata": {},
334 "outputs": [
335 {
336 "metadata": {},
337 "output_type": "pyout",
338 "prompt_number": 180,
339 "text": [
340 "(['hlohr'], [])"
341 ]
342 }
343 ],
344 "prompt_number": 180
345 },
346 {
347 "cell_type": "code",
348 "collapsed": false,
349 "input": [
350 "for r in range(1, height, 2):\n",
351 " midrow = ciphertext[r * n_secs:(r+2)*n_secs]\n",
352 " downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
353 " uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
354 "downrows, uprows"
355 ],
356 "language": "python",
357 "metadata": {},
358 "outputs": [
359 {
360 "metadata": {},
361 "output_type": "pyout",
362 "prompt_number": 179,
363 "text": [
364 "(['hlohr', 'ete'], ['le'])"
365 ]
366 }
367 ],
368 "prompt_number": 179
369 },
370 {
371 "cell_type": "code",
372 "collapsed": false,
373 "input": [
374 "downrows += [ciphertext[-n_secs:]]\n",
375 "downrows, uprows"
376 ],
377 "language": "python",
378 "metadata": {},
379 "outputs": [
380 {
381 "metadata": {},
382 "output_type": "pyout",
383 "prompt_number": 181,
384 "text": [
385 "(['hlohr', 'eltee'], [])"
386 ]
387 }
388 ],
389 "prompt_number": 181
390 },
391 {
392 "cell_type": "code",
393 "collapsed": false,
394 "input": [
395 "rows = downrows + uprows\n",
396 "rows"
397 ],
398 "language": "python",
399 "metadata": {},
400 "outputs": [
401 {
402 "metadata": {},
403 "output_type": "pyout",
404 "prompt_number": 182,
405 "text": [
406 "['hlohr', 'eltee']"
407 ]
408 }
409 ],
410 "prompt_number": 182
411 },
412 {
413 "cell_type": "code",
414 "collapsed": false,
415 "input": [
416 "midrow = rows[1]\n",
417 "midrow"
418 ],
419 "language": "python",
420 "metadata": {},
421 "outputs": [
422 {
423 "metadata": {},
424 "output_type": "pyout",
425 "prompt_number": 64,
426 "text": [
427 "'elteevsmhate!!'"
428 ]
429 }
430 ],
431 "prompt_number": 64
432 },
433 {
434 "cell_type": "code",
435 "collapsed": false,
436 "input": [
437 "mid_down = ''.join([midrow[i] for i in range(0, len(midrow), 2)])\n",
438 "mid_down"
439 ],
440 "language": "python",
441 "metadata": {},
442 "outputs": [
443 {
444 "metadata": {},
445 "output_type": "pyout",
446 "prompt_number": 65,
447 "text": [
448 "'etesht!'"
449 ]
450 }
451 ],
452 "prompt_number": 65
453 },
454 {
455 "cell_type": "code",
456 "collapsed": false,
457 "input": [
458 "mid_up = ''.join([midrow[i] for i in range(1, len(midrow), 2)])\n",
459 "mid_up"
460 ],
461 "language": "python",
462 "metadata": {},
463 "outputs": [
464 {
465 "metadata": {},
466 "output_type": "pyout",
467 "prompt_number": 66,
468 "text": [
469 "'levmae!'"
470 ]
471 }
472 ],
473 "prompt_number": 66
474 },
475 {
476 "cell_type": "code",
477 "collapsed": false,
478 "input": [
479 "rows = downrows + uprows\n",
480 "rows"
481 ],
482 "language": "python",
483 "metadata": {},
484 "outputs": [
485 {
486 "metadata": {},
487 "output_type": "pyout",
488 "prompt_number": 139,
489 "text": [
490 "['hhaesspfoilcs',\n",
491 " 'eesataitrnfi!',\n",
492 " 'lrtrhleetgep!',\n",
493 " 'lemtiocxernh!',\n",
494 " 'oaeisnetsace!',\n",
495 " 'tvheigoftier!']"
496 ]
497 }
498 ],
499 "prompt_number": 139
500 },
501 {
502 "cell_type": "code",
503 "collapsed": false,
504 "input": [
505 "''.join(letter for section in zip(*rows) for letter in section)"
506 ],
507 "language": "python",
508 "metadata": {},
509 "outputs": [
510 {
511 "metadata": {},
512 "output_type": "pyout",
513 "prompt_number": 183,
514 "text": [
515 "'hellothere'"
516 ]
517 }
518 ],
519 "prompt_number": 183
520 },
521 {
522 "cell_type": "code",
523 "collapsed": false,
524 "input": [
525 "def railfence_decipherl(message, height):\n",
526 " n_secs = len(message) // ((height - 1) * 2)\n",
527 " downrows = [message[:n_secs]]\n",
528 " uprows = []\n",
529 " for r in range(height-2):\n",
530 " midrow = ciphertext[(2 * r + 1) * n_secs:(2 * r + 1) * n_secs + n_secs * 2]\n",
531 " downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
532 " uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
533 " downrows += [message[-n_secs:]]\n",
534 " rows = downrows + uprows\n",
535 " return ''.join(letter for section in zip(*rows) for letter in section)"
536 ],
537 "language": "python",
538 "metadata": {},
539 "outputs": [],
540 "prompt_number": 249
541 },
542 {
543 "cell_type": "code",
544 "collapsed": false,
545 "input": [
546 "ciphertext"
547 ],
548 "language": "python",
549 "metadata": {},
550 "outputs": [
551 {
552 "metadata": {},
553 "output_type": "pyout",
554 "prompt_number": 154,
555 "text": [
556 "'hhaesetevshae!!lorateri!!lemt!'"
557 ]
558 }
559 ],
560 "prompt_number": 154
561 },
562 {
563 "cell_type": "code",
564 "collapsed": false,
565 "input": [
566 "railfence_decipherl(ciphertext, 4)"
567 ],
568 "language": "python",
569 "metadata": {},
570 "outputs": [
571 {
572 "metadata": {},
573 "output_type": "pyout",
574 "prompt_number": 155,
575 "text": [
576 "''"
577 ]
578 }
579 ],
580 "prompt_number": 155
581 },
582 {
583 "cell_type": "code",
584 "collapsed": false,
585 "input": [
586 "plaintext = sanitise('hello there avast me hearties this is a long piece of text for testing railfence ciphers')\n",
587 "plaintext"
588 ],
589 "language": "python",
590 "metadata": {},
591 "outputs": [
592 {
593 "metadata": {},
594 "output_type": "pyout",
595 "prompt_number": 250,
596 "text": [
597 "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers'"
598 ]
599 }
600 ],
601 "prompt_number": 250
602 },
603 {
604 "cell_type": "code",
605 "collapsed": false,
606 "input": [
607 "ciphertext = railfence_encipherl(plaintext, height, fillvalue='!')\n",
608 "ciphertext"
609 ],
610 "language": "python",
611 "metadata": {},
612 "outputs": [
613 {
614 "metadata": {},
615 "output_type": "pyout",
616 "prompt_number": 163,
617 "text": [
618 "'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'"
619 ]
620 }
621 ],
622 "prompt_number": 163
623 },
624 {
625 "cell_type": "code",
626 "collapsed": false,
627 "input": [
628 "railfence_decipherl(ciphertext, height)"
629 ],
630 "language": "python",
631 "metadata": {},
632 "outputs": [
633 {
634 "metadata": {},
635 "output_type": "pyout",
636 "prompt_number": 164,
637 "text": [
638 "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!'"
639 ]
640 }
641 ],
642 "prompt_number": 164
643 },
644 {
645 "cell_type": "code",
646 "collapsed": false,
647 "input": [
648 "railfence_encipherl('hellothere', 2)"
649 ],
650 "language": "python",
651 "metadata": {},
652 "outputs": [
653 {
654 "metadata": {},
655 "output_type": "pyout",
656 "prompt_number": 186,
657 "text": [
658 "'hlohreltee'"
659 ]
660 }
661 ],
662 "prompt_number": 186
663 },
664 {
665 "cell_type": "code",
666 "collapsed": false,
667 "input": [
668 "railfence_decipherl('hlohreltee', 2)"
669 ],
670 "language": "python",
671 "metadata": {},
672 "outputs": [
673 {
674 "metadata": {},
675 "output_type": "pyout",
676 "prompt_number": 187,
677 "text": [
678 "'hellothere'"
679 ]
680 }
681 ],
682 "prompt_number": 187
683 },
684 {
685 "cell_type": "code",
686 "collapsed": false,
687 "input": [
688 "[i for i in range(1, 2, 2)]"
689 ],
690 "language": "python",
691 "metadata": {},
692 "outputs": [
693 {
694 "metadata": {},
695 "output_type": "pyout",
696 "prompt_number": 184,
697 "text": [
698 "[1]"
699 ]
700 }
701 ],
702 "prompt_number": 184
703 },
704 {
705 "cell_type": "code",
706 "collapsed": false,
707 "input": [
708 "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 10, fillvalue='!')"
709 ],
710 "language": "python",
711 "metadata": {},
712 "outputs": [
713 {
714 "metadata": {},
715 "output_type": "pyout",
716 "prompt_number": 265,
717 "text": [
718 "'hepisehagitnr!!lernesge!!lmtocerh!!otiletap!!tseaorii!!hassfolc!!evtitffe!!rahsetec!!eixn!'"
719 ]
720 }
721 ],
722 "prompt_number": 265
723 },
724 {
725 "cell_type": "code",
726 "collapsed": false,
727 "input": [
728 "railfence_decipherl('horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr!!lhateihsnefttiaece!', 3)"
729 ],
730 "language": "python",
731 "metadata": {},
732 "outputs": [
733 {
734 "metadata": {},
735 "output_type": "pyout",
736 "prompt_number": 191,
737 "text": [
738 "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!'"
739 ]
740 }
741 ],
742 "prompt_number": 191
743 },
744 {
745 "cell_type": "code",
746 "collapsed": false,
747 "input": [
748 "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 4, fillvalue='!')"
749 ],
750 "language": "python",
751 "metadata": {},
752 "outputs": [
753 {
754 "metadata": {},
755 "output_type": "pyout",
756 "prompt_number": 240,
757 "text": [
758 "'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'"
759 ]
760 }
761 ],
762 "prompt_number": 240
763 },
764 {
765 "cell_type": "code",
766 "collapsed": false,
767 "input": [
768 "railfence_decipherl('hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!', 4)"
769 ],
770 "language": "python",
771 "metadata": {},
772 "outputs": [
773 {
774 "metadata": {},
775 "output_type": "pyout",
776 "prompt_number": 241,
777 "text": [
778 "'hmelfhhetettaaimaoecetcosfei!rsn!olrpntcvefrsxa!o!teilihirgaltintecixhehsst!in'"
779 ]
780 }
781 ],
782 "prompt_number": 241
783 },
784 {
785 "cell_type": "code",
786 "collapsed": false,
787 "input": [
788 "railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 5, fillvalue='!')"
789 ],
790 "language": "python",
791 "metadata": {},
792 "outputs": [
793 {
794 "metadata": {},
795 "output_type": "pyout",
796 "prompt_number": 238,
797 "text": [
798 "'hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!'"
799 ]
800 }
801 ],
802 "prompt_number": 238
803 },
804 {
805 "cell_type": "code",
806 "collapsed": false,
807 "input": [
808 "railfence_decipherl('hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!', 5)"
809 ],
810 "language": "python",
811 "metadata": {},
812 "outputs": [
813 {
814 "metadata": {},
815 "output_type": "pyout",
816 "prompt_number": 239,
817 "text": [
818 "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!!!'"
819 ]
820 }
821 ],
822 "prompt_number": 239
823 },
824 {
825 "cell_type": "code",
826 "collapsed": false,
827 "input": [
828 "len(railfence_encipherl('hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers', 5, fillvalue='!'))"
829 ],
830 "language": "python",
831 "metadata": {},
832 "outputs": [
833 {
834 "metadata": {},
835 "output_type": "pyout",
836 "prompt_number": 199,
837 "text": [
838 "80"
839 ]
840 }
841 ],
842 "prompt_number": 199
843 },
844 {
845 "cell_type": "code",
846 "collapsed": false,
847 "input": [
848 "ciphertext = 'horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr!!lhateihsnefttiaece!'\n",
849 "height=3"
850 ],
851 "language": "python",
852 "metadata": {},
853 "outputs": [],
854 "prompt_number": 226
855 },
856 {
857 "cell_type": "code",
858 "collapsed": false,
859 "input": [
860 "ciphertext = 'hhaesspfoilcsetevshaetiagiotfrtnifeir!!loraterihslneeettsgaecpe!!lemtiocxernh!'\n",
861 "height=4"
862 ],
863 "language": "python",
864 "metadata": {},
865 "outputs": [],
866 "prompt_number": 242
867 },
868 {
869 "cell_type": "code",
870 "collapsed": false,
871 "input": [
872 "ciphertext = 'hresleogcseeemhetaocofrnrner!!lhateihsnefttiaece!!ltvsatiigitxetifih!!oarspeslp!'\n",
873 "height=5"
874 ],
875 "language": "python",
876 "metadata": {},
877 "outputs": [],
878 "prompt_number": 226
879 },
880 {
881 "cell_type": "code",
882 "collapsed": false,
883 "input": [
884 "n_secs = len(ciphertext) // ((height - 1) * 2)\n",
885 "n_secs"
886 ],
887 "language": "python",
888 "metadata": {},
889 "outputs": [
890 {
891 "metadata": {},
892 "output_type": "pyout",
893 "prompt_number": 243,
894 "text": [
895 "13"
896 ]
897 }
898 ],
899 "prompt_number": 243
900 },
901 {
902 "cell_type": "code",
903 "collapsed": false,
904 "input": [
905 "downrows = [ciphertext[:n_secs]]\n",
906 "uprows = []\n",
907 "downrows, uprows"
908 ],
909 "language": "python",
910 "metadata": {},
911 "outputs": [
912 {
913 "metadata": {},
914 "output_type": "pyout",
915 "prompt_number": 244,
916 "text": [
917 "(['hhaesspfoilcs'], [])"
918 ]
919 }
920 ],
921 "prompt_number": 244
922 },
923 {
924 "cell_type": "code",
925 "collapsed": false,
926 "input": [
927 "for r in range(height-2):\n",
928 " print('From', (2 * r + 1) * n_secs, 'to', (2 * r + 1) * n_secs + n_secs * 2)\n",
929 " midrow = ciphertext[(2 * r + 1) * n_secs:(2 * r + 1) * n_secs + n_secs * 2]\n",
930 " downrows += [''.join([midrow[i] for i in range(0, len(midrow), 2)])]\n",
931 " uprows = [''.join([midrow[i] for i in range(1, len(midrow), 2)])] + uprows\n",
932 "downrows, uprows"
933 ],
934 "language": "python",
935 "metadata": {},
936 "outputs": [
937 {
938 "output_type": "stream",
939 "stream": "stdout",
940 "text": [
941 "From 13 to 39\n",
942 "From 39 to 65\n"
943 ]
944 },
945 {
946 "metadata": {},
947 "output_type": "pyout",
948 "prompt_number": 245,
949 "text": [
950 "(['hhaesspfoilcs', 'eesataitrnfi!', 'lrtrhleetgep!'],\n",
951 " ['oaeisnetsace!', 'tvheigoftier!'])"
952 ]
953 }
954 ],
955 "prompt_number": 245
956 },
957 {
958 "cell_type": "code",
959 "collapsed": false,
960 "input": [
961 "downrows += [ciphertext[-n_secs:]]\n",
962 "downrows, uprows"
963 ],
964 "language": "python",
965 "metadata": {},
966 "outputs": [
967 {
968 "metadata": {},
969 "output_type": "pyout",
970 "prompt_number": 246,
971 "text": [
972 "(['hhaesspfoilcs', 'eesataitrnfi!', 'lrtrhleetgep!', 'lemtiocxernh!'],\n",
973 " ['oaeisnetsace!', 'tvheigoftier!'])"
974 ]
975 }
976 ],
977 "prompt_number": 246
978 },
979 {
980 "cell_type": "code",
981 "collapsed": false,
982 "input": [
983 "rows = downrows + uprows"
984 ],
985 "language": "python",
986 "metadata": {},
987 "outputs": [],
988 "prompt_number": 247
989 },
990 {
991 "cell_type": "code",
992 "collapsed": false,
993 "input": [
994 "''.join(letter for section in zip(*rows) for letter in section)"
995 ],
996 "language": "python",
997 "metadata": {},
998 "outputs": [
999 {
1000 "metadata": {},
1001 "output_type": "pyout",
1002 "prompt_number": 248,
1003 "text": [
1004 "'hellothereavastmeheartiesthisisalongpieceoftextfortestingrailfenceciphers!!!!!'"
1005 ]
1006 }
1007 ],
1008 "prompt_number": 248
1009 },
1010 {
1011 "cell_type": "code",
1012 "collapsed": false,
1013 "input": [
1014 "[i for i in range(0)]"
1015 ],
1016 "language": "python",
1017 "metadata": {},
1018 "outputs": [
1019 {
1020 "metadata": {},
1021 "output_type": "pyout",
1022 "prompt_number": 236,
1023 "text": [
1024 "[]"
1025 ]
1026 }
1027 ],
1028 "prompt_number": 236
1029 },
1030 {
1031 "cell_type": "code",
1032 "collapsed": false,
1033 "input": [
1034 "height = 3\n",
1035 "ciphertext = railfence_encipherl(plaintext, height, fillvalue=' ')\n",
1036 "result = railfence_decipherl(ciphertext, height).strip()\n",
1037 "result == plaintext"
1038 ],
1039 "language": "python",
1040 "metadata": {},
1041 "outputs": [
1042 {
1043 "metadata": {},
1044 "output_type": "pyout",
1045 "prompt_number": 270,
1046 "text": [
1047 "True"
1048 ]
1049 }
1050 ],
1051 "prompt_number": 270
1052 },
1053 {
1054 "cell_type": "code",
1055 "collapsed": false,
1056 "input": [
1057 "ciphertext"
1058 ],
1059 "language": "python",
1060 "metadata": {},
1061 "outputs": [
1062 {
1063 "metadata": {},
1064 "output_type": "pyout",
1065 "prompt_number": 271,
1066 "text": [
1067 "'horaersslpeeosglcpselteevsmhatetiiaogicotxfretnrifneihr lhateihsnefttiaece '"
1068 ]
1069 }
1070 ],
1071 "prompt_number": 271
1072 },
1073 {
1074 "cell_type": "code",
1075 "collapsed": false,
1076 "input": [],
1077 "language": "python",
1078 "metadata": {},
1079 "outputs": []
1080 }
1081 ],
1082 "metadata": {}
1083 }
1084 ]
1085 }