{ "cells": [ { "cell_type": "code", "execution_count": 220, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "from szyfrow.keyword_cipher import *\n", "from szyfrow.column_transposition import *\n", "from szyfrow.vigenere import *\n", "from szyfrow.support.text_prettify import *\n", "from szyfrow.polybius import *\n", "from szyfrow.caesar import *\n", "import collections\n", "from itertools import *" ] }, { "cell_type": "code", "execution_count": 150, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "challenge_number = 7\n", "plaintext_a_filename = f'plaintext.{challenge_number}a.txt'\n", "plaintext_b_filename = f'plaintext.{challenge_number}b.txt'\n", "ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt'\n", "ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt'" ] }, { "cell_type": "code", "execution_count": 151, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ca = open(ciphertext_a_filename).read()\n", "sca = sanitise(ca)\n", "rsca = cat(reversed(sca))\n", "cb = open(ciphertext_b_filename).read()\n", "scb = cat(c for c in cb if c in (string.ascii_letters + '#+'))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "triangle \n", "\n", "theattacheddocumentwasinterceptedbyharrysteamwhohavemanagedtoplantabugonthecommunicationlinesoutoftirpitzuferourcryptanalystshaveexaminedtheciphertextandthecasefilesandbelievethatitmayberelatedtothewheatstoneclockcipherdeputyheadofthedivisionhaswrittenabossguidetotheseciphermachinesandwehaveaddedthattothecasefilesharrysteamalsorecoveredascrapofburntpaperfromtheabwehrhqwastewhichcarriesthefollowingmessagewhichwethinkmightbepartoftheplaintexttentialstopthetripwireoptionisalsodeprecatedsinceitismorelikelythattheexplthenavyreportedthatadutchfishingvesselwasimpoundedbythenaziauthoritiesinbremerhaventhecrewweredetainedandnegotiationsareunderwaybetweenthedutchandgermanauthoritiestotrytogetthefishermenandtheirvesselbackbutinthemeantimernpatrolswillwatchoutfortheboatincaseitisinvolvedintheoperationtheairministryhavebeenbriefedonourfindingssofarandhaveemphasisedtheimportanceofprotectingtherdfsystemwhichiamtoldtheycallchainhomevkissympatheticbutthethreeofusarestillworriedaboutthenewagentsembeddedinlondonandwearenotsurehowmuchofathreattheyposeitiscrucialthatwebreaktheattachedciphertextasfastaspossiblesowecanputeffectivecountermeasuresinplaceitistemptingtoarrestalltwentythreespyclistsandaskthemdirectlybutwithoutrevealingtheextentofoursurveillanceandcodebreakingabilityitwillnotbepossibletoprovethattheyhavebrokenthelawsowewouldnotbeabletodetainordeportthemitwouldusuallybebettertowatchandwaitbuttheairministryfeelsthattherisktoourairdefenceistoogreatsoweneedtoactfastifweknewexactlywhenandwheretheyintendedtoattackchainhomethenwemightbeabletoincreasesecuritytopreventitbutagainweriskrevealingourcounterintelligencecapabilitiesharrysuggestedthatwecouldobscureourtracksbyfakingavisitbydignitariestothetargetsitesasacoverstoryforincreasedsecuritybutwecantmaintaintheincreaseforlongwithoutraisingsuspicionsoitiscrucialtodeterminetheirplanswhatevertheabwehrareintendingtheywontwanttheiragentstofallintoourhandsespeciallyafterademolitionsincethatwouldgiveustheexcuseweneedtoarrestthemitwouldbegoodtoknowwhattheyhaveinmindfortheirexfiltrationthingsareveryfinelybalancedifweacttoosoonwegiveawayourcrucialadvantageintheinterceptwarifweacttoolateourenemiescouldseriouslydamageourairdefencecapabilityitisclearthatthingsarecomingtoaheadanditiscrucialthatwecracktheclockcipherassoonaspossiblethefateofthecountryliesinyourhandspearl\n" ] } ], "source": [ "key_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams)\n", "print(key_a, '\\n')\n", "pa = vigenere_decipher(sca, key_a)\n", "print(pa)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the attached document was intercepted by harry steam who have managed to plant a bug on the\n", "communication lines out of tirpitz ufer our crypt analysts have examined the ciphertext and the case\n", "files and believe that it maybe related to the wheatstone clock cipher deputy head of the division\n", "has written a boss guide to these cipher machines and we have added that to the case files harry\n", "steam also recovered a scrap of burnt paper from the abwehr hq waste which carries the following\n", "message which we think might be part of the plaintext tential stop the tripwire option is also\n", "deprecated since it is more likely that the expl the navy reported that a dutch fishing vessel was\n", "impounded by the nazi authorities in bremerhaven the crew were detained and negotiations are\n", "underway between the dutch and german authorities to try to get the fishermen and their vessel back\n", "but in the meantime rn patrols will watch out for the boat in case it is involved in the operation\n", "the air ministry have been briefed on our findings so far and have emphasised the importance of\n", "protecting the rdf system which i am told they call chain home vk is sympathetic but the three of us\n", "are still worried about the new agents embedded in london and we are not sure how much of a threat\n", "they pose it is crucial that we break the attached ciphertext as fast as possible so we can put\n", "effective countermeasures in place it is tempting to arrest all twenty three spy c lists and ask\n", "them directly but without revealing the extent of our surveillance and code breaking ability it will\n", "not be possible to prove that they have broken the law so we would not be able to detain or deport\n", "them it would usually be better to watch and wait but the air ministry feels that the risk to our\n", "air defence is too great so we need to act fast if we knew exactly when and where they intended to\n", "attack chain home then we might be able to increase security to prevent it but again we risk\n", "revealing our counterintelligence capabilities harry suggested that we could obscure our tracks by\n", "faking a visit by dignitaries to the target sites as a coverstory for increased security but we cant\n", "maintain the increase for long without raising suspicion so it is crucial to determine their plans\n", "whatever the abwehr are intending they wont want their agents to fall into our hands especially\n", "after a demolition since that would give us the excuse we need to arrest them it would be good to\n", "know what they have in mind for their exfiltration things are very finely balanced if we act too\n", "soon we giveaway our crucial advantage in the intercept war if we act too late our enemies could\n", "seriously damage our air defence capability it is clear that things are coming to ahead and it is\n", "crucial that we crack the clock cipher as soon as possible the fate of the country lies in your\n", "hands pearl\n" ] } ], "source": [ "pa = prettify(vigenere_decipher(sca, key_a))\n", "print(pa)" ] }, { "cell_type": "code", "execution_count": 236, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "2843" ] }, "execution_count": 236, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_a_filename, 'w').write(pa)" ] }, { "cell_type": "code", "execution_count": 152, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'tentialstopthetripwireoptionisalsodeprecatedsinceitismorelikelythattheexpl'" ] }, "execution_count": 152, "metadata": {}, "output_type": "execute_result" } ], "source": [ "crib = sanitise(\"tential stop the tripwire option is also deprecated since it is more likely that the expl\")\n", "crib" ] }, { "cell_type": "code", "execution_count": 153, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'#+ABCDEFGHIJKLMNOPQRSTUVWXYZ'" ] }, "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cat(sorted(set(scb)))" ] }, { "cell_type": "code", "execution_count": 192, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "p_alpha = string.ascii_lowercase\n", "c_alpha = string.ascii_uppercase + '#+'" ] }, { "cell_type": "code", "execution_count": 193, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))" ] }, { "cell_type": "code", "execution_count": 197, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def decipher_letter(cipher_letter, stream):\n", " stream = dropwhile(lambda p: p[1] != cipher_letter, stream)\n", " stream, temp_stream = tee(stream, 2)\n", " (plain_letter, c) = list(islice(temp_stream, 1))[0]\n", " return (plain_letter, islice(stream, 1, None))" ] }, { "cell_type": "code", "execution_count": 198, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def encipher_letter(plain_letter, stream):\n", " stream = dropwhile(lambda p: p[0] != plain_letter, stream)\n", " stream, temp_stream = tee(stream, 2)\n", " (p, cipher_letter) = list(islice(temp_stream, 1))[0]\n", " return (cipher_letter, islice(stream, 1, None))" ] }, { "cell_type": "code", "execution_count": 199, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "('b', 'd', 'z', 'b', 'd', 'f', 'h')" ] }, "execution_count": 199, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))\n", "p1, s1 = decipher_letter('B', cipherstream)\n", "p2, s2 = decipher_letter('D', s1)\n", "p3, s3 = decipher_letter('Z', s2)\n", "p4, s4 = decipher_letter('+', s3)\n", "p5, s5 = decipher_letter('B', s4)\n", "p6, s6 = decipher_letter('D', s5)\n", "p7, s7 = decipher_letter('D', s6)\n", "\n", "p1, p2, p3, p4, p5, p6, p7" ] }, { "cell_type": "code", "execution_count": 200, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "('b', 'd')" ] }, "execution_count": 200, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))\n", "p1, s1 = decipher_letter('B', cipherstream)\n", "p2, s2 = decipher_letter('B', s1)\n", "\n", "p1, p2" ] }, { "cell_type": "code", "execution_count": 201, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def decipher_message(ciphertext, stream):\n", " plaintext = ''\n", " for l in ciphertext:\n", " p, stream = decipher_letter(l, stream)\n", " plaintext += p\n", " return plaintext, stream " ] }, { "cell_type": "code", "execution_count": 202, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def encipher_message(plaintext, stream):\n", " ciphertext = ''\n", " for l in plaintext:\n", " c, stream = encipher_letter(l, stream)\n", " ciphertext += c\n", " return ciphertext, stream " ] }, { "cell_type": "code", "execution_count": 203, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'vxnozddfahharfgoxiyg'" ] }, "execution_count": 203, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))\n", "pb, s = decipher_message(scb[:20], cipherstream)\n", "pb" ] }, { "cell_type": "code", "execution_count": 204, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'TCLREWFMNGHLZUHDU+GS+MWX+OURKUALSM+ALN#WSJUREUZMOSBQ#SUXIPKMELYRDWNLZUSJ+V'" ] }, "execution_count": 204, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))\n", "c_gen, s = encipher_message(crib, cipherstream)\n", "c_gen" ] }, { "cell_type": "code", "execution_count": 205, "metadata": { "Collapsed": "false", "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "[(19, 'T'),\n", " (2, 'C'),\n", " (11, 'L'),\n", " (17, 'R'),\n", " (4, 'E'),\n", " (22, 'W'),\n", " (5, 'F'),\n", " (12, 'M'),\n", " (13, 'N'),\n", " (6, 'G'),\n", " (7, 'H'),\n", " (11, 'L'),\n", " (25, 'Z'),\n", " (20, 'U'),\n", " (7, 'H'),\n", " (3, 'D'),\n", " (20, 'U'),\n", " (27, '+'),\n", " (6, 'G'),\n", " (18, 'S'),\n", " (27, '+'),\n", " (12, 'M'),\n", " (22, 'W'),\n", " (23, 'X'),\n", " (27, '+'),\n", " (14, 'O'),\n", " (20, 'U'),\n", " (17, 'R'),\n", " (10, 'K'),\n", " (20, 'U'),\n", " (0, 'A'),\n", " (11, 'L'),\n", " (18, 'S'),\n", " (12, 'M'),\n", " (27, '+'),\n", " (0, 'A'),\n", " (11, 'L'),\n", " (13, 'N'),\n", " (26, '#'),\n", " (22, 'W'),\n", " (18, 'S'),\n", " (9, 'J'),\n", " (20, 'U'),\n", " (17, 'R'),\n", " (4, 'E'),\n", " (20, 'U'),\n", " (25, 'Z'),\n", " (12, 'M'),\n", " (14, 'O'),\n", " (18, 'S'),\n", " (1, 'B'),\n", " (16, 'Q'),\n", " (26, '#'),\n", " (18, 'S'),\n", " (20, 'U'),\n", " (23, 'X'),\n", " (8, 'I'),\n", " (15, 'P'),\n", " (10, 'K'),\n", " (12, 'M'),\n", " (4, 'E'),\n", " (11, 'L'),\n", " (24, 'Y'),\n", " (17, 'R'),\n", " (3, 'D'),\n", " (22, 'W'),\n", " (13, 'N'),\n", " (11, 'L'),\n", " (25, 'Z'),\n", " (20, 'U'),\n", " (18, 'S'),\n", " (9, 'J'),\n", " (27, '+'),\n", " (21, 'V')]" ] }, "execution_count": 205, "metadata": {}, "output_type": "execute_result" } ], "source": [ "co = [(c_alpha.find(l), l) for i, l in enumerate(c_gen)]\n", "co" ] }, { "cell_type": "code", "execution_count": 206, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'VXLKVZXZSZXODRQYFQEM'" ] }, "execution_count": 206, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scb[:20]" ] }, { "cell_type": "code", "execution_count": 207, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def offsets(ciphertext):\n", " mappings = {}\n", " letters_seen = 0\n", " offsets = []\n", " for l in ciphertext:\n", " if l not in mappings:\n", " mappings[l] = letters_seen\n", " letters_seen += 1\n", " offsets.append(mappings[l])\n", " return offsets" ] }, { "cell_type": "code", "execution_count": 208, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "74" ] }, "execution_count": 208, "metadata": {}, "output_type": "execute_result" } ], "source": [ "crib_offsets = offsets(c_gen)\n", "len(crib_offsets)" ] }, { "cell_type": "code", "execution_count": 209, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def plausible_samples(generated_text):\n", " plausible_samples = {}\n", " for i in range(len(scb)):\n", " sample = scb[i:(i + len(crib))]\n", " if len(sample) == len(crib):\n", " ofs = offsets(sample)\n", " if ofs == crib_offsets:\n", " plausible_samples[i] = sample\n", " return plausible_samples" ] }, { "cell_type": "code", "execution_count": 210, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'TCLREWFMNGHLZUHDU+GS+MWX+OURKUALSM+ALN#WSJUREUZMOSBQ#SUXIPKMELYRDWNLZUSJ+V'" ] }, "execution_count": 210, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c_gen" ] }, { "cell_type": "code", "execution_count": 211, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "def plausible_mapping(crib_output):\n", " mapping = {}\n", " for n, l in crib_output:\n", " if n in mapping:\n", " if mapping[n] != l:\n", " return {}\n", " else:\n", " mapping[n] = l\n", " return mapping" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 212, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "{19: 'T', 2: 'C', 11: 'L'}" ] }, "execution_count": 212, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plausible_mapping(co[:3])" ] }, { "cell_type": "code", "execution_count": 213, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "{0: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 1: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 2: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 3: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 4: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 5: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 6: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 7: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 8: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 9: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 10: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 11: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 12: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 13: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 14: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 15: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 16: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 17: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 18: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 19: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 20: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 21: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 22: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 23: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 24: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'},\n", " 25: {1026: 'KW+ASVCNDJM+BPM#PLJHLNVZLUPAXPR+HNLR+DIVHGPASPBNUHFOIHPZTYXNS+QA#VD+BPHGLE'}}" ] }, "execution_count": 213, "metadata": {}, "output_type": "execute_result" } ], "source": [ "solutions = {}\n", "for i in range(26):\n", " cipherstream = zip(islice(cycle(p_alpha), i, None),\n", " cycle(c_alpha))\n", " c_gen, s = encipher_message(crib, cipherstream)\n", " solutions[i] = plausible_samples(c_gen)\n", "solutions" ] }, { "cell_type": "code", "execution_count": 225, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 225, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1026 % 26" ] }, { "cell_type": "code", "execution_count": 214, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'TCLREWFMNGHLZUHDU+GS+MWX+OURKUALSM+ALN#WSJUREUZMOSBQ#SUXIPKMELYRDWNLZUSJ+V'" ] }, "execution_count": 214, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(c_alpha))\n", "c_gen0, s = encipher_message(crib, cipherstream)\n", "c_gen0" ] }, { "cell_type": "code", "execution_count": 215, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'ABCDEFGHIJKLMNOPQRSTUVWXYZ#+'" ] }, "execution_count": 215, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c_alpha" ] }, { "cell_type": "code", "execution_count": 216, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "{19: 'K',\n", " 2: 'W',\n", " 11: '+',\n", " 17: 'A',\n", " 4: 'S',\n", " 22: 'V',\n", " 5: 'C',\n", " 12: 'N',\n", " 13: 'D',\n", " 6: 'J',\n", " 7: 'M',\n", " 25: 'B',\n", " 20: 'P',\n", " 3: '#',\n", " 27: 'L',\n", " 18: 'H',\n", " 23: 'Z',\n", " 14: 'U',\n", " 10: 'X',\n", " 0: 'R',\n", " 26: 'I',\n", " 9: 'G',\n", " 1: 'F',\n", " 16: 'O',\n", " 8: 'T',\n", " 15: 'Y',\n", " 24: 'Q',\n", " 21: 'E'}" ] }, "execution_count": 216, "metadata": {}, "output_type": "execute_result" } ], "source": [ "soln = solutions[0][1026]\n", "alpha_pos = [c_alpha.find(c) for c in c_gen0]\n", "c_alpha_mapped = {}\n", "\n", "for p, c in zip(alpha_pos, soln):\n", " c_alpha_mapped[p] = c\n", "c_alpha_mapped" ] }, { "cell_type": "code", "execution_count": 217, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'RFW#SCJMTGX+NDUYOAHKPEVZQBIL'" ] }, "execution_count": 217, "metadata": {}, "output_type": "execute_result" } ], "source": [ "discovered_c_alpha = cat(c_alpha_mapped[i] if i in c_alpha_mapped else ' ' for i in range(28))\n", "discovered_c_alpha" ] }, { "cell_type": "code", "execution_count": 218, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "28" ] }, "execution_count": 218, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(c_alpha_mapped)" ] }, { "cell_type": "code", "execution_count": 226, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'NDUYOAHKPEVZQBILRFW#SCJMTGX+'" ] }, "execution_count": 226, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rotated_c_alpha = discovered_c_alpha[12:] + discovered_c_alpha[:12]\n", "rotated_c_alpha" ] }, { "cell_type": "code", "execution_count": 219, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'wmdxabqdmfuazomftqpdmxfaiqdtmenqqzmbbdahqpmzpagdmsqzfemdqmddmzsuzsfabdahupqkagiuftftqfzfkagdqcgqefqpuzkagdxmefyqeemsqefabftueiuxxnqetubbqpazmpgfotruetuzshqeeqxituotiuxxxmzpmfftqymdetqearraxpxqustmffiamyazrdupmkpqoqynqdfqzftefabftqkiuxxeuszmxftqudmdduhmxnkrxmetuzsftqudzmhusmfuazxustfeuzyadeqoapqfaebqxxagfftqiadprxmfmzpkagiuxxdqbxkfkdqefaburkagnqxuqhqftmfkagmdqnquzsimfotqpftqzmnmzpazftqdqzpqlhagemzpfdkmsmuzmfuzfqdhmxearfiapmkeftdqqpmkeruhqpmkemzpeqhqzpmkeefabpazafmffqybffaymwqoazfmofiuftftqnamfadufeodqiuzmzkaftqdimkefabftqqjbxaeuhqueefmnxqngfetagxpnqfdqmfqpiuftomdqefabftqrgeqemdqftqyaefdqoqzfbdapgofaragddqeqmdotmzpfqotzaxaskpuhueuazmzpomddkfdubxqfdussqdeefabftqktmhqmfuyqdoudogufituotymknqeqfradmzkbqduaprdayftdqqyuzgfqefaeqhqzfqqztagdeefabftqkomzmxeanqfdussqdqpnkmfdubiudqmeeqynxkadftqrgeqyqotmzueyomznqdqbxmoqpiuftmtmzpsdqzmpqyqotmzueyefabeuzoqftqeqotmdsqetmhqnqqzetmbqpradpqyaxufuazgeqiqpazafdqoayyqzpgeuzsftqeqpqhuoqeuzoaynmfeuzoqkagtmhqzaoqdfmuzfkftmfftqotmdsqiuxxxmzpuzmzaduqzfmfuazftmfiuxxymjuyuequfepqefdgofuhqbafqzfumxefabftqfdubiudqabfuazuemxeapqbdqomfqpeuzoqufueyadqxuwqxkftmfftqqjbxaeuhqeiuxxnqpueoahqdqpurftqkmdqmffmotqpfaegotmfdussqdmzpyadqahqdufiagxpnqpurruogxffaoaadpuzmfqftqotmdsqegeuzsegotmpqhuoqefabftqotmdsqeftqyeqxhqemdqeymxxngfftqsqayqfdkarftqbmowmsqiuxxraogeftqnxmefeaufueuybqdmfuhqftmfkaguzefmxxftqeqotmdsqeuzmooadpmzoqiuftftqymzgrmofgdqdeuzefdgofuazeefabuzadpqdfaymjuyueqftqpmymsqfaftqfaiqdeftqqzsuzqqdedqoayyqzpftmfkageqfotmdsqeazftdqqarftqxqsearqmotfaiqdiuftotmdsqefiamzpftdqqeqffaqjbxapquzeqcgqzoqmrfqdotmdsqazqefabeqfmzmppufuazmxpqxmkarftudfkeqoazperadotmdsqfiamzpazqyuzgfqfiqzfkruhqeqoazperadotmdsqftdqqefabmeftqrudefxqsngowxqeufiuxxefdqeeftqrdmyqeaftmfftqetaowimhqarftqeqoazpotmdsqiuxxpuefadfftqegbbadfuzsyqynqdeefabiuftftqftudpqjbxaeuazftqrdmyqetagxpngowxqdqegxfuzsuzftqfafmxpqefdgofuazarftqfaiqdengfftueeqcgqzoqiuxxymwqeufqoxqmdmzoqmzpdqoazefdgofuaztmdpqdfamooaybxuetefabftqpqxmkiuftotmdsqftdqqmxeauzodqmeqeftqxuwqxutaapftmfeaxpuqdeiuxxtmhqmdduhqpazeufquzfuyqfanqomgstfuzftqftudpnxmefuzodqmeuzsoazrgeuazmzpxaeearyadmxqefaburufuebaeeunxqfaoxuynftqfaiqduzmphmzoqarftqpqyaxufuazfasqfyadqpqfmuxqpuymsqearftqmqdumxmzpmybxuruqdoudogufdkftqzftueetagxpnqmffqybfqptaiqhqdurftqdquemzksgmdpbdqeqzoqftqzzadueweetagxpnqfmwqzuzftuedqsmdpefabiqygefxqmhquffakagfapqfqdyuzqftqyaefqrrqofuhqfmdsqferadftqabqdmfuazngfftqpqyaxufuazygeftmbbqzeuygxfmzqagexkmfmxxeufqeradfiadqmeazeefabrudefuzadpqdfabdqhqzfagdqzqykrdaypuedgbfuzsftqabqdmfuazazoqftqkdqmxueqitmfuetmbbqzuzsefabeqoazpiqygefxqmhqzapagnfftmfftueimemzmofarimdefabftqdquemduewftmfftqndufuetsahqdzyqzfymkfdkfadqmotmzmooayyapmfuaziuftftqrgtdqdpuhupuzsftqiadxpnqfiqqzftqudpkuzsqybudqmzpagdevgefmeufuenadzefabftqazxkimkfaqzegdqftmfiqomzfdgxkegbbxmzfftqyuefapdmiftqyuzfamimdftqkomzzafiuzmzpftuebdavqofiuxxnqftqbdahaomfuazftmfqzegdqeftmfftueiuxxtmbbqzefabftqbxmzzuzspuhueuaztmepqfqdyuzqpftmfvmzgmdkrudefiuxxnqftqabfuymxzustfradftqmffmowmeufoauzoupqeiuftmzqiyaazefabftqkegssqefftmfkagebxufuzfafiafqmyefamffmowftqqpygzpefomuefadmzpomzqipazeufqeabqzuzsmoaddupadmxazsftqftmyqeradagdradftoayuzsmuddmupeefabftqegbbadffqmyeetagxpeqfgbxaawagfbaefemfftqfmdsqfeuzmphmzoqarftqmffmoweaftmfkagomzyazufadsgmdpyahqyqzfemzpymwqmruzmxmeeqeeyqzfarftqeqogdufkefabraxxaiuzsftqabqdmfuazftqemnafmsqfqmyeetagxpdqzpqlhagefasqftqdiuftftqegbbadffqmyemfftqtayqarftqxaomxadfesdgbbqotuqruzeagftymxpazefabmgnamfiuxxefmzpnkfabuowkagmxxgbmfftdqqradfkeqhqzvmzgmdkeqoazpiuftmrmxxnmowdqzpqlhagearazqftudfqqzazftqftudfqqzftitqzftqeqmdotetagxptmhqpuqppaizefabkagiuxxzqqpfasmuzmooqeefamnamfombmnxqaromddkuzskagmxxagffayqqfufefabftqdqmdqhqdkymzkruetuzshqeeqxeuzftuezqustnagdtaapmzpiqdqoayyqzpefqmxuzsazqmrfqdftqabqdmfuazefabufyustfrqqxxqeeeqogdqftmfanfmuzuzsazquzmphmzoqtaiqhqdiqygefpaqhqdkftuzsiqomzfabdqhqzfegebuouazuzmphmzoqarftqabqdmfuazefaburftueyueeuazegooqqpeftqzufiuxxnqazxkmymffqdarpmkenqradqftqimdnqsuzemzpkagdftdqqoaydmpqeuzxazpaziuxxbxmkmodgoumxdaxquzoaadpuzmfuzsagduzfqxxusqzoqqrradfenqtuzpqzqykxuzqeefabiqtmhqnqqzimfotuzsmzpxuefqzuzsomdqrgxxkradeuszeftmfftqabqdmfuazoagxptmhqnqqzoaybdayueqpmzpmemdqegxfarftaeqqzcguduqeiqtmhqpueoahqdqpmzqifabeqodqfmsqzokwzaizazxknkftqmodazkynaeeefabiqtmhqnqqzgzmnxqfauzruxfdmfqftuesdagbngfufuewzaizftmfftqxqmpqdueeayqazqiuftftquzufumxtmzpftmfftqkmdqfmwuzsftqxqmpazeuszmxeuzfqxxusqzoqefabftqtqmparftqoagzfqduzfqxxusqzoqndmzotgeqeftqoapqzmyqbqmdxmzpiqiuxxnqymwuzsqhqdkqrradffapueoahqdtqdupqzfufkefabituxqftqpqoxmdmfuazarimdmzpftqpqefdgofuazarftqdprekefqymdqftqoqzfdmxsamxearftueabqdmfuazftqxazpazfdumzsxqiuxxnqwqkfaqzegduzsmrxaiartustcgmxufkuzfqxxusqzoqfauzradyagdnmffxqbxmzeefabiuftagfftqudoayygzuomfuazeiqiuxxnqgzmnxqfayazufadndufuetbxmzebxmouzssqdymzxuhqemfgzzqoqeemdkduewefaburftqdquemzkotmzoqftmfyqynqdearkagdsdagboagxpnqombfgdqpmzpuzfqddasmfqpftqzkagetagxpmnmzpazftqemnafmsqabqdmfuazmzpdqfgdzfafudbuflgrqdefabbdafqofuzsftqupqzfufkarftqfdumzsxquearrmdsdqmfqdxazsfqdyuybadfmzoqfageefabiqomzruzpaftqdimkefabdahawqftqimdngfiqiagxpruzpufyadqpurruogxffaqzegdqftmfiqomziuzufiuftagfmzqfiadwarmsqzfeuzftqombufmxefabftqyueeuaziuxxnqdqsmdpqpmemegooqeeazxkuriqomzsgmdmzfqqftqudemrqfkefabfauzodqmeqftqeqogdufkarftqxazpazfdumzsxqufueodgoumxftmfftqoxaowoubtqdpqhuoqmzpftqmeeaoumfqpoapqnaawedqmotagdxazpazmsqzfeefabftqpqhuoqomzzafnqmxxaiqpfarmxxuzfaqzqyktmzpemzpftueygefnqftqfabbduadufkefaburkagmdqombfgdqpftqzftqoapqnaawoazfmuzuzsftqwqkefaftqoubtqdygefnqpqefdakqpefabufuebduzfqpazebqoumxbmbqdftmfetagxpqmeuxkpueeaxhqngfufomzmxeanquzsqefqpurzqoqeemdkefabitqzgeuzsftqymotuzqfmwqomdqfaqdmeqftqoubtqdmxbtmnqfmrfqdgeqmzpfapqxqfqftqwqkrdayftqoapqnaawfaqzegdqftmfzaazqgeqeftqemyqwqkfiuoqefabftueiuxxmxeadqpgoqftqduewarftqwqkqpoubtqdrmxxuzsuzfaqzqyktmzpeefaburombfgdqmbbqmdeuyyuzqzfftqzgeqazqarftqetmbqpotmdsqefapqefdakftqpqhuoqbdqrqdmnxkngdkuzsuffasqftqdiuftftqotmdsqfauzodqmeqftqpqefdgofuhqbaiqdmzpymwquftmdpqdfadqoazefdgofefabqhqdkazquzftqyahqyqzfiuxxnqbdmkuzsradkagdegooqeemzpkagdoagdmsqmzpoayyufyqzffaftqrmftqdxmzpiuxxnqbdmueqpradqhqdefabkagmdqmzuzebudmfuazfagemxxefabiuetuzskagxgowuzftqruzmxbtmeqarftqabqdmfuazefabkagdegzoxqiuxtqxy'" ] }, "execution_count": 219, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(discovered_c_alpha))\n", "c_gen, s = decipher_message(scb, cipherstream)\n", "c_gen" ] }, { "cell_type": "code", "execution_count": 221, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "(12, -7510.337448308099)" ] }, "execution_count": 221, "metadata": {}, "output_type": "execute_result" } ], "source": [ "caesar_break(c_gen)" ] }, { "cell_type": "code", "execution_count": 222, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'karloperationcathedraltowerhasbeenapprovedandouragentsarearrangingtoprovideyouwiththetntyourequestedinyourlastmessagestopthiswillbeshippedonadutchfishingvesselwhichwilllandatthemarshesoffoldleighattwoamonfridaydecembertenthstoptheywillsignaltheirarrivalbyflashingtheirnavigationlightsinmorsecodetospelloutthewordflatandyouwillreplytyrestopifyoubelievethatyouarebeingwatchedthenabandontherendezvousandtryagainatintervalsoftwodaysthreedaysfivedaysandsevendaysstopdonotattempttomakecontactwiththeboatoritscrewinanyotherwaystoptheexplosiveisstablebutshouldbetreatedwithcarestopthefusesarethemostrecentproductofourresearchandtechnologydivisionandcarrytripletriggersstoptheyhaveatimercircuitwhichmaybesetforanyperiodfromthreeminutestoseventeenhoursstoptheycanalsobetriggeredbyatripwireassemblyorthefusemechanismcanbereplacedwithahandgrenademechanismstopsincethesechargeshavebeenshapedfordemolitionusewedonotrecommendusingthesedevicesincombatsinceyouhavenocertaintythatthechargewilllandinanorientationthatwillmaximiseitsdestructivepotentialstopthetripwireoptionisalsodeprecatedsinceitismorelikelythattheexplosiveswillbediscoverediftheyareattachedtosuchatriggerandmoreoveritwouldbedifficulttocoordinatethechargesusingsuchadevicestopthechargesthemselvesaresmallbutthegeometryofthepackagewillfocustheblastsoitisimperativethatyouinstallthesechargesinaccordancewiththemanufacturersinstructionsstopinordertomaximisethedamagetothetowerstheengineersrecommendthatyousetchargesonthreeofthelegsofeachtowerwithchargestwoandthreesettoexplodeinsequenceafterchargeonestopsetanadditionaldelayofthirtysecondsforchargetwoandoneminutetwentyfivesecondsforchargethreestopasthefirstlegbucklesitwillstresstheframesothattheshockwaveofthesecondchargewilldistortthesupportingmembersstopwiththethirdexplosiontheframeshouldbuckleresultinginthetotaldestructionofthetowersbutthissequencewillmakesiteclearanceandreconstructionhardertoaccomplishstopthedelaywithchargethreealsoincreasesthelikelihoodthatsoldierswillhavearrivedonsiteintimetobecaughtinthethirdblastincreasingconfusionandlossofmoralestopifitispossibletoclimbthetowerinadvanceofthedemolitiontogetmoredetailedimagesoftheaerialandamplifiercircuitrythenthisshouldbeattemptedhoweverifthereisanyguardpresencethennorisksshouldbetakeninthisregardstopwemustleaveittoyoutodeterminethemosteffectivetargetsfortheoperationbutthedemolitionmusthappensimultaneouslyatallsitesfortworeasonsstopfirstinordertopreventourenemyfromdisruptingtheoperationoncetheyrealisewhatishappeningstopsecondwemustleavenodoubtthatthiswasanactofwarstopthereisariskthatthebritishgovernmentmaytrytoreachanaccommodationwiththefuhrerdividingtheworldbetweentheirdyingempireandoursjustasitisbornstoptheonlywaytoensurethatwecantrulysupplantthemistodrawthemintoawartheycannotwinandthisprojectwillbetheprovocationthatensuresthatthiswillhappenstoptheplanningdivisionhasdeterminedthatjanuaryfirstwillbetheoptimalnightfortheattackasitcoincideswithanewmoonstoptheysuggestthatyousplitintotwoteamstoattacktheedmundstcaistorandcanewdonsitesopeningacorridoralongthethamesforourforthcomingairraidsstopthesupportteamsshouldsetuplookoutpostsatthetargetsinadvanceoftheattacksothatyoucanmonitorguardmovementsandmakeafinalassessmentofthesecuritystopfollowingtheoperationthesabotageteamsshouldrendezvoustogetherwiththesupportteamsatthehomeofthelocalortsgruppechiefinsouthmaldonstopauboatwillstandbytopickyouallupatthreefortysevenjanuarysecondwithafallbackrendezvousofonethirteenonthethirteenthwhenthesearchshouldhavedieddownstopyouwillneedtogainaccesstoaboatcapableofcarryingyouallouttomeetitstopthereareverymanyfishingvesselsinthisneighbourhoodandwerecommendstealingoneaftertheoperationstopitmightfeellesssecurethatobtainingoneinadvancehoweverwemustdoeverythingwecantopreventsuspicioninadvanceoftheoperationstopifthismissionsucceedsthenitwillbeonlyamatterofdaysbeforethewarbeginsandyourthreecomradesinlondonwillplayacrucialroleincoordinatingourintelligenceeffortsbehindenemylinesstopwehavebeenwatchingandlisteningcarefullyforsignsthattheoperationcouldhavebeencompromisedandasaresultofthoseenquirieswehavediscoveredanewtopsecretagencyknownonlybytheacronymbossstopwehavebeenunabletoinfiltratethisgroupbutitisknownthattheleaderissomeonewiththeinitialhandthattheyaretakingtheleadonsignalsintelligencestoptheheadofthecounterintelligencebranchusesthecodenamepearlandwewillbemakingeveryefforttodiscoverheridentitystopwhilethedeclarationofwarandthedestructionoftherdfsystemarethecentralgoalsofthisoperationthelondontrianglewillbekeytoensuringaflowofhighqualityintelligencetoinformourbattleplansstopwithouttheircommunicationswewillbeunabletomonitorbritishplansplacinggermanlivesatunnecessaryriskstopifthereisanychancethatmembersofyourgroupcouldbecapturedandinterrogatedthenyoushouldabandonthesabotageoperationandreturntotirpitzuferstopprotectingtheidentityofthetriangleisoffargreaterlongtermimportancetousstopwecanfindotherwaystoprovokethewarbutwewouldfinditmoredifficulttoensurethatwecanwinitwithoutanetworkofagentsinthecapitalstopthemissionwillberegardedasasuccessonlyifwecanguaranteetheirsafetystoptoincreasethesecurityofthelondontriangleitiscrucialthattheclockcipherdeviceandtheassociatedcodebooksreachourlondonagentsstopthedevicecannotbeallowedtofallintoenemyhandsandthismustbethetopprioritystopifyouarecapturedthenthecodebookcontainingthekeystotheciphermustbedestroyedstopitisprintedonspecialpaperthatshouldeasilydissolvebutitcanalsobeingestedifnecessarystopwhenusingthemachinetakecaretoerasethecipheralphabetafteruseandtodeletethekeyfromthecodebooktoensurethatnooneusesthesamekeytwicestopthiswillalsoreducetheriskofthekeyedcipherfallingintoenemyhandsstopifcaptureappearsimminentthenuseoneoftheshapedchargestodestroythedevicepreferablyburyingittogetherwiththechargetoincreasethedestructivepowerandmakeithardertoreconstructstopeveryoneinthemovementwillbeprayingforyoursuccessandyourcourageandcommitmenttothefatherlandwillbepraisedforeverstopyouareaninspirationtousallstopwishingyouluckinthefinalphaseoftheoperationstopyoursunclewilhelm'" ] }, "execution_count": 222, "metadata": {}, "output_type": "execute_result" } ], "source": [ "caesar_decipher(c_gen, 12)" ] }, { "cell_type": "code", "execution_count": 229, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'karloperationcathedraltowerhasbeenapprovedandouragentsarearrangingtoprovideyouwiththetntyourequestedinyourlastmessagestopthiswillbeshippedonadutchfishingvesselwhichwilllandatthemarshesoffoldleighattwoamonfridaydecembertenthstoptheywillsignaltheirarrivalbyflashingtheirnavigationlightsinmorsecodetospelloutthewordflatandyouwillreplytyrestopifyoubelievethatyouarebeingwatchedthenabandontherendezvousandtryagainatintervalsoftwodaysthreedaysfivedaysandsevendaysstopdonotattempttomakecontactwiththeboatoritscrewinanyotherwaystoptheexplosiveisstablebutshouldbetreatedwithcarestopthefusesarethemostrecentproductofourresearchandtechnologydivisionandcarrytripletriggersstoptheyhaveatimercircuitwhichmaybesetforanyperiodfromthreeminutestoseventeenhoursstoptheycanalsobetriggeredbyatripwireassemblyorthefusemechanismcanbereplacedwithahandgrenademechanismstopsincethesechargeshavebeenshapedfordemolitionusewedonotrecommendusingthesedevicesincombatsinceyouhavenocertaintythatthechargewilllandinanorientationthatwillmaximiseitsdestructivepotentialstopthetripwireoptionisalsodeprecatedsinceitismorelikelythattheexplosiveswillbediscoverediftheyareattachedtosuchatriggerandmoreoveritwouldbedifficulttocoordinatethechargesusingsuchadevicestopthechargesthemselvesaresmallbutthegeometryofthepackagewillfocustheblastsoitisimperativethatyouinstallthesechargesinaccordancewiththemanufacturersinstructionsstopinordertomaximisethedamagetothetowerstheengineersrecommendthatyousetchargesonthreeofthelegsofeachtowerwithchargestwoandthreesettoexplodeinsequenceafterchargeonestopsetanadditionaldelayofthirtysecondsforchargetwoandoneminutetwentyfivesecondsforchargethreestopasthefirstlegbucklesitwillstresstheframesothattheshockwaveofthesecondchargewilldistortthesupportingmembersstopwiththethirdexplosiontheframeshouldbuckleresultinginthetotaldestructionofthetowersbutthissequencewillmakesiteclearanceandreconstructionhardertoaccomplishstopthedelaywithchargethreealsoincreasesthelikelihoodthatsoldierswillhavearrivedonsiteintimetobecaughtinthethirdblastincreasingconfusionandlossofmoralestopifitispossibletoclimbthetowerinadvanceofthedemolitiontogetmoredetailedimagesoftheaerialandamplifiercircuitrythenthisshouldbeattemptedhoweverifthereisanyguardpresencethennorisksshouldbetakeninthisregardstopwemustleaveittoyoutodeterminethemosteffectivetargetsfortheoperationbutthedemolitionmusthappensimultaneouslyatallsitesfortworeasonsstopfirstinordertopreventourenemyfromdisruptingtheoperationoncetheyrealisewhatishappeningstopsecondwemustleavenodoubtthatthiswasanactofwarstopthereisariskthatthebritishgovernmentmaytrytoreachanaccommodationwiththefuhrerdividingtheworldbetweentheirdyingempireandoursjustasitisbornstoptheonlywaytoensurethatwecantrulysupplantthemistodrawthemintoawartheycannotwinandthisprojectwillbetheprovocationthatensuresthatthiswillhappenstoptheplanningdivisionhasdeterminedthatjanuaryfirstwillbetheoptimalnightfortheattackasitcoincideswithanewmoonstoptheysuggestthatyousplitintotwoteamstoattacktheedmundstcaistorandcanewdonsitesopeningacorridoralongthethamesforourforthcomingairraidsstopthesupportteamsshouldsetuplookoutpostsatthetargetsinadvanceoftheattacksothatyoucanmonitorguardmovementsandmakeafinalassessmentofthesecuritystopfollowingtheoperationthesabotageteamsshouldrendezvoustogetherwiththesupportteamsatthehomeofthelocalortsgruppechiefinsouthmaldonstopauboatwillstandbytopickyouallupatthreefortysevenjanuarysecondwithafallbackrendezvousofonethirteenonthethirteenthwhenthesearchshouldhavedieddownstopyouwillneedtogainaccesstoaboatcapableofcarryingyouallouttomeetitstopthereareverymanyfishingvesselsinthisneighbourhoodandwerecommendstealingoneaftertheoperationstopitmightfeellesssecurethatobtainingoneinadvancehoweverwemustdoeverythingwecantopreventsuspicioninadvanceoftheoperationstopifthismissionsucceedsthenitwillbeonlyamatterofdaysbeforethewarbeginsandyourthreecomradesinlondonwillplayacrucialroleincoordinatingourintelligenceeffortsbehindenemylinesstopwehavebeenwatchingandlisteningcarefullyforsignsthattheoperationcouldhavebeencompromisedandasaresultofthoseenquirieswehavediscoveredanewtopsecretagencyknownonlybytheacronymbossstopwehavebeenunabletoinfiltratethisgroupbutitisknownthattheleaderissomeonewiththeinitialhandthattheyaretakingtheleadonsignalsintelligencestoptheheadofthecounterintelligencebranchusesthecodenamepearlandwewillbemakingeveryefforttodiscoverheridentitystopwhilethedeclarationofwarandthedestructionoftherdfsystemarethecentralgoalsofthisoperationthelondontrianglewillbekeytoensuringaflowofhighqualityintelligencetoinformourbattleplansstopwithouttheircommunicationswewillbeunabletomonitorbritishplansplacinggermanlivesatunnecessaryriskstopifthereisanychancethatmembersofyourgroupcouldbecapturedandinterrogatedthenyoushouldabandonthesabotageoperationandreturntotirpitzuferstopprotectingtheidentityofthetriangleisoffargreaterlongtermimportancetousstopwecanfindotherwaystoprovokethewarbutwewouldfinditmoredifficulttoensurethatwecanwinitwithoutanetworkofagentsinthecapitalstopthemissionwillberegardedasasuccessonlyifwecanguaranteetheirsafetystoptoincreasethesecurityofthelondontriangleitiscrucialthattheclockcipherdeviceandtheassociatedcodebooksreachourlondonagentsstopthedevicecannotbeallowedtofallintoenemyhandsandthismustbethetopprioritystopifyouarecapturedthenthecodebookcontainingthekeystotheciphermustbedestroyedstopitisprintedonspecialpaperthatshouldeasilydissolvebutitcanalsobeingestedifnecessarystopwhenusingthemachinetakecaretoerasethecipheralphabetafteruseandtodeletethekeyfromthecodebooktoensurethatnooneusesthesamekeytwicestopthiswillalsoreducetheriskofthekeyedcipherfallingintoenemyhandsstopifcaptureappearsimminentthenuseoneoftheshapedchargestodestroythedevicepreferablyburyingittogetherwiththechargetoincreasethedestructivepowerandmakeithardertoreconstructstopeveryoneinthemovementwillbeprayingforyoursuccessandyourcourageandcommitmenttothefatherlandwillbepraisedforeverstopyouareaninspirationtousallstopwishingyouluckinthefinalphaseoftheoperationstopyoursunclewilhelm'" ] }, "execution_count": 229, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cipherstream = zip(cycle(p_alpha), cycle(rotated_c_alpha))\n", "p_gen, s = decipher_message(scb, cipherstream)\n", "p_gen" ] }, { "cell_type": "code", "execution_count": 233, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "pb = prettify(p_gen)" ] }, { "cell_type": "code", "execution_count": 235, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "7298" ] }, "execution_count": 235, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_b_filename, 'w').write(pb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,md" }, "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 }