Started on 2016
[cipher-training.git] / 2016 / 2016-challenge2.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "collapsed": true
8 },
9 "outputs": [],
10 "source": [
11 "import os,sys,inspect\n",
12 "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
13 "parentdir = os.path.dirname(currentdir)\n",
14 "sys.path.insert(0,parentdir) \n",
15 "\n",
16 "import matplotlib.pyplot as plt\n",
17 "%matplotlib inline\n",
18 "\n",
19 "from cipherbreak import *\n",
20 "\n",
21 "c2a = open('2a.ciphertext').read()\n",
22 "c2b = open('2b.ciphertext').read()"
23 ]
24 },
25 {
26 "cell_type": "code",
27 "execution_count": 2,
28 "metadata": {
29 "collapsed": false
30 },
31 "outputs": [
32 {
33 "data": {
34 "text/plain": [
35 "(6, -1833.0297785667572)"
36 ]
37 },
38 "execution_count": 2,
39 "metadata": {},
40 "output_type": "execute_result"
41 }
42 ],
43 "source": [
44 "key_a, score = caesar_break(c2a)\n",
45 "key_a, score"
46 ]
47 },
48 {
49 "cell_type": "code",
50 "execution_count": 6,
51 "metadata": {
52 "collapsed": false
53 },
54 "outputs": [
55 {
56 "name": "stdout",
57 "output_type": "stream",
58 "text": [
59 "CHARLIE\n",
60 "THE NOTE YOU SENT OVER WAS TRICKIER THAN I EXPECTED. JAMELIA DIDN'T JUST REVERSE THE WHOLE MESSAGE BEFORE ENCRYPTING IT, SHE PUT ALL THE PUNCTUATION AND SPACING BACK IN THE ORIGINAL PLACES TO THROW THE CASUAL READER OFF THE SCENT. IT WASN'T VERY SOPHISTICATED, BUT IT WAS DEVIOUS, AND TELLS US SOMETHING ABOUT THE WAY SHE THINKS. ONE THING I AM CERTAIN ABOUT, THIS DOESN'T READ LIKE A SUICIDE NOTE. WHO WRITES ONE OF THOSE IN CODE?\n",
61 "\n",
62 "OUR FIELD AGENT ASKED AROUND AT THE UNIVERSITY AND WAS TOLD THAT JAMELIA'S BOYFRIEND WORKED IN THE SAME LAB AS HER FOR A WHILE. HIS NAME IS MARTIN TRAYNOR AND THEY BOTH DID AN INTERNSHIP IN THEIR SECOND YEAR AT A SPINOUT COMPANY CALLED DYNAMIX. THAT IS A SMALL STARTUP WHICH WORKS ON THE FRINGES OF THE ARMS INDUSTRY, BUT NO-ONE SEEMS TO KNOW MUCH ABOUT IT.\n",
63 "\n",
64 "I AM NOT SURE WHY DYNAMIX WOULD HAVE HIRED JAMELIA; YOU SAID THAT SHE WAS WORKING ON GRAVITY WAVES, WHICH ARE A SEISMOLOGICAL PHENOMENON. I READ AN INTERESTING PAPER CALLED \"GRAVITY WAVES IN EARTHQUAKES\" WHICH SUGGESTED THAT THEY MIGHT BE RESPONSIBLE FOR THE DESTRUCTION OF HIGH RISE BLOCKS DURING SOME TREMORS. BUT UNLESS DYNAMIX ARE PLANNING TO TRY TO WEAPONISE EARTHQUAKES I AM NOT SURE WHY THIS WOULD BE OF INTEREST TO THEM. WE NEED TO KNOW MORE ABOUT HER WORK AND WHAT THEY HIRED HER TO DO.\n",
65 "\n",
66 "THERE ARE A LOT OF QUESTIONS EVEN IN THE FIRST NOTE:\n",
67 "\n",
68 "WHY DID MARTIN LEAVE?\n",
69 "WHERE IS HE?\n",
70 "WHY COULDN'T SHE GET HOLD OF HIM?\n",
71 "WHAT WAS TOO BIG FOR JAMELIA TO HANDLE ALONE?\n",
72 "WHAT MADE JAMELIA FEEL GUILTY?\n",
73 "HOW WAS SHE PLANNING TO FIX IT?\n",
74 "\n",
75 "I AM HOPING THAT THE ATTACHED DOCUMENT WILL ANSWER SOME OF THESE QUESTIONS BUT IT WILL PROBABLY JUST RAISE OTHERS. I FOUND IT PASTED UNDER THE COVER OF THE NOTEBOOK THAT THE PREVIOUS MESSAGE WAS TAKEN FROM. I CAN SEE WHY THE POLICE MISSED IT, THOUGH IT WASN'T A VERY PROFESSIONAL JOB.\n",
76 "\n",
77 "HARRY\n",
78 "\n"
79 ]
80 }
81 ],
82 "source": [
83 "print(caesar_decipher(c2a, key_a))"
84 ]
85 },
86 {
87 "cell_type": "code",
88 "execution_count": 7,
89 "metadata": {
90 "collapsed": false
91 },
92 "outputs": [
93 {
94 "data": {
95 "text/plain": [
96 "(17, -1552.2481210949848)"
97 ]
98 },
99 "execution_count": 7,
100 "metadata": {},
101 "output_type": "execute_result"
102 }
103 ],
104 "source": [
105 "key_b, score = caesar_break(c2b)\n",
106 "key_b, score"
107 ]
108 },
109 {
110 "cell_type": "code",
111 "execution_count": 10,
112 "metadata": {
113 "collapsed": false
114 },
115 "outputs": [
116 {
117 "name": "stdout",
118 "output_type": "stream",
119 "text": [
120 "NHFXCZDYX KDS TLSCZY,\n",
121 "\n",
122 "RUB LSF VZCLAFOOF ZYCFSFXCFA ZY ABYLTZW?\n",
123 "UDR AZA ABYLTZW PFC TB VDAF-QLXF?\n",
124 "RULC LSF ABYLTZW IOLYYZYP CD AD RZCU ZC?\n",
125 "RUB ZX UF XCZOO ZYMDOMFA RZCU CUFT?\n",
126 "RUD LSF CUF IAX XBYAZVLCF?\n",
127 "\n",
128 "Z CUZYJ Z JYDR CUF LYXRFSX, LYA Z LT ISFCCB XHSF UF THXC AD CDD. CUF CUSFF TDYCUX RF XIFYC RDSJZYP LC ABYLTZW RFSF XDTF DK CUF TDXC FWVZCZYP Z ULMF FMFS FWIFSZFYVFA, QHC XHSFOB, JYDRZYP RULC RF JYDR YDR, FMFY TLSCZY THXC ULMF XDTF SFXFSMLCZDYX LQDHC RDSJZYP RZCU CUFXF IFDIOF.\n",
129 "\n",
130 "Z LT YDC XHSF RUD CD CLOJ CD LQDHC CUZX. Z LT VFSCLZY CULC XDTF TFTQFSX DK CUF QDLSA LC ABYLTZW LSF VDTIOFCFOB ZY CUF ALSJ LQDHC ZC, YD VDYXIZSLVB RZCU CULC TLYB TFTQFSX VDHOA ULMF XHSMZMFA TDSF CULY L RFFJ, QHC Z ULMF YD ZAFL RUZVU DK CUFT Z VLY CSHXC. Z CUDHPUC Z VDHOA CSHXC TLSCZY, QHC CULC RLX QFKDSF CUF IAX ULVJ.\n",
131 "\n",
132 "Z VLY’C CLOJ CD CUF IDOZVF; XIFVZLO QSLYVU LSF VFSCLZY CD KOLP ZC PZMFY CUF YLTFX DK XDTF DK CUF IFDIOF DY CUF QDLSA. RZCU CUFZS VDYYFVCZDYX RUD JYDRX RULC TZPUC ULIIFY. CUF IAX XBYAZVLCF LSF CDD QZP KDS TF CD ULYAOF LODYF. CUFB JYDR LOTDXC FMFSBCUZYP LQDHC TF, LYA Z JYDR YFWC CD YDCUZYP LQDHC CUFT. ZK Z XCLB UFSF CD KZPUC, CUFY ZC ZX DYOB L TLCCFS DK CZTF HYCZO CUFB SFLOZXF Z LT DY CD CUFT. ZK Z ULMFY’C AZXLIIFLSFA QFKDSF CUFY, CUFY Z ULMF L KFFOZYP CUFB RZOO TLJF TF AZXLIIFLS.\n",
133 "\n"
134 ]
135 }
136 ],
137 "source": [
138 "print(c2b)"
139 ]
140 },
141 {
142 "cell_type": "code",
143 "execution_count": 9,
144 "metadata": {
145 "collapsed": false
146 },
147 "outputs": [
148 {
149 "name": "stdout",
150 "output_type": "stream",
151 "text": [
152 "WQOGLIMHG TMB CUBLIH,\n",
153 "\n",
154 "ADK UBO EILUJOXXO IHLOBOGLOJ IH JKHUCIF?\n",
155 "DMA JIJ JKHUCIF YOL CK EMJO-ZUGO?\n",
156 "ADUL UBO JKHUCIF RXUHHIHY LM JM AILD IL?\n",
157 "ADK IG DO GLIXX IHVMXVOJ AILD LDOC?\n",
158 "ADM UBO LDO RJG GKHJIEULO?\n",
159 "\n",
160 "I LDIHS I SHMA LDO UHGAOBG, UHJ I UC RBOLLK GQBO DO CQGL JM LMM. LDO LDBOO CMHLDG AO GROHL AMBSIHY UL JKHUCIF AOBO GMCO MT LDO CMGL OFEILIHY I DUVO OVOB OFROBIOHEOJ, ZQL GQBOXK, SHMAIHY ADUL AO SHMA HMA, OVOH CUBLIH CQGL DUVO GMCO BOGOBVULIMHG UZMQL AMBSIHY AILD LDOGO ROMRXO.\n",
161 "\n",
162 "I UC HML GQBO ADM LM LUXS LM UZMQL LDIG. I UC EOBLUIH LDUL GMCO COCZOBG MT LDO ZMUBJ UL JKHUCIF UBO EMCRXOLOXK IH LDO JUBS UZMQL IL, HM EMHGRIBUEK AILD LDUL CUHK COCZOBG EMQXJ DUVO GQBVIVOJ CMBO LDUH U AOOS, ZQL I DUVO HM IJOU ADIED MT LDOC I EUH LBQGL. I LDMQYDL I EMQXJ LBQGL CUBLIH, ZQL LDUL AUG ZOTMBO LDO RJG DUES.\n",
163 "\n",
164 "I EUH'L LUXS LM LDO RMXIEO; GROEIUX ZBUHED UBO EOBLUIH LM TXUY IL YIVOH LDO HUCOG MT GMCO MT LDO ROMRXO MH LDO ZMUBJ. AILD LDOIB EMHHOELIMHG ADM SHMAG ADUL CIYDL DURROH. LDO RJG GKHJIEULO UBO LMM ZIY TMB CO LM DUHJXO UXMHO. LDOK SHMA UXCMGL OVOBKLDIHY UZMQL CO, UHJ I SHMA HOFL LM HMLDIHY UZMQL LDOC. IT I GLUK DOBO LM TIYDL, LDOH IL IG MHXK U CULLOB MT LICO QHLIX LDOK BOUXIGO I UC MH LM LDOC. IT I DUVOH'L JIGURROUBOJ ZOTMBO LDOH, LDOH I DUVO U TOOXIHY LDOK AIXX CUSO CO JIGURROUB.\n",
165 "\n"
166 ]
167 }
168 ],
169 "source": [
170 "print(caesar_decipher(c2b, key_b))"
171 ]
172 },
173 {
174 "cell_type": "code",
175 "execution_count": 11,
176 "metadata": {
177 "collapsed": false
178 },
179 "outputs": [
180 {
181 "data": {
182 "text/plain": [
183 "((5, 7, True), -1275.2927860232996)"
184 ]
185 },
186 "execution_count": 11,
187 "metadata": {},
188 "output_type": "execute_result"
189 }
190 ],
191 "source": [
192 "key_b, score = affine_break(c2b)\n",
193 "key_b, score"
194 ]
195 },
196 {
197 "cell_type": "code",
198 "execution_count": 13,
199 "metadata": {
200 "collapsed": false
201 },
202 "outputs": [
203 {
204 "name": "stdout",
205 "output_type": "stream",
206 "text": [
207 "QUESTIONS FOR MARTIN,\n",
208 "\n",
209 "WHY ARE CITADELLE INTERESTED IN DYNAMIX?\n",
210 "HOW DID DYNAMIX GET MY CODE-BASE?\n",
211 "WHAT ARE DYNAMIX PLANNING TO DO WITH IT?\n",
212 "WHY IS HE STILL INVOLVED WITH THEM?\n",
213 "WHO ARE THE PDS SYNDICATE?\n",
214 "\n",
215 "I THINK I KNOW THE ANSWERS, AND I AM PRETTY SURE HE MUST DO TOO. THE THREE MONTHS WE SPENT WORKING AT DYNAMIX WERE SOME OF THE MOST EXCITING I HAVE EVER EXPERIENCED, BUT SURELY, KNOWING WHAT WE KNOW NOW, EVEN MARTIN MUST HAVE SOME RESERVATIONS ABOUT WORKING WITH THESE PEOPLE.\n",
216 "\n",
217 "I AM NOT SURE WHO TO TALK TO ABOUT THIS. I AM CERTAIN THAT SOME MEMBERS OF THE BOARD AT DYNAMIX ARE COMPLETELY IN THE DARK ABOUT IT, NO CONSPIRACY WITH THAT MANY MEMBERS COULD HAVE SURVIVED MORE THAN A WEEK, BUT I HAVE NO IDEA WHICH OF THEM I CAN TRUST. I THOUGHT I COULD TRUST MARTIN, BUT THAT WAS BEFORE THE PDS HACK.\n",
218 "\n",
219 "I CAN’T TALK TO THE POLICE; SPECIAL BRANCH ARE CERTAIN TO FLAG IT GIVEN THE NAMES OF SOME OF THE PEOPLE ON THE BOARD. WITH THEIR CONNECTIONS WHO KNOWS WHAT MIGHT HAPPEN. THE PDS SYNDICATE ARE TOO BIG FOR ME TO HANDLE ALONE. THEY KNOW ALMOST EVERYTHING ABOUT ME, AND I KNOW NEXT TO NOTHING ABOUT THEM. IF I STAY HERE TO FIGHT, THEN IT IS ONLY A MATTER OF TIME UNTIL THEY REALISE I AM ON TO THEM. IF I HAVEN’T DISAPPEARED BEFORE THEN, THEN I HAVE A FEELING THEY WILL MAKE ME DISAPPEAR.\n",
220 "\n"
221 ]
222 }
223 ],
224 "source": [
225 "print(affine_decipher(c2b, key_b[0], key_b[1], key_b[2]))"
226 ]
227 },
228 {
229 "cell_type": "code",
230 "execution_count": null,
231 "metadata": {
232 "collapsed": true
233 },
234 "outputs": [],
235 "source": []
236 }
237 ],
238 "metadata": {
239 "kernelspec": {
240 "display_name": "Python 3",
241 "language": "python",
242 "name": "python3"
243 },
244 "language_info": {
245 "codemirror_mode": {
246 "name": "ipython",
247 "version": 3
248 },
249 "file_extension": ".py",
250 "mimetype": "text/x-python",
251 "name": "python",
252 "nbconvert_exporter": "python",
253 "pygments_lexer": "ipython3",
254 "version": "3.5.2"
255 }
256 },
257 "nbformat": 4,
258 "nbformat_minor": 1
259 }