From: Neil Smith Date: Thu, 18 Oct 2018 21:08:48 +0000 (+0100) Subject: Done challenge 3 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=7b623dfcf6c9c01abd43a5566d2388eecb245fa7;p=cipher-tools.git Done challenge 3 --- diff --git a/2018/2018-challenge3.ipynb b/2018/2018-challenge3.ipynb new file mode 100644 index 0000000..d7c5282 --- /dev/null +++ b/2018/2018-challenge3.ipynb @@ -0,0 +1,212 @@ +{ + "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 +} diff --git a/2018/3a.ciphertext b/2018/3a.ciphertext new file mode 100644 index 0000000..b36aef0 --- /dev/null +++ b/2018/3a.ciphertext @@ -0,0 +1 @@ +FTNPTQP RDF TGOBTLFKX HPPQ IYDI B FYTLKM HQTR DGTLI MTLVKDF GKDJH GLI B RDF KPSI RTQMPCBQV RYDI YP YDM IT MT RBIY IYP FYDMTR DCJYBOP. B STLQM FTNP ICDJPF TS YBN BQ GTFITQ QPRFWDWPC JKBWWBQVF SCTN IYP WPCBTM. IYP FITCBPF FITWWPM BQ 1873, DCTLQM IYP MDIP TS IYP KPIIPCF GPIRPPQ OBJITCBD DQM FBC JYDCKPF, FT B DFFLNP YP CPILCQPM IT PQVKDQM IYPQ, GLI B JTLKMQ’I SBQM DQX CPJTCM TS YBN BQ IYP BNNBVCDIBTQ SBKPF DQM IYPCP RDF QTIYBQV BQ IYP TSSBJBDK CPJTCM IT FLVVPFI IYDI YP NPI RBIY FBC JYDCKPF, KPI DKTQP RBIY YPC NDEPFIX. IYP ICDBK YDM VTQP JTKM DQM B NBVYI YDOP NTOPM TQ DI IYDI WTBQI, GLI IYPQ B VTI IYP IYBCM PNDBK. IYBF IBNP BI RDF D HPXRTCM JBWYPC DQM BI ITTH D KBIIKP KTQVPC IT GCPDH, IYTLVY IYP RTCM FICLJILCP YPKWPM D KTI. BI JTQSBCNPM POPCXIYBQV B YDM VLPFFPM FT SDC DGTLI GKDJH, DQM CDBFPM D RYTKP KTDM TS QPR ZLPFIBTQF! BI DKFT FLVVPFIPM IYDI B NBVYI SBQM DQFRPCF BQ IYP FYDMTR DCJYBOP, GLI SBCFI B YDM IT SBVLCP TLI RYPCP BI RDF, DQM YTR B JTLKM VPI BQ. B FIBKK JDQ’I GPKBPOP BI, GLI IYP DQFRPC JDNP SCTN D VTTVKP FPDCJY. B RDF KTTHBQV STC D KTJDIBTQ IYDI RTLKM YDOP WCTOBMPM GKDJH RBIY JTOPC STC D FICPDN TS OBFBITCF, WCPSPCDGKX BQ D JPQICDK KTQMTQ KTJDIBTQ, DQM RBIY SDJBKBIBPF STC FPJLCP FITCDVP TS TSSBJBDK CPJTCMF, DQM BI FYTLKM YDOP GPPQ TWPQPM BQ 1873 TC 1874. B FPDCJYPM STC “GKDJH, KTQMTQ, 1874” DQM B KBHPM RYDI B STLQM. DQM IYDI BF RYX B STLQM NXFPKS KXBQV TQ IYP CTTS TS IYP QTCNDQ FYDR GLBKMBQVF BQ IYP NBMMKP TS IYP QBVYI DQM BQ WTLCBQV CDBQ! B YDM IT SBVLCP TLI D RDX TS VPIIBQV BQFBMP TQP TS IYP NTFI FPJLCP KTJDIBTQF BQ PQVKDQM! diff --git a/2018/3a.plaintext b/2018/3a.plaintext new file mode 100644 index 0000000..bb32477 --- /dev/null +++ b/2018/3a.plaintext @@ -0,0 +1 @@ +SOMEONE WAS OBVIOUSLY KEEN THAT I SHOULD KNOW ABOUT DOUGLAS BLACK BUT I WAS LEFT WONDERING WHAT HE HAD TO DO WITH THE SHADOW ARCHIVE. I FOUND SOME TRACES OF HIM IN BOSTON NEWSPAPER CLIPPINGS FROM THE PERIOD. THE STORIES STOPPED IN 1873, AROUND THE DATE OF THE LETTERS BETWEEN VICTORIA AND SIR CHARLES, SO I ASSUME HE RETURNED TO ENGLAND THEN, BUT I COULDN’T FIND ANY RECORD OF HIM IN THE IMMIGRATION FILES AND THERE WAS NOTHING IN THE OFFICIAL RECORD TO SUGGEST THAT HE MET WITH SIR CHARLES, LET ALONE WITH HER MAJESTY. THE TRAIL HAD GONE COLD AND I MIGHT HAVE MOVED ON AT THAT POINT, BUT THEN I GOT THE THIRD EMAIL. THIS TIME IT WAS A KEYWORD CIPHER AND IT TOOK A LITTLE LONGER TO BREAK, THOUGH THE WORD STRUCTURE HELPED A LOT. IT CONFIRMED EVERYTHING I HAD GUESSED SO FAR ABOUT BLACK, AND RAISED A WHOLE LOAD OF NEW QUESTIONS! IT ALSO SUGGESTED THAT I MIGHT FIND ANSWERS IN THE SHADOW ARCHIVE, BUT FIRST I HAD TO FIGURE OUT WHERE IT WAS, AND HOW I COULD GET IN. I STILL CAN’T BELIEVE IT, BUT THE ANSWER CAME FROM A GOOGLE SEARCH. I WAS LOOKING FOR A LOCATION THAT WOULD HAVE PROVIDED BLACK WITH COVER FOR A STREAM OF VISITORS, PREFERABLY IN A CENTRAL LONDON LOCATION, AND WITH FACILITIES FOR SECURE STORAGE OF OFFICIAL RECORDS, AND IT SHOULD HAVE BEEN OPENED IN 1873 OR 1874. I SEARCHED FOR “BLACK, LONDON, 1874” AND I LIKED WHAT I FOUND. AND THAT IS WHY I FOUND MYSELF LYING ON THE ROOF OF THE NORMAN SHAW BUILDINGS IN THE MIDDLE OF THE NIGHT AND IN POURING RAIN! I HAD TO FIGURE OUT A WAY OF GETTING INSIDE ONE OF THE MOST SECURE LOCATIONS IN ENGLAND! diff --git a/2018/3b.ciphertext b/2018/3b.ciphertext new file mode 100644 index 0000000..a52eba3 --- /dev/null +++ b/2018/3b.ciphertext @@ -0,0 +1,7 @@ +CTN HLETPQW DP NDBCQ, GDZT DI OJPQJI DP ARGG, ORQ IJQ ARGG TIJRBC QJ KTNPRLAT HT QCLQ UJNFDIB ZJN CTN UJRGA OT UJNQC QCT NDPF. ORQ JZ YJRNPT PCT CLA LI LIPUTN ZJN QCLQ. PCT KJDIQTA JRQ QCLQ NTQRNIDIB QJ QCT RIDQTA PQLQTP YLNNDTA DQP JUI NDPFP. + +D CLA FTKQ HWPTGZ LHRPTA ZJN QCT GLPQ ZTU WTLNP PTKLNLQDIB QCT BNTTAW LIA STILG ZNJH QCTDN HJITW OW L SLNDTQW JZ HTLIP, IJQ LGG JZ QCTH TIQDNTGW LKKNJSTA OW QCT GLU. D ULP GTZQ UJIATNDIB CJU QCT MRTTI FITU LOJRQ QCLQ, LIA UCTQCTN HW YJRPDI CLA OTTI DIPQNRYQTA QJ QTGG QCT ZTATNLG HLNPCLGGP LOJRQ HW LYQDSDQDTP. ADPYNTQDJI PTTHTA QCT UDPT YJRNPT, LIA LIWULW, CJU JZQTI AJ WJR BTQ L EJO JZZTN ZNJH L MRTTI? + +YCLNGTP CLP AJIT L PQTNGDIB EJO ATSTGJKDIB L ITQUJNF JZ LBTIQP LIA CDP DIQTGGDBTIYT JKTNLQDJIP CLST OTYJHT L FTW KLNQ JZ ONDQDPC ADKGJHLYW. QCT BNJUDIB DIPQLODGDQW LYNJPP TRNJKT QCNTLQTIP QCT THKDNT, LIA DQ DP CTN HLETPQW’P OTGDTZ QCLQ UT UDGG ITTA QJ NTPKJIA DI FDIA QJ ATPQLODGDPT JRN TITHDTP OTZJNT QCTW BNJU QJJ PQNJIB. QCDP DP L ITU LIA ALIBTNJRP FDIA JZ ULNZLNT, ORQ YJRGA, D PRKKJPT, PLST GDSTP, LIA UT UDGG, DI LIW YLPT, ITTA QJ HLQYC JRN TITHDTP DZ UT LNT QJ PQLW LCTLA. + +QCDP TIQDNT JKTNLQDJI HRPQ OT FTKQ PTYNTQ. ZDNPQ ZNJH JRN TITHDTP, ORQ PTYJIA, LIA ERPQ LP DHKJNQLIQ, ZNJH QCT JZZDYDLG HLYCDITNW JZ PQLQT. CTN HLETPQW YLIIJQ LZZJNA QCT NDPF QCLQ CTN BJSTNIHTIQ YJRGA OT DHKGDYLQTA DI QCTPT JKTNLQDJIP, LIA PDN YCLNGTP CLP NTLPJI QJ OTGDTST QCLQ QCT ZJNTDBI JZZDYT HLW CLST OTTI YJHKNJHDPTA. ZJN QCDP NTLPJI UT ITTA QJ HJST PDN YCLNGTP’ DIQTGGDBTIYT JKTNLQDJI QJ L HJNT PTYRNT GJYLQDJI. LIA D QCDIF D CLST LI DATL UCTNT QCLQ YJRGA OT! \ No newline at end of file diff --git a/2018/3b.plaintext b/2018/3b.plaintext new file mode 100644 index 0000000..27b9736 --- /dev/null +++ b/2018/3b.plaintext @@ -0,0 +1,7 @@ +her majesty is right, life in boston is dull, but not dull enough to persuade me that working for her would be worth the risk. but of course she had an answer for that. she pointed out that returning to the united states carried its own risks. + +i had kept myself amused for the last few years separating the greedy and venal from their money by a variety of means, not all of them entirely approved by the law. i was left wondering how the queen knew about that, and whether my cousin had been instructed to tell the federal marshalls about my activities. discretion seemed the wise course, and anyway, how often do you get a job offer from a queen? + +charles has done a sterling job developing a network of agents and his intelligence operations have become a key part of british diplomacy. the growing instability across europe threatens the empire, and it is her majesty’s belief that we will need to respond in kind to destabilise our enemies before they grow too strong. this is a new and dangerous kind of warfare, but could, i suppose, save lives, and we will, in any case, need to match our enemies if we are to stay ahead. + +this entire operation must be kept secret. first from our enemies, but second, and just as important, from the official machinery of state. her majesty cannot afford the risk that her government could be implicated in these operations, and sir charles has reason to believe that the foreign office may have been compromised. for this reason we need to move sir charles’ intelligence operation to a more secure location. and i think i have an idea where that could be! \ No newline at end of file