--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os,sys,inspect\n",
+ "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
+ "parentdir = os.path.dirname(currentdir)\n",
+ "sys.path.insert(0,parentdir) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from cipher.caesar import *\n",
+ "from cipher.affine import *\n",
+ "from cipher.keyword_cipher import *\n",
+ "from cipher.column_transposition import *\n",
+ "from cipher.vigenere import *\n",
+ "from support.text_prettify import *\n",
+ "from support.utilities import *\n",
+ "from support.plot_frequency_histogram import *"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "challenge_number = 5\n",
+ "plaintext_a_filename = f'{challenge_number}a.plaintext'\n",
+ "plaintext_b_filename = f'{challenge_number}b.plaintext'\n",
+ "ciphertext_a_filename = f'{challenge_number}a.ciphertext'\n",
+ "ciphertext_b_filename = f'{challenge_number}b.ciphertext'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ca = open(ciphertext_a_filename).read()\n",
+ "cb = open(ciphertext_b_filename).read()\n",
+ "sca = sanitise(ca)\n",
+ "pca = letters(ca)\n",
+ "pta = depunctuate(ca)\n",
+ "\n",
+ "scb = sanitise(cb)\n",
+ "pcb = letters(cb)\n",
+ "ptb = depunctuate(cb)\n",
+ "\n",
+ "rcb = cat(reversed(cb))\n",
+ "rscb = sanitise(rcb)\n",
+ "ptrb = depunctuate(rcb)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 62,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('solar', <KeywordWrapAlphabet.from_last: 2>, -2436.5996155834796)"
+ ]
+ },
+ "execution_count": 62,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(key_a, wrap_a), score_a = keyword_break_mp(sca)\n",
+ "key_a, wrap_a, score_a"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 63,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "harry mike has turned out to be really useful following his report to you about the apollo xine arm\n",
+ "is she has turned up a number of other computer reports hinting at possible sabotage attempts on\n",
+ "viii through xii some of them we already knew about the guidance problems with apollo x and the\n",
+ "programme alarms and descent trajectory problems on xi but he also showed me some files from the\n",
+ "building and maintenance logs for the future apollo fleet and pointed out some worrying lapses in\n",
+ "particular there is a gap in the records of the apollo xiii service modules owe are running a few\n",
+ "checks before assembly to make sure everything is okay before launch my first instinct was to place\n",
+ "everything on hold while we tracked down the saboteur but the whole building launch process is a\n",
+ "fine tuned machine and i am worried that if we disrupt it then we might cause more problems in\n",
+ "particular it will be easier to detect unexpected behaviour if we know exactly what to expect mike\n",
+ "is really worried that the soviets could have infiltrated the program he has never for given them\n",
+ "for the death of his son who was shot down by a mig over the korean peninsula i am hoping that his\n",
+ "grief will drive him to help us get to the bottom of this mystery for now we have another problem my\n",
+ "team at langley were tipped off by a journalist at the newyork post about an encrypted letter sent\n",
+ "to the newsdesk there it came with a cover note which said that the cipher key would be published in\n",
+ "the wanted ads but there area lot of those spread over hundreds of newspapers and the editor didnt\n",
+ "want to devote hours of staff time to tracking down the advert i think he assumed it was just\n",
+ "another crackpot attention seeker but justin case he asked the journalist to try breaking the cipher\n",
+ "herself she recognised it as avi genere cipher but it came with a little twist that she could not\n",
+ "figure out so she sent it to someone she knew in the cia once they cracked it they realised what it\n",
+ "was and sent it on to me the letter contains details of some of the events we have been\n",
+ "investigating and blames the soviets for them it would have been dynamite if it had been published\n",
+ "so it is just as well we were able to stop it at source the journalist was persuaded to tell her\n",
+ "boss that the cipher couldnt be cracked but in exchange we owe her an exclusive at the end of all of\n",
+ "this all the best meg\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(lcat(tpack(segment(keyword_decipher(sca, key_a, wrap_a)))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2373"
+ ]
+ },
+ "execution_count": 42,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_a_filename, 'w').write(lcat(tpack(segment(keyword_decipher(sca, key_a, wrap_a)))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 64,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "zodiac \n",
+ "\n",
+ "totheeditorofthenewyorkposttheheadlineofthisstorywritesitselfthesovietshaveinfiltratedourspaceagencynasaandhaveactivelyembarkedonaprogrammeofsabotageaimedatkillingourastronautsanddestroyingourmissionnotcontentwithsupportingwaracrossthefareastandfomentingrevolutionacrosstheamericastheyarenowcampedinourbackyardincubaandhavetaunteduswiththeirownspaceprogrammenowtheyhavelaunchedanattackontheheartofourcountryinanattempttodestroyourmoraleandtoreasserttheirdominanceinspacenopartofthelunarprogrammehasbeenunaffectedbytheiragentsthereareconstantleaksofourtechnologytotheengineersatbaikonurandourplansarelaidbaretoaidtheussrinitseffortstoovertakeusourbraveastronautshavebeenrepeatedlyplacedinharmswayanditisonlybecauseoftheeffectivenessofoursecurityagenciesandthebraveryandskillofourastronautsthatnoonehasbeenkilledinspacesofaritisonlyamatteroftimebeforeourenemiessucceedourpoliticalmastersdonotwantyoutoknowthattheapolloxlunarmoduleguidanceprogrammewascorruptedbysovietagentsorthattheapolloxiastronautswerealmostkilledbyacollisionwiththeirownservicemoduleastheyreenteredtheearthsatmospherethesebraveastronautscouldhavebeenkilledbytheactionsofsovietoperatorswhohadinfiltratedtheprogrammingandengineeringteamsourpoliticianswantyoutothinkthatapolloxiiwasstruckbylightningduringitslaunchandthatitwasthisthattookoutthecontrolcircuitrybutaskyourselfwhywouldamachineasadvancedasthesaturnvbevulnerabletoanaturalphenomenonascommonaslightningonthefloridapeninsulaandhowlikelyisittohavebeenstrucktwiceclearlysomeonesetouttosabotagethislaunchjustastheytriedtosabotageboththeapolloxreconnaissanceandtheapolloximoonlandingandreentrythesearepowerfulenemiesabletostrikeatanyaspectoftheapolloprogrammeandonlyastrongresponsefromourgovernmenthasanyhopeofstoppingthemforthesakeofourastronautsandofournationalprideiurgethepresidenttothreatenthestrongestpossibleretaliationiffurtherattacksarelaunchedagainstus\n"
+ ]
+ }
+ ],
+ "source": [
+ "k_a, score_a = vigenere_frequency_break(rscb)\n",
+ "print(k_a, '\\n')\n",
+ "rpb = vigenere_decipher(rscb, k_a)\n",
+ "print(rpb)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "To the editor of the New York Post:\n",
+ "\n",
+ "The headline of this story writes itself: The Soviets have infiltrated our space agency NASA and have actively embarked on a programme of sabotage, aimed at killing our astronauts and destroying our mission. Not content with supporting war across the Far East and fomenting revolution across the Americas, they are now camped in our backyard in Cuba and have taunted us with their own space programme. Now they have launched an attack on the heart of our country in an attempt to destroy our morale and to reassert their dominance in space.\n",
+ "\n",
+ "No part of the lunar programme has been unaffected by their agents. There are constant leaks of our technology to the engineers at Baikonur, and our plans are laid bare to aid the USSR in its efforts to overtake us. Our brave astronauts have been repeatedly placed in harm’s way and it is only because of the effectiveness of our security agencies and the bravery and skill of our astronauts that no one has been killed in space so far. It is only a matter of time before our enemies succeed.\n",
+ "\n",
+ "Our political masters do not want you to know that the Apollo X lunar module guidance programme was corrupted by Soviet agents or that the Apollo XI astronauts were almost killed by a collision with their own service module as they re-entered the earth’s atmosphere. These brave astronauts could have been killed by the actions of Soviet operators who had infiltrated the programming and engineering teams. Our politicians want you to think that Apollo XII was struck by lightning during its launch and that it was this that took out the control circuitry. But ask yourself, why would a machine as advanced as the Saturn V be vulnerable to a natural phenomenon as common as lightning on the Florida Peninsula? And how likely is it to have been struck twice? Clearly someone set out to sabotage this launch just as they tried to sabotage both the Apollo X reconnaissance and the Apollo XI moon landing and re-entry.\n",
+ "\n",
+ "These are powerful enemies able to strike at any aspect of the Apollo programme and only a strong response from our government has any hope of stopping them.\n",
+ "\n",
+ "For the sake of our astronauts and of our national pride I urge the President to threaten the strongest possible retaliation if further attacks are launched against us.\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(repunctuate(rpb, ptrb))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2317"
+ ]
+ },
+ "execution_count": 58,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_b_filename, 'w').write(repunctuate(rpb, ptrb))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.7.4"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
--- /dev/null
+harry mike has turned out to be really useful following his report to you about the apollo xine arm
+is she has turned up a number of other computer reports hinting at possible sabotage attempts on
+viii through xii some of them we already knew about the guidance problems with apollo x and the
+programme alarms and descent trajectory problems on xi but he also showed me some files from the
+building and maintenance logs for the future apollo fleet and pointed out some worrying lapses in
+particular there is a gap in the records of the apollo xiii service modules owe are running a few
+checks before assembly to make sure everything is okay before launch my first instinct was to place
+everything on hold while we tracked down the saboteur but the whole building launch process is a
+fine tuned machine and i am worried that if we disrupt it then we might cause more problems in
+particular it will be easier to detect unexpected behaviour if we know exactly what to expect mike
+is really worried that the soviets could have infiltrated the program he has never for given them
+for the death of his son who was shot down by a mig over the korean peninsula i am hoping that his
+grief will drive him to help us get to the bottom of this mystery for now we have another problem my
+team at langley were tipped off by a journalist at the newyork post about an encrypted letter sent
+to the newsdesk there it came with a cover note which said that the cipher key would be published in
+the wanted ads but there area lot of those spread over hundreds of newspapers and the editor didnt
+want to devote hours of staff time to tracking down the advert i think he assumed it was just
+another crackpot attention seeker but justin case he asked the journalist to try breaking the cipher
+herself she recognised it as avi genere cipher but it came with a little twist that she could not
+figure out so she sent it to someone she knew in the cia once they cracked it they realised what it
+was and sent it on to me the letter contains details of some of the events we have been
+investigating and blames the soviets for them it would have been dynamite if it had been published
+so it is just as well we were able to stop it at source the journalist was persuaded to tell her
+boss that the cipher couldnt be cracked but in exchange we owe her an exclusive at the end of all of
+this all the best meg
\ No newline at end of file