Updated for challenge 9
[cipher-tools.git] / 2014 / 2014-challenge1.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 2,
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.caesar import *\n",
18 "from support.utilities import *\n",
19 "from support.text_prettify import *\n",
20 "from support.language_models import *\n",
21 "\n",
22 "c1a = open('1a.ciphertext').read()\n",
23 "c1b = open('1b.ciphertext').read()"
24 ]
25 },
26 {
27 "cell_type": "code",
28 "execution_count": 3,
29 "metadata": {},
30 "outputs": [
31 {
32 "data": {
33 "text/plain": [
34 "(4, -728.156672407534)"
35 ]
36 },
37 "execution_count": 3,
38 "metadata": {},
39 "output_type": "execute_result"
40 }
41 ],
42 "source": [
43 "key_a, score = caesar_break(c1a)\n",
44 "key_a, score"
45 ]
46 },
47 {
48 "cell_type": "code",
49 "execution_count": 4,
50 "metadata": {},
51 "outputs": [
52 {
53 "name": "stdout",
54 "output_type": "stream",
55 "text": [
56 "MARK, \n",
57 "\n",
58 "THANKS FOR BRINGING ME IN ON THIS ONE, SEEMS LIKE A FASCINATING CASE. \n",
59 "\n",
60 "I HAVE THREE QUESTIONS: \n",
61 "WHY WOULD THE FLAG DAY ASSOCIATES WANT A SHIP? \n",
62 "WHY WOULD THEY WANT THIS SHIP? \n",
63 "WHY WOULD THEY WANT THIS SHIP NOW? \n",
64 "\n",
65 "HAVING READ THE ATTACHED DOCUMENT I SUSPECT THAT THE ANSWERS ARE ALL RELATED TO THE QUESTION OF WHAT EXACTLY SHE AND HER FLAG DAY ASSOCIATE CREW WERE TRYING TO SURVEY. \n",
66 "\n",
67 "I AM GUESSING THAT YOU ALREADY CHECKED OUT THE ONBOARD GPS SYSTEM FOR INFORMATION ABOUT HER MOVEMENTS, BUT IF YOU DID FIND ANYTHING I WOULD BE FASCINATED TO HEAR ABOUT IT. IN THE MEANTIME I AM PRETTY SURE THAT YOU KNOW MORE ABOUT THE FLAG DAY ASSOCIATES THAN YOU HAVE TOLD ME, SO A BRIEFING WOULD BE MUCH APPRECIATED. \n",
68 "\n",
69 "ALL THE BEST, \n",
70 "\n",
71 "HARRY \n",
72 "\n"
73 ]
74 }
75 ],
76 "source": [
77 "print(caesar_decipher(c1a, key_a))"
78 ]
79 },
80 {
81 "cell_type": "code",
82 "execution_count": 5,
83 "metadata": {},
84 "outputs": [
85 {
86 "data": {
87 "text/plain": [
88 "(22, -637.7038880633795)"
89 ]
90 },
91 "execution_count": 5,
92 "metadata": {},
93 "output_type": "execute_result"
94 }
95 ],
96 "source": [
97 "key_b, score = caesar_break(c1b)\n",
98 "key_b, score"
99 ]
100 },
101 {
102 "cell_type": "code",
103 "execution_count": 6,
104 "metadata": {},
105 "outputs": [
106 {
107 "name": "stdout",
108 "output_type": "stream",
109 "text": [
110 "report on the trojan project having drugged the crew we were able to take the ship with essentially no resistance the crew were handed to the somali pirates at the deepwater rendezvous as planned and we began the survey just after midnight the radar showed an approaching vessel which our database identified as a coastguard cutter we headed south to avoid detection with all ship lights off we then completed the survey in the new location afterdawn with the listening post installed we began assembling the equipment for phase two of the operation keeping a watch for further patrols in the sky and on the water\n"
111 ]
112 }
113 ],
114 "source": [
115 "print(' '.join(segment(sanitise(caesar_decipher(c1b, key_b)))))"
116 ]
117 },
118 {
119 "cell_type": "code",
120 "execution_count": 10,
121 "metadata": {},
122 "outputs": [
123 {
124 "name": "stdout",
125 "output_type": "stream",
126 "text": [
127 "report on the trojan project having drugged the crew we were able to take the ship with essentially\n",
128 "no resistance the crew were handed to the somali pirates at the deepwater rendezvous as planned and\n",
129 "we began the survey just after midnight the radar showed an approaching vessel which our database\n",
130 "identified as a coastguard cutter we headed south to avoid detection with all ship lights off we\n",
131 "then completed the survey in the new location afterdawn with the listening post installed we began\n",
132 "assembling the equipment for phase two of the operation keeping a watch for further patrols in the\n",
133 "sky and on the water\n"
134 ]
135 }
136 ],
137 "source": [
138 "print(lcat(tpack(segment(sanitise(caesar_decipher(c1b, key_b))))))"
139 ]
140 },
141 {
142 "cell_type": "code",
143 "execution_count": null,
144 "metadata": {},
145 "outputs": [],
146 "source": []
147 }
148 ],
149 "metadata": {
150 "kernelspec": {
151 "display_name": "Python 3",
152 "language": "python",
153 "name": "python3"
154 },
155 "language_info": {
156 "codemirror_mode": {
157 "name": "ipython",
158 "version": 3
159 },
160 "file_extension": ".py",
161 "mimetype": "text/x-python",
162 "name": "python",
163 "nbconvert_exporter": "python",
164 "pygments_lexer": "ipython3",
165 "version": "3.6.3"
166 }
167 },
168 "nbformat": 4,
169 "nbformat_minor": 1
170 }