Challenge 8a done, 8b not attempted
[cipher-training.git] / 2015-challenge3.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "collapsed": false
8 },
9 "outputs": [],
10 "source": [
11 "import matplotlib.pyplot as plt\n",
12 "%matplotlib inline\n",
13 "\n",
14 "from cipherbreak import *\n",
15 "\n",
16 "c3a = open('2015/3a.ciphertext').read()\n",
17 "c3b = open('2015/3b.ciphertext').read()"
18 ]
19 },
20 {
21 "cell_type": "code",
22 "execution_count": 6,
23 "metadata": {
24 "collapsed": false
25 },
26 "outputs": [
27 {
28 "data": {
29 "text/plain": [
30 "((3, 5, True), -901.37737042341)"
31 ]
32 },
33 "execution_count": 6,
34 "metadata": {},
35 "output_type": "execute_result"
36 }
37 ],
38 "source": [
39 "(key_a_m, key_a_a, key_a_o), score = affine_break(c3a)\n",
40 "(key_a_m, key_a_a, key_a_o), score"
41 ]
42 },
43 {
44 "cell_type": "code",
45 "execution_count": 7,
46 "metadata": {
47 "collapsed": false
48 },
49 "outputs": [
50 {
51 "name": "stdout",
52 "output_type": "stream",
53 "text": [
54 "HARRY, THE PUZZLE OF THE STAMPED POSTCARD HAD ME FOOLED FOR A WHILE, BUT I THINK I FIGURED IT OUT. WAS THE MESSAGE ON THE BACK OF THE STAMP? I AM GUESSING YOU STEAMED IT OFF AND FOUND IT THERE. IT WAS A PRETTY INGENIOUS PLOY. MY MASTERS BACK IN WASHINGTON ARE INCREASINGLY WORRIED ABOUT OUR RELATIONSHIP WITH THE REST OF THE FOUR POWERS. FOLLOWING THE BREAKDOWN IN TRUST WITH THE SOVIETS THEY ARE COUNTING ON THE UK AND FRANCE AS ALLIES. IF THEY ARE GOING BEHIND OUR BACKS WITH THIS REICHSDOKTOR, THAT DOES NOT BODE WELL FOR FUTURE DIPLOMACY. DO YOU HAVE CONTACTS THERE YOU CAN EXPLOIT TO FIND OUT WHAT THEY ARE INTENDING? WE REALLY CANNOT AFFORD TO FALL OUT RIGHT NOW. THE ATTACHED MESSAGE IS ANOTHER INTERCEPT, THIS TIME FROM THE BRITISH EMBASSY WIRELESS. WHILE THINGS ARE DICEY I DON’T FEEL I CAN ASK THEM ABOUT IT, MAYBE YOU COULD CRACK IT FOR US. DOES IT MENTION THE RATLINES? BEST, CHARLIE\n",
55 "\n"
56 ]
57 }
58 ],
59 "source": [
60 "print(affine_decipher(c3a, multiplier=key_a_m, adder=key_a_a, one_based=key_a_o))"
61 ]
62 },
63 {
64 "cell_type": "code",
65 "execution_count": 10,
66 "metadata": {
67 "collapsed": false
68 },
69 "outputs": [
70 {
71 "data": {
72 "text/plain": [
73 "((5, 7, True), -574.5522852453349)"
74 ]
75 },
76 "execution_count": 10,
77 "metadata": {},
78 "output_type": "execute_result"
79 }
80 ],
81 "source": [
82 "(key_b_m, key_b_a, key_b_o), score = affine_break(c3b)\n",
83 "(key_b_m, key_b_a, key_b_o), score"
84 ]
85 },
86 {
87 "cell_type": "code",
88 "execution_count": 12,
89 "metadata": {
90 "collapsed": false
91 },
92 "outputs": [
93 {
94 "name": "stdout",
95 "output_type": "stream",
96 "text": [
97 "eyes only rumours of a source in berlin with access to the rat lines source seems to go by name of reichs doktor russian intercepts suggest has been seen in vicinity of us embassy not clear how to make direct contact also not clear why our us friends are keeping this to themselves detailed info about rat i lines hard to obtain but high value could lead to arrest of major targets of nuremberg investigations vital we reach reichs doktor at earliest opportunity discreet enquiries in french and us sectors only request funds for further investigation\n"
98 ]
99 }
100 ],
101 "source": [
102 "print(' '.join(segment(sanitise(affine_decipher(c3b, multiplier=key_b_m, adder=key_b_a, one_based=key_b_o)))))"
103 ]
104 },
105 {
106 "cell_type": "code",
107 "execution_count": null,
108 "metadata": {
109 "collapsed": false
110 },
111 "outputs": [],
112 "source": []
113 }
114 ],
115 "metadata": {
116 "kernelspec": {
117 "display_name": "Python 3",
118 "language": "python",
119 "name": "python3"
120 },
121 "language_info": {
122 "codemirror_mode": {
123 "name": "ipython",
124 "version": 3
125 },
126 "file_extension": ".py",
127 "mimetype": "text/x-python",
128 "name": "python",
129 "nbconvert_exporter": "python",
130 "pygments_lexer": "ipython3",
131 "version": "3.4.3"
132 }
133 },
134 "nbformat": 4,
135 "nbformat_minor": 0
136 }