Updated for challenge 9
[cipher-tools.git] / 2019 / 2019-challenge2.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) "
13 ]
14 },
15 {
16 "cell_type": "code",
17 "execution_count": 9,
18 "metadata": {},
19 "outputs": [],
20 "source": [
21 "from cipher.caesar import *\n",
22 "from cipher.affine import *\n",
23 "from support.text_prettify import *"
24 ]
25 },
26 {
27 "cell_type": "code",
28 "execution_count": 10,
29 "metadata": {},
30 "outputs": [],
31 "source": [
32 "ca = open('2a.ciphertext').read()\n",
33 "cb = open('2b.ciphertext').read()"
34 ]
35 },
36 {
37 "cell_type": "code",
38 "execution_count": 30,
39 "metadata": {},
40 "outputs": [
41 {
42 "name": "stdout",
43 "output_type": "stream",
44 "text": [
45 "11 7 True \n",
46 "\n",
47 "Meg, I took a look at the file you sent over and it was just a rotation cipher applied to the text.\n",
48 "At first it was hard to say if that was a bug or a feature and normally I would assume bug, but it\n",
49 "seemed odd that it was the only file that was affected so I asked around to see if anyone had seen\n",
50 "anything similar. It turns out that this was not the first navigation problem to hit the programme.\n",
51 "Gene reported a major issue with the guidance programme for Snoopy on the Apollo Ten mission which\n",
52 "could again have caused a major problem. For some reason the programme controlling the landing radar\n",
53 "wasn’t updated with the flight plan and if Gene hadn’t raised that with Iverson then the boys might\n",
54 "have had real trouble getting back. I looked through the company files and found another of our\n",
55 "mysteriously formatted reports: the memo informing them about the change, which explains why the\n",
56 "programme never got updated. This time the cipher was an affine shift, so slightly harder to crack,\n",
57 "but nothing serious. Still, it is much less likely that it was a bug that time, and in any case\n",
58 "twice is too much of a coincidence. It did start me wondering why the second cipher was easier to\n",
59 "crack than the first, but then I realised that the affine shift was too much of a giveaway. A\n",
60 "rotation cipher really could just be an encoding error, but the affine shift is too sophisticated\n",
61 "for a mistake, so whoever mangled the reports must have realised they had made a bit of an error\n",
62 "with the first one and tried to cover their steps with the second. It is hard to see this as\n",
63 "anything other than attempted sabotage, but I am not sure what the motive could be. I doubt it is\n",
64 "personal. The Apollo Ten and Eleven crews don’t overlap, so either someone has a grudge against the\n",
65 "whole Astronaut corps or they are trying to derail the Apollo programme. It could be the Soviets I\n",
66 "suppose. At first, I thought that their willingness to shift the LUNA-FIFTEEN orbit showed that they\n",
67 "weren’t part of it, but someone in the State Department pointed out that they might just have had a\n",
68 "guilty conscience, or been keen to distance themselves once the plot was discovered. I am still not\n",
69 "sure. In the meantime, could you take a look at the computer files to see who might have had access\n",
70 "to both memos, and who might have had the opportunity and means to doctor them? I am flying back to\n",
71 "Langley tonight, to see if the State Department have any ideas what might be going on. Neil said he\n",
72 "could fly me up in one of the NASA chase planes, which is something I have been keen to try. I will\n",
73 "call you if I get anything.\n"
74 ]
75 },
76 {
77 "data": {
78 "text/plain": [
79 "2592"
80 ]
81 },
82 "execution_count": 30,
83 "metadata": {},
84 "output_type": "execute_result"
85 }
86 ],
87 "source": [
88 "(m_a, s_a, o_a), score_a = affine_break(ca)\n",
89 "print(m_a, s_a, o_a, '\\n')\n",
90 "print(lcat(tpack(affine_decipher(ca, m_a, s_a, o_a).split())))\n",
91 "open('2a.plaintext', 'w').write(lcat(tpack(affine_decipher(ca, m_a, s_a, o_a).split())))"
92 ]
93 },
94 {
95 "cell_type": "code",
96 "execution_count": 29,
97 "metadata": {},
98 "outputs": [
99 {
100 "name": "stdout",
101 "output_type": "stream",
102 "text": [
103 "3 8 True \n",
104 "\n",
105 "Apollo Ten\n",
106 "Spacecraft Operational Trajectory\n",
107 "First Revision\n",
108 "This document contains updated information about the planned lunar orbital operations for the mission and has been compiled to satisfy flight crew/flight controller training and simulation requirements.\n",
109 "\n",
110 "The following mission phases remain UNCHANGED from the original plan:\n",
111 "Launch, which ends with insertion into earth parking orbit (EPO).\n",
112 "Earth orbit coast, which ends with Translunar Injection (TLI).\n",
113 "Trans Lunar coast, which ends with Lunar Orbit Insertion (LOI).\n",
114 "Trans Earth coast, which ends with re-entry into the mid-Pacific recovery area.\n",
115 "\n",
116 "The total mission duration will be approximately EIGHT days.\n",
117 "\n",
118 "The report includes significant changes to Lunar orbital operations, which start at LOI and end with Trans Earth lnjection. NOTE THESE IMPORTANT TRAJECTORY CHANGES\n",
119 "\n",
120 "The prime objective of the LOI-TEI phase will be to demonstrate all\n",
121 "components of Mission G except those which directly involve Lunar Module powered descent and powered ascent.\n",
122 "\n"
123 ]
124 },
125 {
126 "data": {
127 "text/plain": [
128 "1012"
129 ]
130 },
131 "execution_count": 29,
132 "metadata": {},
133 "output_type": "execute_result"
134 }
135 ],
136 "source": [
137 "(m_b, s_b, o_b), score_a = affine_break(cb)\n",
138 "print(m_b, s_b, o_b, '\\n')\n",
139 "print(affine_decipher(cb, m_b, s_b, o_b))\n",
140 "open('2b.plaintext', 'w').write(affine_decipher(cb, m_b, s_b, o_b))"
141 ]
142 },
143 {
144 "cell_type": "code",
145 "execution_count": null,
146 "metadata": {},
147 "outputs": [],
148 "source": []
149 }
150 ],
151 "metadata": {
152 "kernelspec": {
153 "display_name": "Python 3",
154 "language": "python",
155 "name": "python3"
156 },
157 "language_info": {
158 "codemirror_mode": {
159 "name": "ipython",
160 "version": 3
161 },
162 "file_extension": ".py",
163 "mimetype": "text/x-python",
164 "name": "python",
165 "nbconvert_exporter": "python",
166 "pygments_lexer": "ipython3",
167 "version": "3.6.8"
168 }
169 },
170 "nbformat": 4,
171 "nbformat_minor": 2
172 }