Updated for challenge 9
[cipher-tools.git] / 2015 / 2015-challenge8.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import os,sys,inspect\n",
10 "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
11 "parentdir = os.path.dirname(currentdir)\n",
12 "sys.path.insert(0,parentdir) \n",
13 "\n",
14 "import matplotlib.pyplot as plt\n",
15 "%matplotlib inline\n",
16 "\n",
17 "from cipher.vigenere import *\n",
18 "from support.utilities import *\n",
19 "from support.text_prettify import *\n",
20 "\n",
21 "c8a = sanitise(open('8a.ciphertext').read())\n",
22 "c8b = sanitise(open('8b.ciphertext').read())"
23 ]
24 },
25 {
26 "cell_type": "code",
27 "execution_count": 2,
28 "metadata": {},
29 "outputs": [
30 {
31 "data": {
32 "text/plain": [
33 "('charlie', -2104.8140749325567)"
34 ]
35 },
36 "execution_count": 2,
37 "metadata": {},
38 "output_type": "execute_result"
39 }
40 ],
41 "source": [
42 "key_a, score = vigenere_frequency_break(c8a)\n",
43 "key_a, score"
44 ]
45 },
46 {
47 "cell_type": "code",
48 "execution_count": 5,
49 "metadata": {},
50 "outputs": [
51 {
52 "name": "stdout",
53 "output_type": "stream",
54 "text": [
55 "harry i am so sorry we went into the russian hq last night without you but the station chief wanted\n",
56 "it to be his team that got the glory i am really grateful to you for coming back and putting us on\n",
57 "the right track though the stolen file from soviet headquarters was as you expected encrypted with\n",
58 "the solitaire cipher fortunately the cipher clerk who managed the encryption was incredibly careless\n",
59 "i found a sheet of burnt paper in the bin which gave me a list of thirty eight cards and i am hoping\n",
60 "that this is a large part of the key it will still be hard to break but maybe not impossible\n",
61 "especially as the erased part was still intact there maybe another clue in that the page appears to\n",
62 "have been torn from an economics textbook i found on the desk anyway i figure the chemists at\n",
63 "langley may help us to reconstruct the whole key given time though i wouldnt expect them to manage\n",
64 "more than one card a day given how careful they will have to be not to destroy the document it will\n",
65 "take usa while to crack this but maybe time is on our side with christmas things seem to be quiet\n",
66 "and i am hoping that within the next three weeks we may know precisely what the soviets were trying\n",
67 "to do here whatever the outcome i think it is clear that the future of europe is not likely to be\n",
68 "settled for a while i hear rumours everyday about shortages in the soviet bloc and border controls\n",
69 "are going up in places you wouldnt expect to prevent largescale migration there are problems in\n",
70 "greece and turkey and divisions between the british and french and the brits are having real trouble\n",
71 "paying off their war debts whether or not we crack the reichs doktor mystery i think there is going\n",
72 "to be plenty for you to do i know we had to work hard to persuade you to flyover but we really do\n",
73 "need you here even the chief recognizes that so if i can i want to persuade you to stay francois and\n",
74 "i are being posted to paris kind of a thankyou for our work on this project but icant go unless i\n",
75 "know the berlin station has someone i trust hope youll agree to take the job charlie\n"
76 ]
77 }
78 ],
79 "source": [
80 "print(lcat(tpack(segment(vigenere_decipher(c8a, key_a)))))"
81 ]
82 },
83 {
84 "cell_type": "code",
85 "execution_count": null,
86 "metadata": {
87 "collapsed": true
88 },
89 "outputs": [],
90 "source": []
91 }
92 ],
93 "metadata": {
94 "kernelspec": {
95 "display_name": "Python 3",
96 "language": "python",
97 "name": "python3"
98 },
99 "language_info": {
100 "codemirror_mode": {
101 "name": "ipython",
102 "version": 3
103 },
104 "file_extension": ".py",
105 "mimetype": "text/x-python",
106 "name": "python",
107 "nbconvert_exporter": "python",
108 "pygments_lexer": "ipython3",
109 "version": "3.6.3"
110 }
111 },
112 "nbformat": 4,
113 "nbformat_minor": 1
114 }