{ "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": 12, "metadata": {}, "outputs": [], "source": [ "from cipher.caesar import *\n", "from cipher.affine import *\n", "from cipher.keyword_cipher import *\n", "from support.text_prettify import *" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "c3a = open('3a.ciphertext').read()\n", "c3b = open('3b.ciphertext').read()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "IWQSWTS UGI WJREWOINA KSST LBGL E IBWONP KTWU GJWOL PWOYNGI JNGMK JOL E UGI NSVL UWTPSFETY UBGL BS BGP LW PW UELB LBS IBGPWU GFMBERS. E VWOTP IWQS LFGMSI WV BEQ ET JWILWT TSUIZGZSF MNEZZETYI VFWQ LBS ZSFEWP. LBS ILWFESI ILWZZSP ET 1873, GFWOTP LBS PGLS WV LBS NSLLSFI JSLUSST REMLWFEG GTP IEF MBGFNSI, IW E GIIOQS BS FSLOFTSP LW STYNGTP LBST, JOL E MWONPT'L VETP GTA FSMWFP WV BEQ ET LBS EQQEYFGLEWT VENSI GTP LBSFS UGI TWLBETY ET LBS WVVEMEGN FSMWFP LW IOYYSIL LBGL BS QSL UELB IEF MBGFNSI, NSL GNWTS UELB BSF QGHSILA. LBS LFGEN BGP YWTS MWNP GTP E QEYBL BGRS QWRSP WT GL LBGL ZWETL, JOL LBST E YWL LBS LBEFP SQGEN. LBEI LEQS EL UGI G KSAUWFP MEZBSF GTP EL LWWK G NELLNS NWTYSF LW JFSGK, LBWOYB LBS UWFP ILFOMLOFS BSNZSP G NWL. EL MWTVEFQSP SRSFALBETY E BGP YOSIISP IW VGF GJWOL JNGMK, GTP FGEISP G UBWNS NWGP WV TSU COSILEWTI! EL GNIW IOYYSILSP LBGL E QEYBL VETP GTIUSFI ET LBS IBGPWU GFMBERS, JOL VEFIL E BGP LW VEYOFS WOL UBSFS EL UGI, GTP BWU E MWONP YSL ET. E ILENN MGT'L JSNESRS EL, JOL LBS GTIUSF MGQS VFWQ G YWWYNS ISGFMB. E UGI NWWKETY VWF G NWMGLEWT LBGL UWONP BGRS ZFWREPSP JNGMK UELB MWRSF VWF G ILFSGQ WV REIELWFI, ZFSVSFGJNA ET G MSTLFGN NWTPWT NWMGLEWT, GTP UELB VGMENELESI VWF ISMOFS ILWFGYS WV WVVEMEGN FSMWFPI, GTP EL IBWONP BGRS JSST WZSTSP ET 1873 WF 1874. E ISGFMBSP VWF \"JNGMK, NWTPWT, 1874\" GTP E NEKSP UBGL E VWOTP. GTP LBGL EI UBA E VWOTP QAISNV NAETY WT LBS FWWV WV LBS TWFQGT IBGU JOENPETYI ET LBS QEPPNS WV LBS TEYBL GTP ET ZWOFETY FGET! E BGP LW VEYOFS WOL G UGA WV YSLLETY ETIEPS WTS WV LBS QWIL ISMOFS NWMGLEWTI ET STYNGTP!\n", "\n" ] } ], "source": [ "key_a, score_a = caesar_break(c3a)\n", "print(caesar_decipher(c3a, key_a))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SOMEONE WAS OBVIOUSLY KEEN THAT I SHOULD KNOW ABOUT DOUGLAS BLACK BUT I WAS LEFT WONDERING WHAT HE\n", "HAD TO DO WITH THE SHADOW ARCHIVE. I FOUND SOME TRACES OF HIM IN BOSTON NEWSPAPER CLIPPINGS FROM THE\n", "PERIOD. THE STORIES STOPPED IN 1873, AROUND THE DATE OF THE LETTERS BETWEEN VICTORIA AND SIR\n", "CHARLES, SO I ASSUME HE RETURNED TO ENGLAND THEN, BUT I COULDN’T FIND ANY RECORD OF HIM IN THE\n", "IMMIGRATION FILES AND THERE WAS NOTHING IN THE OFFICIAL RECORD TO SUGGEST THAT HE MET WITH SIR\n", "CHARLES, LET ALONE WITH HER MAJESTY. THE TRAIL HAD GONE COLD AND I MIGHT HAVE MOVED ON AT THAT\n", "POINT, BUT THEN I GOT THE THIRD EMAIL. THIS TIME IT WAS A KEYWORD CIPHER AND IT TOOK A LITTLE LONGER\n", "TO BREAK, THOUGH THE WORD STRUCTURE HELPED A LOT. IT CONFIRMED EVERYTHING I HAD GUESSED SO FAR ABOUT\n", "BLACK, AND RAISED A WHOLE LOAD OF NEW QUESTIONS! IT ALSO SUGGESTED THAT I MIGHT FIND ANSWERS IN THE\n", "SHADOW ARCHIVE, BUT FIRST I HAD TO FIGURE OUT WHERE IT WAS, AND HOW I COULD GET IN. I STILL CAN’T\n", "BELIEVE IT, BUT THE ANSWER CAME FROM A GOOGLE SEARCH. I WAS LOOKING FOR A LOCATION THAT WOULD HAVE\n", "PROVIDED BLACK WITH COVER FOR A STREAM OF VISITORS, PREFERABLY IN A CENTRAL LONDON LOCATION, AND\n", "WITH FACILITIES FOR SECURE STORAGE OF OFFICIAL RECORDS, AND IT SHOULD HAVE BEEN OPENED IN 1873 OR\n", "1874. I SEARCHED FOR “BLACK, LONDON, 1874” AND I LIKED WHAT I FOUND. AND THAT IS WHY I FOUND MYSELF\n", "LYING ON THE ROOF OF THE NORMAN SHAW BUILDINGS IN THE MIDDLE OF THE NIGHT AND IN POURING RAIN! I HAD\n", "TO FIGURE OUT A WAY OF GETTING INSIDE ONE OF THE MOST SECURE LOCATIONS IN ENGLAND!\n" ] } ], "source": [ "(m_a, s_a, o_a), score_a = affine_break(c3a)\n", "print(lcat(tpack(affine_decipher(c3a, m_a, s_a, o_a).split())))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1556" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open('3a.plaintext', 'w').write(affine_decipher(c3a, m_a, s_a, o_a))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('loyalty', , -1602.564299343375)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(key_b, wrap_b), score_b = keyword_break_mp(c3b)\n", "key_b, wrap_b, score_b" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "her majesty is right, life in boston is dull, but not dull enough to persuade me that working for\n", "her would be worth the risk. but of course she had an answer for that. she pointed out that\n", "returning to the united states carried its own risks. i had kept myself amused for the last few\n", "years separating the greedy and venal from their money by a variety of means, not all of them\n", "entirely approved by the law. i was left wondering how the queen knew about that, and whether my\n", "cousin had been instructed to tell the federal marshalls about my activities. discretion seemed the\n", "wise course, and anyway, how often do you get a job offer from a queen? charles has done a sterling\n", "job developing a network of agents and his intelligence operations have become a key part of british\n", "diplomacy. the growing instability across europe threatens the empire, and it is her majesty’s\n", "belief that we will need to respond in kind to destabilise our enemies before they grow too strong.\n", "this is a new and dangerous kind of warfare, but could, i suppose, save lives, and we will, in any\n", "case, need to match our enemies if we are to stay ahead. this entire operation must be kept secret.\n", "first from our enemies, but second, and just as important, from the official machinery of state. her\n", "majesty cannot afford the risk that her government could be implicated in these operations, and sir\n", "charles has reason to believe that the foreign office may have been compromised. for this reason we\n", "need to move sir charles’ intelligence operation to a more secure location. and i think i have an\n", "idea where that could be!\n" ] } ], "source": [ "print(lcat(tpack(keyword_decipher(c3b, key_b, wrap_b).split())))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1599" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open('3b.plaintext', 'w').write(keyword_decipher(c3b, key_b, wrap_b))" ] }, { "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }