From a8fe7438ec48719c7807bdc82fd35f6c8a690e24 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 5 Nov 2020 15:35:40 +0000 Subject: [PATCH 01/16] Done challenge 2 --- 2020/2020-a-challenge2.ipynb | 218 +++++++++++++++++++++++++++++++++++ 2020/2020-a-challenge2.md | 70 +++++++++++ 2020/ciphertext.2a.txt | 1 + 2020/ciphertext.2b.txt | 1 + 2020/plaintext.2a.txt | 1 + 2020/plaintext.2b.txt | 1 + 6 files changed, 292 insertions(+) create mode 100644 2020/2020-a-challenge2.ipynb create mode 100644 2020/2020-a-challenge2.md create mode 100644 2020/ciphertext.2a.txt create mode 100644 2020/ciphertext.2b.txt create mode 100644 2020/plaintext.2a.txt create mode 100644 2020/plaintext.2b.txt diff --git a/2020/2020-a-challenge2.ipynb b/2020/2020-a-challenge2.ipynb new file mode 100644 index 0000000..be5233b --- /dev/null +++ b/2020/2020-a-challenge2.ipynb @@ -0,0 +1,218 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 2\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": 9, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "19 18 True \n", + "\n", + "The decrypt of the first mission intercept has raised a number of questions about the spyclist operation, if that is what it is, but it has also triggered enquiries about the personnel referenced in that message. Our counterintelligence unit have asked me to task you with enquiries about the names mentioned there, in particular: Jessica; Wilhelm; Nikolaus; Tirpitzufer. It is possible that these are pseudonyms or code names, but they do not appear in our records and CI branch would be very interested in anything you can find out about them in relation to Nazi spy operations. I followed up on the SIS report that Hitler Youth groups travelling abroad were asked to complete a detailed questionnaire, checking if Harry had links that could help with this, and he sent me the attached message that was photographed by a BOSS undercover operative in Berlin. He told me that it had been exfiltrated from Abwehr headquarters and appears to be a request for approval for a new mission, though neither H nor I have had time to break it, so I look forward to receiving your decrypts. We believe the message has been enciphered using a keyword substitution cipher and given that we are not sure how serious the spyclist threat might be we would be grateful if you could decipher it quickly. The message was also a reminder to me that our own security is an important consideration, so I will also switch to a keyword substitution cipher for the next Mission Briefing. Pearl.\n", + "\n" + ] + } + ], + "source": [ + "(m_a, a_a, o_a), score_a = affine_break(ca)\n", + "print(m_a, a_a, o_a, '\\n')\n", + "pa = affine_decipher(ca, m_a, a_a, o_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1471" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "archerys KeywordWrapAlphabet.from_last \n", + "\n", + "attdctioc w our missioc to dmnde sympathisdrs ic thd ul dstanfishmdct is goicg wdff afthough thd rdkdct ickrdasd ic eipfomatik tdcsioc has sigcibikactfy ickrdasde thd risl bor our agdcts ic kommucikaticg with thdir hacefdrs. with tdfdgram trabbik ucedr dchackde supdrvisioc ny thd ul ictdffigdckd orgacisatiocs it is afso ickrdasicgfy eibbikuft bor thd agdcts ace thdir hacefdrs to rdpatriatd ictdffigdckd rdports ob acy sigcibikackd. thd usd ob naclicg kiphdrs is co focgdr rdgarede as sdkurd ace edspitd its onvious aevactagds, thd dcigma is too vafuanfd to us to affow its usd ndhice dcdmy ficds. bor cow, wd ard dckouragicg our agdcts to usd a mix ob ldywore ace tracspositioc kiphdrs as taught ic thdir nasik traicicg, sickd thdsd ard rdfianfd ace eo cot rdquird thd agdcts to nd ic possdssioc ob mord thac a sdrids ob ldy wores ace phrasds, whikh thdy ard wdff anfd to mdmorisd. as thd quactity ob sigcafs trabbik ickrdasds wd wiff cdde to rdkocsiedr our protokofs, nut bor cow i thicl our bokus shoufe nd oc edvdfopicg sdkurd kommucikatioc khaccdfs, with kut-outs to isofatd our mord vafuanfd assdts. i eiskussde this issud with my kouctdrpart ic edpartmdct ih who is a lddc kykfist ace hd maed a rathdr icgdcious suggdstioc that wd might mald gooe usd ob thd hitfdr youth. a cumndr ob partids havd nddc icvitde to visit thd ul oc kykficg tours ace hd hae nddc kocsiedricg aslicg thdm to rdkore icbormatioc anout thd fayout ob mifitary ace iceustriaf facemarls as part ob his ictdffigdckd gathdricg opdratioc. it is highfy fildfy that acy war wiff icvofvd a protraktde nomnicg kampaigc ace up to eatd maps wiff nd ob grdat vafud ic our pfaccicg. burthdrmord, thd kouctrysied roae fayouts ic thd ul ard cotorious bor thdir icdbbikidcky ace acy icvasioc, woufe nd sdvdrdfy hampdrde ny our fakl ob lcowfdegd ob tracsport cdtworls. hd hae erabtde ac appardctfy rathdr iccokuous artikfd bor thd cazi kykfist assokiatioc magazicd with a fist ob thicgs that our youcg kykfists might bice ictdrdsticg: imprdss oc your mdmory thd roaes ace paths, viffagds ace towcs, outstaceicg khurkh towdrs ace othdr facemarls so that you wiff cot borgdt thdm. mald a cotd ob thd camds, pfakds, rivdrs, sdas ace mouctaics. pdrhaps you may nd anfd to utifisd thdsd somd timd bor thd ndcdbit ob thd bathdrface. shoufe you komd to a nriegd whikh ictdrdsts you, dxamicd its kocstruktioc ace thd matdriafs usde. fdarc to mdasurd ace dstimatd thd wieth ob strdams. waed through bores so that you wiff nd anfd to bice thdm ic thd earl. i proposd that wd kocsiedr usicg thdsd assdts as thd kut-outs ndtwddc our ucedrkovdr agdcts ace thdir hacefdrs ic thd ul ace our kommucikatiocs cdtworl. thdy ard rdfativdfy brdd to movd arouce thd kouctry ace kac dasify nd traicde to usd erop-obbs ace othdr spykrabt to affow thdm to koffdkt ictdffigdckd rdports ace pass thdm oc. thd marvdffous postd rdstactd systdm affows us to kommucikatd with thdm, ace a suitanfd koednool woufe affow us to tracsmit icstruktiocs ic pfaic tdxt with co risl that thd mdacicg koufe nd eiskdrcde ny kouctdrictdffigdckd opdrativds ic thd postaf sdrvikd. i havd acothdr thought anout how wd might dxpfoit this cdtworl burthdr, howdvdr i cdde to worl through somd mord edtaifs ndbord i eiskuss it with you, ace i wactde to khdkl that you ard happy bor md to affokatd rdsourkds to traic a cumndr ob hitfdr youth ic thd rdquirde sliffs bor this opdratioc. cr.\n", + "\n" + ] + } + ], + "source": [ + "(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams)\n", + "print(word_b, wrap_b, '\\n')\n", + "pb = keyword_decipher(cb, word_b, wrap_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "abwehrstuvxyzcdfgijklmnopq \n", + "\n", + "attention w our mission to embed sympathisers in the uk establishment is going well although the recent increase in diplomatic tension has significantly increased the risk for our agents in communicating with their handlers. with telegram traffic under enhanced supervision by the uk intelligence organisations it is also increasingly difficult for the agents and their handlers to repatriate intelligence reports of any significance. the use of banking ciphers is no longer regarded as secure and despite its obvious advantages, the enigma is too valuable to us to allow its use behind enemy lines. for now, we are encouraging our agents to use a mix of keyword and transposition ciphers as taught in their basic training, since these are reliable and do not require the agents to be in possession of more than a series of key words and phrases, which they are well able to memorise. as the quantity of signals traffic increases we will need to reconsider our protocols, but for now i think our focus should be on developing secure communication channels, with cut-outs to isolate our more valuable assets. i discussed this issue with my counterpart in department ih who is a keen cyclist and he made a rather ingenious suggestion that we might make good use of the hitler youth. a number of parties have been invited to visit the uk on cycling tours and he had been considering asking them to record information about the layout of military and industrial landmarks as part of his intelligence gathering operation. it is highly likely that any war will involve a protracted bombing campaign and up to date maps will be of great value in our planning. furthermore, the countryside road layouts in the uk are notorious for their inefficiency and any invasion, would be severely hampered by our lack of knowledge of transport networks. he had drafted an apparently rather innocuous article for the nazi cyclist association magazine with a list of things that our young cyclists might find interesting: impress on your memory the roads and paths, villages and towns, outstanding church towers and other landmarks so that you will not forget them. make a note of the names, places, rivers, seas and mountains. perhaps you may be able to utilise these some time for the benefit of the fatherland. should you come to a bridge which interests you, examine its construction and the materials used. learn to measure and estimate the width of streams. wade through fords so that you will be able to find them in the dark. i propose that we consider using these assets as the cut-outs between our undercover agents and their handlers in the uk and our communications network. they are relatively free to move around the country and can easily be trained to use drop-offs and other spycraft to allow them to collect intelligence reports and pass them on. the marvellous poste restante system allows us to communicate with them, and a suitable codebook would allow us to transmit instructions in plain text with no risk that the meaning could be discerned by counterintelligence operatives in the postal service. i have another thought about how we might exploit this network further, however i need to work through some more details before i discuss it with you, and i wanted to check that you are happy for me to allocate resources to train a number of hitler youth in the required skills for this operation. nr.\n", + "\n" + ] + } + ], + "source": [ + "word_b, score_b = simulated_annealing_break(scb)\n", + "print(word_b, '\\n')\n", + "pb = keyword_decipher(cb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'attention w our mission to embed sympathisers in the uk establishment is going well although the recent increase in diplomatic tension has significantly increased the risk for our agents in communicating with their handlers. with telegram traffic under enhanced supervision by the uk intelligence organisations it is also increasingly difficult for the agents and their handlers to repatriate intelligence reports of any significance. the use of banking ciphers is no longer regarded as secure and despite its obvious advantages, the enigma is too valuable to us to allow its use behind enemy lines. for now, we are encouraging our agents to use a mix of keyword and transposition ciphers as taught in their basic training, since these are reliable and do not require the agents to be in possession of more than a series of key words and phrases, which they are well able to memorise. as the quantity of signals traffic increases we will need to reconsider our protocols, but for now i think our focus should be on developing secure communication channels, with cut-outs to isolate our more valuable assets. i discussed this issue with my counterpart in department ih who is a keen cyclist and he made a rather ingenious suggestion that we might make good use of the hitler youth. a number of parties have been invited to visit the uk on cycling tours and he had been considering asking them to record information about the layout of military and industrial landmarks as part of his intelligence gathering operation. it is highly likely that any war will involve a protracted bombing campaign and up to date maps will be of great value in our planning. furthermore, the countryside road layouts in the uk are notorious for their inefficiency and any invasion, would be severely hampered by our lack of knowledge of transport networks. he had drafted an apparently rather innocuous article for the nazi cyclist association magazine with a list of things that our young cyclists might find interesting: impress on your memory the roads and paths, villages and towns, outstanding church towers and other landmarks so that you will not forget them. make a note of the names, places, rivers, seas and mountains. perhaps you may be able to utilise these some time for the benefit of the fatherland. should you come to a bridge which interests you, examine its construction and the materials used. learn to measure and estimate the width of streams. wade through fords so that you will be able to find them in the dark. i propose that we consider using these assets as the cut-outs between our undercover agents and their handlers in the uk and our communications network. they are relatively free to move around the country and can easily be trained to use drop-offs and other spycraft to allow them to collect intelligence reports and pass them on. the marvellous poste restante system allows us to communicate with them, and a suitable codebook would allow us to transmit instructions in plain text with no risk that the meaning could be discerned by counterintelligence operatives in the postal service. i have another thought about how we might exploit this network further, however i need to work through some more details before i discuss it with you, and i wanted to check that you are happy for me to allocate resources to train a number of hitler youth in the required skills for this operation. nr.\\n'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "keyword_decipher(cb, 'abwehr', KeywordWrapAlphabet.from_last)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3403" + ] + }, + "execution_count": 21, + "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 +} diff --git a/2020/2020-a-challenge2.md b/2020/2020-a-challenge2.md new file mode 100644 index 0000000..80efcc4 --- /dev/null +++ b/2020/2020-a-challenge2.md @@ -0,0 +1,70 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +``` + +```python Collapsed="false" +challenge_number = 2 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() +scb = sanitise(cb) +``` + +```python Collapsed="false" +(m_a, a_a, o_a), score_a = affine_break(ca) +print(m_a, a_a, o_a, '\n') +pa = affine_decipher(ca, m_a, a_a, o_a) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams) +print(word_b, wrap_b, '\n') +pb = keyword_decipher(cb, word_b, wrap_b) +print(pb) +``` + +```python Collapsed="false" +word_b, score_b = simulated_annealing_break(scb) +print(word_b, '\n') +pb = keyword_decipher(cb, word_b) +print(pb) +``` + +```python Collapsed="false" +keyword_decipher(cb, 'abwehr', KeywordWrapAlphabet.from_last) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2020/ciphertext.2a.txt b/2020/ciphertext.2a.txt new file mode 100644 index 0000000..d33e44b --- /dev/null +++ b/2020/ciphertext.2a.txt @@ -0,0 +1 @@ +Hni piwvyjh qb hni bgvoh egoogqx gxhivwijh nko vkgoip k xaediv qb caiohgqxo kdqah hni ojywlgoh qjivkhgqx, gb hnkh go mnkh gh go, dah gh nko kloq hvguuivip ixcagvgio kdqah hni jivoqxxil vibivixwip gx hnkh eiookui. Qav wqaxhivgxhillguixwi axgh nkti kosip ei hq hkos yqa mghn ixcagvgio kdqah hni xkeio eixhgqxip hnivi, gx jkvhgwalkv: Zioogwk; Mglnile; Xgsqlkao; Hgvjghrabiv. Gh go jqoogdli hnkh hnioi kvi joiapqxyeo qv wqpi xkeio, dah hniy pq xqh kjjikv gx qav viwqvpo kxp WG dvkxwn mqalp di tivy gxhiviohip gx kxyhngxu yqa wkx bgxp qah kdqah hnie gx vilkhgqx hq Xkrg ojy qjivkhgqxo. G bqllqmip aj qx hni OGO vijqvh hnkh Nghliv Yqahn uvqajo hvktillgxu kdvqkp mivi kosip hq wqejlihi k pihkglip caiohgqxxkgvi, wniwsgxu gb Nkvvy nkp lgxso hnkh wqalp nilj mghn hngo, kxp ni oixh ei hni khhkwnip eiookui hnkh mko jnqhquvkjnip dy k DQOO axpivwqtiv qjivkhgti gx Divlgx. Ni hqlp ei hnkh gh nkp diix ifbglhvkhip bvqe Kdminv nikpcakvhivo kxp kjjikvo hq di k vicaioh bqv kjjvqtkl bqv k xim egoogqx, hnqaun xighniv N xqv G nkti nkp hgei hq dviks gh, oq G lqqs bqvmkvp hq viwigtgxu yqav piwvyjho. Mi dilgiti hni eiookui nko diix ixwgjnivip aogxu k siymqvp oadohghahgqx wgjniv kxp ugtix hnkh mi kvi xqh oavi nqm oivgqao hni ojywlgoh hnvikh egunh di mi mqalp di uvkhibal gb yqa wqalp piwgjniv gh cagwsly. Hni eiookui mko kloq k viegxpiv hq ei hnkh qav qmx oiwavghy go kx gejqvhkxh wqxogpivkhgqx, oq G mgll kloq omghwn hq k siymqvp oadohghahgqx wgjniv bqv hni xifh Egoogqx Dvgibgxu. Jikvl. diff --git a/2020/ciphertext.2b.txt b/2020/ciphertext.2b.txt new file mode 100644 index 0000000..3268019 --- /dev/null +++ b/2020/ciphertext.2b.txt @@ -0,0 +1 @@ +AKKHCKUDC N DLI ZUJJUDC KD HZBHE JPZFAKTUJHIJ UC KTH LX HJKABYUJTZHCK UJ SDUCS NHYY AYKTDLST KTH IHWHCK UCWIHAJH UC EUFYDZAKUW KHCJUDC TAJ JUSCURUWACKYP UCWIHAJHE KTH IUJX RDI DLI ASHCKJ UC WDZZLCUWAKUCS NUKT KTHUI TACEYHIJ. NUKT KHYHSIAZ KIARRUW LCEHI HCTACWHE JLFHIMUJUDC BP KTH LX UCKHYYUSHCWH DISACUJAKUDCJ UK UJ AYJD UCWIHAJUCSYP EURRUWLYK RDI KTH ASHCKJ ACE KTHUI TACEYHIJ KD IHFAKIUAKH UCKHYYUSHCWH IHFDIKJ DR ACP JUSCURUWACWH. KTH LJH DR BACXUCS WUFTHIJ UJ CD YDCSHI IHSAIEHE AJ JHWLIH ACE EHJFUKH UKJ DBMUDLJ AEMACKASHJ, KTH HCUSZA UJ KDD MAYLABYH KD LJ KD AYYDN UKJ LJH BHTUCE HCHZP YUCHJ. RDI CDN, NH AIH HCWDLIASUCS DLI ASHCKJ KD LJH A ZUO DR XHPNDIE ACE KIACJFDJUKUDC WUFTHIJ AJ KALSTK UC KTHUI BAJUW KIAUCUCS, JUCWH KTHJH AIH IHYUABYH ACE ED CDK IHGLUIH KTH ASHCKJ KD BH UC FDJJHJJUDC DR ZDIH KTAC A JHIUHJ DR XHP NDIEJ ACE FTIAJHJ, NTUWT KTHP AIH NHYY ABYH KD ZHZDIUJH. AJ KTH GLACKUKP DR JUSCAYJ KIARRUW UCWIHAJHJ NH NUYY CHHE KD IHWDCJUEHI DLI FIDKDWDYJ, BLK RDI CDN U KTUCX DLI RDWLJ JTDLYE BH DC EHMHYDFUCS JHWLIH WDZZLCUWAKUDC WTACCHYJ, NUKT WLK-DLKJ KD UJDYAKH DLI ZDIH MAYLABYH AJJHKJ. U EUJWLJJHE KTUJ UJJLH NUKT ZP WDLCKHIFAIK UC EHFAIKZHCK UT NTD UJ A XHHC WPWYUJK ACE TH ZAEH A IAKTHI UCSHCUDLJ JLSSHJKUDC KTAK NH ZUSTK ZAXH SDDE LJH DR KTH TUKYHI PDLKT. A CLZBHI DR FAIKUHJ TAMH BHHC UCMUKHE KD MUJUK KTH LX DC WPWYUCS KDLIJ ACE TH TAE BHHC WDCJUEHIUCS AJXUCS KTHZ KD IHWDIE UCRDIZAKUDC ABDLK KTH YAPDLK DR ZUYUKAIP ACE UCELJKIUAY YACEZAIXJ AJ FAIK DR TUJ UCKHYYUSHCWH SAKTHIUCS DFHIAKUDC. UK UJ TUSTYP YUXHYP KTAK ACP NAI NUYY UCMDYMH A FIDKIAWKHE BDZBUCS WAZFAUSC ACE LF KD EAKH ZAFJ NUYY BH DR SIHAK MAYLH UC DLI FYACCUCS. RLIKTHIZDIH, KTH WDLCKIPJUEH IDAE YAPDLKJ UC KTH LX AIH CDKDIUDLJ RDI KTHUI UCHRRUWUHCWP ACE ACP UCMAJUDC, NDLYE BH JHMHIHYP TAZFHIHE BP DLI YAWX DR XCDNYHESH DR KIACJFDIK CHKNDIXJ. TH TAE EIARKHE AC AFFAIHCKYP IAKTHI UCCDWLDLJ AIKUWYH RDI KTH CAQU WPWYUJK AJJDWUAKUDC ZASAQUCH NUKT A YUJK DR KTUCSJ KTAK DLI PDLCS WPWYUJKJ ZUSTK RUCE UCKHIHJKUCS: UZFIHJJ DC PDLI ZHZDIP KTH IDAEJ ACE FAKTJ, MUYYASHJ ACE KDNCJ, DLKJKACEUCS WTLIWT KDNHIJ ACE DKTHI YACEZAIXJ JD KTAK PDL NUYY CDK RDISHK KTHZ. ZAXH A CDKH DR KTH CAZHJ, FYAWHJ, IUMHIJ, JHAJ ACE ZDLCKAUCJ. FHITAFJ PDL ZAP BH ABYH KD LKUYUJH KTHJH JDZH KUZH RDI KTH BHCHRUK DR KTH RAKTHIYACE. JTDLYE PDL WDZH KD A BIUESH NTUWT UCKHIHJKJ PDL, HOAZUCH UKJ WDCJKILWKUDC ACE KTH ZAKHIUAYJ LJHE. YHAIC KD ZHAJLIH ACE HJKUZAKH KTH NUEKT DR JKIHAZJ. NAEH KTIDLST RDIEJ JD KTAK PDL NUYY BH ABYH KD RUCE KTHZ UC KTH EAIX. U FIDFDJH KTAK NH WDCJUEHI LJUCS KTHJH AJJHKJ AJ KTH WLK-DLKJ BHKNHHC DLI LCEHIWDMHI ASHCKJ ACE KTHUI TACEYHIJ UC KTH LX ACE DLI WDZZLCUWAKUDCJ CHKNDIX. KTHP AIH IHYAKUMHYP RIHH KD ZDMH AIDLCE KTH WDLCKIP ACE WAC HAJUYP BH KIAUCHE KD LJH EIDF-DRRJ ACE DKTHI JFPWIARK KD AYYDN KTHZ KD WDYYHWK UCKHYYUSHCWH IHFDIKJ ACE FAJJ KTHZ DC. KTH ZAIMHYYDLJ FDJKH IHJKACKH JPJKHZ AYYDNJ LJ KD WDZZLCUWAKH NUKT KTHZ, ACE A JLUKABYH WDEHBDDX NDLYE AYYDN LJ KD KIACJZUK UCJKILWKUDCJ UC FYAUC KHOK NUKT CD IUJX KTAK KTH ZHACUCS WDLYE BH EUJWHICHE BP WDLCKHIUCKHYYUSHCWH DFHIAKUMHJ UC KTH FDJKAY JHIMUWH. U TAMH ACDKTHI KTDLSTK ABDLK TDN NH ZUSTK HOFYDUK KTUJ CHKNDIX RLIKTHI, TDNHMHI U CHHE KD NDIX KTIDLST JDZH ZDIH EHKAUYJ BHRDIH U EUJWLJJ UK NUKT PDL, ACE U NACKHE KD WTHWX KTAK PDL AIH TAFFP RDI ZH KD AYYDWAKH IHJDLIWHJ KD KIAUC A CLZBHI DR TUKYHI PDLKT UC KTH IHGLUIHE JXUYYJ RDI KTUJ DFHIAKUDC. CI. diff --git a/2020/plaintext.2a.txt b/2020/plaintext.2a.txt new file mode 100644 index 0000000..40cad1b --- /dev/null +++ b/2020/plaintext.2a.txt @@ -0,0 +1 @@ +The decrypt of the first mission intercept has raised a number of questions about the spyclist operation, if that is what it is, but it has also triggered enquiries about the personnel referenced in that message. Our counterintelligence unit have asked me to task you with enquiries about the names mentioned there, in particular: Jessica; Wilhelm; Nikolaus; Tirpitzufer. It is possible that these are pseudonyms or code names, but they do not appear in our records and CI branch would be very interested in anything you can find out about them in relation to Nazi spy operations. I followed up on the SIS report that Hitler Youth groups travelling abroad were asked to complete a detailed questionnaire, checking if Harry had links that could help with this, and he sent me the attached message that was photographed by a BOSS undercover operative in Berlin. He told me that it had been exfiltrated from Abwehr headquarters and appears to be a request for approval for a new mission, though neither H nor I have had time to break it, so I look forward to receiving your decrypts. We believe the message has been enciphered using a keyword substitution cipher and given that we are not sure how serious the spyclist threat might be we would be grateful if you could decipher it quickly. The message was also a reminder to me that our own security is an important consideration, so I will also switch to a keyword substitution cipher for the next Mission Briefing. Pearl. diff --git a/2020/plaintext.2b.txt b/2020/plaintext.2b.txt new file mode 100644 index 0000000..7b70558 --- /dev/null +++ b/2020/plaintext.2b.txt @@ -0,0 +1 @@ +attention w our mission to embed sympathisers in the uk establishment is going well although the recent increase in diplomatic tension has significantly increased the risk for our agents in communicating with their handlers. with telegram traffic under enhanced supervision by the uk intelligence organisations it is also increasingly difficult for the agents and their handlers to repatriate intelligence reports of any significance. the use of banking ciphers is no longer regarded as secure and despite its obvious advantages, the enigma is too valuable to us to allow its use behind enemy lines. for now, we are encouraging our agents to use a mix of keyword and transposition ciphers as taught in their basic training, since these are reliable and do not require the agents to be in possession of more than a series of key words and phrases, which they are well able to memorise. as the quantity of signals traffic increases we will need to reconsider our protocols, but for now i think our focus should be on developing secure communication channels, with cut-outs to isolate our more valuable assets. i discussed this issue with my counterpart in department ih who is a keen cyclist and he made a rather ingenious suggestion that we might make good use of the hitler youth. a number of parties have been invited to visit the uk on cycling tours and he had been considering asking them to record information about the layout of military and industrial landmarks as part of his intelligence gathering operation. it is highly likely that any war will involve a protracted bombing campaign and up to date maps will be of great value in our planning. furthermore, the countryside road layouts in the uk are notorious for their inefficiency and any invasion, would be severely hampered by our lack of knowledge of transport networks. he had drafted an apparently rather innocuous article for the nazi cyclist association magazine with a list of things that our young cyclists might find interesting: impress on your memory the roads and paths, villages and towns, outstanding church towers and other landmarks so that you will not forget them. make a note of the names, places, rivers, seas and mountains. perhaps you may be able to utilise these some time for the benefit of the fatherland. should you come to a bridge which interests you, examine its construction and the materials used. learn to measure and estimate the width of streams. wade through fords so that you will be able to find them in the dark. i propose that we consider using these assets as the cut-outs between our undercover agents and their handlers in the uk and our communications network. they are relatively free to move around the country and can easily be trained to use drop-offs and other spycraft to allow them to collect intelligence reports and pass them on. the marvellous poste restante system allows us to communicate with them, and a suitable codebook would allow us to transmit instructions in plain text with no risk that the meaning could be discerned by counterintelligence operatives in the postal service. i have another thought about how we might exploit this network further, however i need to work through some more details before i discuss it with you, and i wanted to check that you are happy for me to allocate resources to train a number of hitler youth in the required skills for this operation. nr. -- 2.34.1 From a2e56feae1a26ca26f5f6cdf290eeab606bd99d9 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 12 Nov 2020 20:29:47 +0000 Subject: [PATCH 02/16] Done challenge 3 --- 2020/2020-a-challenge3.ipynb | 236 +++++++++++++++++++++++++++++++++++ 2020/2020-a-challenge3.md | 71 +++++++++++ 2020/challenge3-clue.ipynb | 118 ++++++++++++++++++ 2020/ciphertext.3a.txt | 6 + 2020/ciphertext.3b.txt | 7 ++ 2020/plaintext.3a.txt | 6 + 2020/plaintext.3b.txt | 7 ++ 7 files changed, 451 insertions(+) create mode 100644 2020/2020-a-challenge3.ipynb create mode 100644 2020/2020-a-challenge3.md create mode 100644 2020/challenge3-clue.ipynb create mode 100644 2020/ciphertext.3a.txt create mode 100644 2020/ciphertext.3b.txt create mode 100644 2020/plaintext.3a.txt create mode 100644 2020/plaintext.3b.txt diff --git a/2020/2020-a-challenge3.ipynb b/2020/2020-a-challenge3.ipynb new file mode 100644 index 0000000..ccb356e --- /dev/null +++ b/2020/2020-a-challenge3.ipynb @@ -0,0 +1,236 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 3\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": 5, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "sca = sanitise(ca)\n", + "cb = open(ciphertext_b_filename).read()\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "vern KeywordWrapAlphabet.from_last \n", + "\n", + "thanks to everyone for their work on the intercept, it looks really important and i have discussed the contents with harry. our sources in germany have confirmed that the nca magazine carried the instructions issued by ih and nr, and vk wrote to the chief constables of local police forces requesting them to keep an eye out for the touring groups and to report on any matters of interest. special branch are coordinating intelligence activities and forwarded a report from the local constabulary in norfolk detailing activity by one of the touring cycling parties who were seen taking photographs and sketching the landscape at caistor st edmund. the local constable questioned them, but they were not held as there were no grounds for an arrest. they had arrived at harwich and were apparently touring norfolk at the invitation of a local scout group before heading to london.\n", + "while there are significant defence installations in that area, caistor st edmund seems an unlikely target for german intelligence so perhaps this is innocent, but the evidence we have so far suggests that that is unlikely. another possibility is that it is a red herring operation disguising the activities of other groups, but just in case i will make enquiries with our sister agencies to see if there is anything we should know about in that area.\n", + "i asked our agents in norfolk to report on unusual activity and sent them a list of keywords that should trigger investigation. they forwarded the attached message addressed to tirpitzufer, which was left at the caistor st edmund post office by the local scoutmaster. it was in a bulky packet containing a number of sketches of the area together with an encrypted message which we need you to decipher quickly. analysis of other communication intercepts have suggested that this message may also contain a key to future communications across the spyclist network so you should spend some time thinking about it once you have submitted the decrypt.\n", + "while the mission of the spyclists is spelled out in detail in the last decrypt, it is still not clear what the larger aims of the abwehr mission might be, but your research into wilhelm and nikolaus has probably led you to the same conclusion as me: this is a high-level mission and is likely to pose a significant threat to our security. it follows that we should increase our own security to prevent nazi code breakers from reading our messages, so i will lengthen the keyword in my next mission briefing. i will also review our communication protocols for subsequent messages with harry and will update you on the standards to use in mission briefing 4.\n", + "the report from norfolk gave me an idea about how we could gather intelligence on the spyclist network. harry and i discussed this with vk since it carries a number of risks, but vk approved the strategy which we have given the codename the akela initiative. more to follow.\n", + "pearl\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2918" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "croatias KeywordWrapAlphabet.from_last \n", + "\n", + "gear unfle wilhelm,\n", + "i trust that you ang the camily at tirpitzucer are all well ang that you enjoyeg the sketfhes i sent you last week. i have enfloseg my most refent impressions oc the deauticul, ic somewhat stark langsfape in norcolk. i hope ang delieve that you will cing them oc breat interest. the clat ang open cielgs have a spartan deauty punftuateg dy just a cew langmarks oc gistinftion, dut their isolation makes them stang out even more ang infreases their interest.\n", + "our hosts have deen most abreeadle ang even the lofal polife corfe have deen as affommogatinb as you subbesteg they woulg de. the lofal fonstadle seemeg most interesteg in our photobraphif hoddy, dut he appeareg to de fontent with the explanation oc our interest in their deauticul fountrysige ang villabes. he was also very apprefiative oc our roubh sketfhes oc their strikinb langsfape, thoubh he gig seem surpriseg at the numder oc grawinbs we have mage oc the cielgs aroung faistor st egmung, subbestinb that its sibnicifanfe is not wigely known.\n", + "the lofal sfoutmaster abreeg to pass this messabe to you ang has also arranbeg cor our corwarg travel. we will heag next to longon to meet with my fousin nikolaus decore preparinb cor the sefong stabe oc our little agventure. ic you have any curther requests cor incormation or aggitional grawinbs in this extraorginary part oc the worlg then please go make sure to let me know decore we gepart.\n", + "let me cinish with a little puzzle cor you. fan you cing an eibht letter enblish worg whifh you fan fhanbe dy alterinb the orger oc its letters to progufe cour other giccerent enblish worgs?\n", + "yours sinferely,\n", + "otto\n", + "\n" + ] + } + ], + "source": [ + "(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams)\n", + "print(word_b, wrap_b, '\\n')\n", + "pb = keyword_decipher(cb, word_b, wrap_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "caistoruvwxyzbdefghjklmnpq \n", + "\n", + "dear uncle wilhelm,\n", + "i trust that you and the family at tirpitzufer are all well and that you enjoyed the sketches i sent you last week. i have enclosed my most recent impressions of the beautiful, if somewhat stark landscape in norfolk. i hope and believe that you will find them of great interest. the flat and open fields have a spartan beauty punctuated by just a few landmarks of distinction, but their isolation makes them stand out even more and increases their interest.\n", + "our hosts have been most agreeable and even the local police force have been as accommodating as you suggested they would be. the local constable seemed most interested in our photographic hobby, but he appeared to be content with the explanation of our interest in their beautiful countryside and villages. he was also very appreciative of our rough sketches of their striking landscape, though he did seem surprised at the number of drawings we have made of the fields around caistor st edmund, suggesting that its significance is not widely known.\n", + "the local scoutmaster agreed to pass this message to you and has also arranged for our forward travel. we will head next to london to meet with my cousin nikolaus before preparing for the second stage of our little adventure. if you have any further requests for information or additional drawings in this extraordinary part of the world then please do make sure to let me know before we depart.\n", + "let me finish with a little puzzle for you. can you find an eight letter english word which you can change by altering the order of its letters to produce four other different english words?\n", + "yours sincerely,\n", + "otto\n", + "\n" + ] + } + ], + "source": [ + "word_b, score_b = simulated_annealing_break(scb, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = keyword_decipher(cb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'dear uncle wilhelm,\\ni trust that you and the family at tirpitzufer are all well and that you enjoyed the sketches i sent you last week. i have enclosed my most recent impressions of the beautiful, if somewhat stark landscape in norfolk. i hope and believe that you will find them of great interest. the flat and open fields have a spartan beauty punctuated by just a few landmarks of distinction, but their isolation makes them stand out even more and increases their interest.\\nour hosts have been most agreeable and even the local police force have been as accommodating as you suggested they would be. the local constable seemed most interested in our photographic hobby, but he appeared to be content with the explanation of our interest in their beautiful countryside and villages. he was also very appreciative of our rough sketches of their striking landscape, though he did seem surprised at the number of drawings we have made of the fields around caistor st edmund, suggesting that its significance is not widely known.\\nthe local scoutmaster agreed to pass this message to you and has also arranged for our forward travel. we will head next to london to meet with my cousin nikolaus before preparing for the second stage of our little adventure. if you have any further requests for information or additional drawings in this extraordinary part of the world then please do make sure to let me know before we depart.\\nlet me finish with a little puzzle for you. can you find an eight letter english word which you can change by altering the order of its letters to produce four other different english words?\\nyours sincerely,\\notto\\n'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "keyword_decipher(cb, 'caistor', KeywordWrapAlphabet.from_last)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1638" + ] + }, + "execution_count": 13, + "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 +} diff --git a/2020/2020-a-challenge3.md b/2020/2020-a-challenge3.md new file mode 100644 index 0000000..05bb180 --- /dev/null +++ b/2020/2020-a-challenge3.md @@ -0,0 +1,71 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +``` + +```python Collapsed="false" +challenge_number = 3 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +sca = sanitise(ca) +cb = open(ciphertext_b_filename).read() +scb = sanitise(cb) +``` + +```python Collapsed="false" +(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams) +print(word_b, wrap_b, '\n') +pb = keyword_decipher(cb, word_b, wrap_b) +print(pb) +``` + +```python Collapsed="false" +word_b, score_b = simulated_annealing_break(scb, fitness=Ptrigrams) +print(word_b, '\n') +pb = keyword_decipher(cb, word_b) +print(pb) +``` + +```python Collapsed="false" +keyword_decipher(cb, 'caistor', KeywordWrapAlphabet.from_last) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2020/challenge3-clue.ipynb b/2020/challenge3-clue.ipynb new file mode 100644 index 0000000..ada4445 --- /dev/null +++ b/2020/challenge3-clue.ipynb @@ -0,0 +1,118 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from szyfrow.support.language_models import *\n", + "from szyfrow.support.utilities import *\n", + "import collections" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14843" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "words8 = [w for w in keywords if len(w) == 8]\n", + "len(words8)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "anags8 = collections.defaultdict(list)\n", + "for w in words8:\n", + " anags8[cat(sorted(w))] += [w]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['aegilnrt', 'aeginrst', 'deeinrst', 'ceeprsst', 'aeinrrst']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cands = [w for w in anags8 if len(anags8[w]) >= 5]\n", + "cands" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "aegilnrt ['alerting', 'altering', 'integral', 'relating', 'triangle']\n", + "aeginrst ['angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers']\n", + "deeinrst ['dniester', 'inserted', 'nerdiest', 'resident', 'trendies']\n", + "ceeprsst ['respects', 'scepters', 'sceptres', 'specters', 'spectres']\n", + "aeinrrst ['restrain', 'retrains', 'strainer', 'terrains', 'trainers']\n" + ] + } + ], + "source": [ + "for c in cands:\n", + " print(c, anags8[c])" + ] + }, + { + "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 +} diff --git a/2020/ciphertext.3a.txt b/2020/ciphertext.3a.txt new file mode 100644 index 0000000..e3cb6a4 --- /dev/null +++ b/2020/ciphertext.3a.txt @@ -0,0 +1,6 @@ +GSVZWF GA OIODLAZO PAD GSOTD JADW AZ GSO TZGODROBG, TG XAAWF DOVXXL TYBADGVZG VZN T SVIO NTFRHFFON GSO RAZGOZGF JTGS SVDDL. AHD FAHDROF TZ QODYVZL SVIO RAZPTDYON GSVG GSO ZRV YVQVMTZO RVDDTON GSO TZFGDHRGTAZF TFFHON EL TS VZN ZD, VZN IW JDAGO GA GSO RSTOP RAZFGVEXOF AP XARVX BAXTRO PADROF DOCHOFGTZQ GSOY GA WOOB VZ OLO AHG PAD GSO GAHDTZQ QDAHBF VZN GA DOBADG AZ VZL YVGGODF AP TZGODOFG. FBORTVX EDVZRS VDO RAADNTZVGTZQ TZGOXXTQOZRO VRGTITGTOF VZN PADJVDNON V DOBADG PDAY GSO XARVX RAZFGVEHXVDL TZ ZADPAXW NOGVTXTZQ VRGTITGL EL AZO AP GSO GAHDTZQ RLRXTZQ BVDGTOF JSA JODO FOOZ GVWTZQ BSAGAQDVBSF VZN FWOGRSTZQ GSO XVZNFRVBO VG RVTFGAD FG ONYHZN. GSO XARVX RAZFGVEXO CHOFGTAZON GSOY, EHG GSOL JODO ZAG SOXN VF GSODO JODO ZA QDAHZNF PAD VZ VDDOFG. GSOL SVN VDDTION VG SVDJTRS VZN JODO VBBVDOZGXL GAHDTZQ ZADPAXW VG GSO TZITGVGTAZ AP V XARVX FRAHG QDAHB EOPADO SOVNTZQ GA XAZNAZ. +JSTXO GSODO VDO FTQZTPTRVZG NOPOZRO TZFGVXXVGTAZF TZ GSVG VDOV, RVTFGAD FG ONYHZN FOOYF VZ HZXTWOXL GVDQOG PAD QODYVZ TZGOXXTQOZRO FA BODSVBF GSTF TF TZZAROZG, EHG GSO OITNOZRO JO SVIO FA PVD FHQQOFGF GSVG GSVG TF HZXTWOXL. VZAGSOD BAFFTETXTGL TF GSVG TG TF V DON SODDTZQ ABODVGTAZ NTFQHTFTZQ GSO VRGTITGTOF AP AGSOD QDAHBF, EHG UHFG TZ RVFO T JTXX YVWO OZCHTDTOF JTGS AHD FTFGOD VQOZRTOF GA FOO TP GSODO TF VZLGSTZQ JO FSAHXN WZAJ VEAHG TZ GSVG VDOV. +T VFWON AHD VQOZGF TZ ZADPAXW GA DOBADG AZ HZHFHVX VRGTITGL VZN FOZG GSOY V XTFG AP WOLJADNF GSVG FSAHXN GDTQQOD TZIOFGTQVGTAZ. GSOL PADJVDNON GSO VGGVRSON YOFFVQO VNNDOFFON GA GTDBTGMHPOD, JSTRS JVF XOPG VG GSO RVTFGAD FG ONYHZN BAFG APPTRO EL GSO XARVX FRAHGYVFGOD. TG JVF TZ V EHXWL BVRWOG RAZGVTZTZQ V ZHYEOD AP FWOGRSOF AP GSO VDOV GAQOGSOD JTGS VZ OZRDLBGON YOFFVQO JSTRS JO ZOON LAH GA NORTBSOD CHTRWXL. VZVXLFTF AP AGSOD RAYYHZTRVGTAZ TZGODROBGF SVIO FHQQOFGON GSVG GSTF YOFFVQO YVL VXFA RAZGVTZ V WOL GA PHGHDO RAYYHZTRVGTAZF VRDAFF GSO FBLRXTFG ZOGJADW FA LAH FSAHXN FBOZN FAYO GTYO GSTZWTZQ VEAHG TG AZRO LAH SVIO FHEYTGGON GSO NORDLBG. +JSTXO GSO YTFFTAZ AP GSO FBLRXTFGF TF FBOXXON AHG TZ NOGVTX TZ GSO XVFG NORDLBG, TG TF FGTXX ZAG RXOVD JSVG GSO XVDQOD VTYF AP GSO VEJOSD YTFFTAZ YTQSG EO, EHG LAHD DOFOVDRS TZGA JTXSOXY VZN ZTWAXVHF SVF BDAEVEXL XON LAH GA GSO FVYO RAZRXHFTAZ VF YO: GSTF TF V STQS-XOIOX YTFFTAZ VZN TF XTWOXL GA BAFO V FTQZTPTRVZG GSDOVG GA AHD FORHDTGL. TG PAXXAJF GSVG JO FSAHXN TZRDOVFO AHD AJZ FORHDTGL GA BDOIOZG ZVMT RANO EDOVWODF PDAY DOVNTZQ AHD YOFFVQOF, FA T JTXX XOZQGSOZ GSO WOLJADN TZ YL ZOKG YTFFTAZ EDTOPTZQ. T JTXX VXFA DOITOJ AHD RAYYHZTRVGTAZ BDAGARAXF PAD FHEFOCHOZG YOFFVQOF JTGS SVDDL VZN JTXX HBNVGO LAH AZ GSO FGVZNVDNF GA HFO TZ YTFFTAZ EDTOPTZQ 4. +GSO DOBADG PDAY ZADPAXW QVIO YO VZ TNOV VEAHG SAJ JO RAHXN QVGSOD TZGOXXTQOZRO AZ GSO FBLRXTFG ZOGJADW. SVDDL VZN T NTFRHFFON GSTF JTGS IW FTZRO TG RVDDTOF V ZHYEOD AP DTFWF, EHG IW VBBDAION GSO FGDVGOQL JSTRS JO SVIO QTIOZ GSO RANOZVYO GSO VWOXV TZTGTVGTIO. YADO GA PAXXAJ. +BOVDX diff --git a/2020/ciphertext.3b.txt b/2020/ciphertext.3b.txt new file mode 100644 index 0000000..1a9ed13 --- /dev/null +++ b/2020/ciphertext.3b.txt @@ -0,0 +1,7 @@ +STCG KBIYT MVYUTYZ, +V JGKHJ JUCJ PDK CBS JUT OCZVYP CJ JVGEVJQKOTG CGT CYY MTYY CBS JUCJ PDK TBWDPTS JUT HXTJIUTH V HTBJ PDK YCHJ MTTX. V UCLT TBIYDHTS ZP ZDHJ GTITBJ VZEGTHHVDBH DO JUT ATCKJVOKY, VO HDZTMUCJ HJCGX YCBSHICET VB BDGODYX. V UDET CBS ATYVTLT JUCJ PDK MVYY OVBS JUTZ DO RGTCJ VBJTGTHJ. JUT OYCJ CBS DETB OVTYSH UCLT C HECGJCB ATCKJP EKBIJKCJTS AP WKHJ C OTM YCBSZCGXH DO SVHJVBIJVDB, AKJ JUTVG VHDYCJVDB ZCXTH JUTZ HJCBS DKJ TLTB ZDGT CBS VBIGTCHTH JUTVG VBJTGTHJ. +DKG UDHJH UCLT ATTB ZDHJ CRGTTCAYT CBS TLTB JUT YDICY EDYVIT ODGIT UCLT ATTB CH CIIDZZDSCJVBR CH PDK HKRRTHJTS JUTP MDKYS AT. JUT YDICY IDBHJCAYT HTTZTS ZDHJ VBJTGTHJTS VB DKG EUDJDRGCEUVI UDAAP, AKJ UT CEETCGTS JD AT IDBJTBJ MVJU JUT TNEYCBCJVDB DO DKG VBJTGTHJ VB JUTVG ATCKJVOKY IDKBJGPHVST CBS LVYYCRTH. UT MCH CYHD LTGP CEEGTIVCJVLT DO DKG GDKRU HXTJIUTH DO JUTVG HJGVXVBR YCBSHICET, JUDKRU UT SVS HTTZ HKGEGVHTS CJ JUT BKZATG DO SGCMVBRH MT UCLT ZCST DO JUT OVTYSH CGDKBS ICVHJDG HJ TSZKBS, HKRRTHJVBR JUCJ VJH HVRBVOVICBIT VH BDJ MVSTYP XBDMB. +JUT YDICY HIDKJZCHJTG CRGTTS JD ECHH JUVH ZTHHCRT JD PDK CBS UCH CYHD CGGCBRTS ODG DKG ODGMCGS JGCLTY. MT MVYY UTCS BTNJ JD YDBSDB JD ZTTJ MVJU ZP IDKHVB BVXDYCKH ATODGT EGTECGVBR ODG JUT HTIDBS HJCRT DO DKG YVJJYT CSLTBJKGT. VO PDK UCLT CBP OKGJUTG GTFKTHJH ODG VBODGZCJVDB DG CSSVJVDBCY SGCMVBRH VB JUVH TNJGCDGSVBCGP ECGJ DO JUT MDGYS JUTB EYTCHT SD ZCXT HKGT JD YTJ ZT XBDM ATODGT MT STECGJ. +YTJ ZT OVBVHU MVJU C YVJJYT EKQQYT ODG PDK. ICB PDK OVBS CB TVRUJ YTJJTG TBRYVHU MDGS MUVIU PDK ICB IUCBRT AP CYJTGVBR JUT DGSTG DO VJH YTJJTGH JD EGDSKIT ODKG DJUTG SVOOTGTBJ TBRYVHU MDGSH? +PDKGH HVBITGTYP, +DJJD diff --git a/2020/plaintext.3a.txt b/2020/plaintext.3a.txt new file mode 100644 index 0000000..22efdef --- /dev/null +++ b/2020/plaintext.3a.txt @@ -0,0 +1,6 @@ +thanks to everyone for their work on the intercept, it looks really important and i have discussed the contents with harry. our sources in germany have confirmed that the nca magazine carried the instructions issued by ih and nr, and vk wrote to the chief constables of local police forces requesting them to keep an eye out for the touring groups and to report on any matters of interest. special branch are coordinating intelligence activities and forwarded a report from the local constabulary in norfolk detailing activity by one of the touring cycling parties who were seen taking photographs and sketching the landscape at caistor st edmund. the local constable questioned them, but they were not held as there were no grounds for an arrest. they had arrived at harwich and were apparently touring norfolk at the invitation of a local scout group before heading to london. +while there are significant defence installations in that area, caistor st edmund seems an unlikely target for german intelligence so perhaps this is innocent, but the evidence we have so far suggests that that is unlikely. another possibility is that it is a red herring operation disguising the activities of other groups, but just in case i will make enquiries with our sister agencies to see if there is anything we should know about in that area. +i asked our agents in norfolk to report on unusual activity and sent them a list of keywords that should trigger investigation. they forwarded the attached message addressed to tirpitzufer, which was left at the caistor st edmund post office by the local scoutmaster. it was in a bulky packet containing a number of sketches of the area together with an encrypted message which we need you to decipher quickly. analysis of other communication intercepts have suggested that this message may also contain a key to future communications across the spyclist network so you should spend some time thinking about it once you have submitted the decrypt. +while the mission of the spyclists is spelled out in detail in the last decrypt, it is still not clear what the larger aims of the abwehr mission might be, but your research into wilhelm and nikolaus has probably led you to the same conclusion as me: this is a high-level mission and is likely to pose a significant threat to our security. it follows that we should increase our own security to prevent nazi code breakers from reading our messages, so i will lengthen the keyword in my next mission briefing. i will also review our communication protocols for subsequent messages with harry and will update you on the standards to use in mission briefing 4. +the report from norfolk gave me an idea about how we could gather intelligence on the spyclist network. harry and i discussed this with vk since it carries a number of risks, but vk approved the strategy which we have given the codename the akela initiative. more to follow. +pearl diff --git a/2020/plaintext.3b.txt b/2020/plaintext.3b.txt new file mode 100644 index 0000000..db41750 --- /dev/null +++ b/2020/plaintext.3b.txt @@ -0,0 +1,7 @@ +dear uncle wilhelm, +i trust that you and the family at tirpitzufer are all well and that you enjoyed the sketches i sent you last week. i have enclosed my most recent impressions of the beautiful, if somewhat stark landscape in norfolk. i hope and believe that you will find them of great interest. the flat and open fields have a spartan beauty punctuated by just a few landmarks of distinction, but their isolation makes them stand out even more and increases their interest. +our hosts have been most agreeable and even the local police force have been as accommodating as you suggested they would be. the local constable seemed most interested in our photographic hobby, but he appeared to be content with the explanation of our interest in their beautiful countryside and villages. he was also very appreciative of our rough sketches of their striking landscape, though he did seem surprised at the number of drawings we have made of the fields around caistor st edmund, suggesting that its significance is not widely known. +the local scoutmaster agreed to pass this message to you and has also arranged for our forward travel. we will head next to london to meet with my cousin nikolaus before preparing for the second stage of our little adventure. if you have any further requests for information or additional drawings in this extraordinary part of the world then please do make sure to let me know before we depart. +let me finish with a little puzzle for you. can you find an eight letter english word which you can change by altering the order of its letters to produce four other different english words? +yours sincerely, +otto -- 2.34.1 From 7bb04bb89765b97ea35c70ebcb26f7301107d5ce Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 19 Nov 2020 16:49:26 +0000 Subject: [PATCH 03/16] Done challenge 4 --- 2020/2020-a-challenge4.ipynb | 434 +++++++++++++++++++++++++++++++++++ 2020/2020-a-challenge4.md | 99 ++++++++ 2020/challenge3-clue.ipynb | 54 ++++- 2020/ciphertext.4a.txt | 11 + 2020/ciphertext.4b.txt | 1 + 2020/plaintext.4a.txt | 11 + 2020/plaintext.4b.txt | 18 ++ 7 files changed, 618 insertions(+), 10 deletions(-) create mode 100644 2020/2020-a-challenge4.ipynb create mode 100644 2020/2020-a-challenge4.md create mode 100644 2020/ciphertext.4a.txt create mode 100644 2020/ciphertext.4b.txt create mode 100644 2020/plaintext.4a.txt create mode 100644 2020/plaintext.4b.txt diff --git a/2020/2020-a-challenge4.ipynb b/2020/2020-a-challenge4.ipynb new file mode 100644 index 0000000..19f01c1 --- /dev/null +++ b/2020/2020-a-challenge4.ipynb @@ -0,0 +1,434 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.support.text_prettify import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 4\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": 3, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "sca = sanitise(ca)\n", + "cb = open(ciphertext_b_filename).read()\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "akkad KeywordWrapAlphabet.from_largest \n", + "\n", + "i have drawn a blank in my enqciries aboct uaistor st edmcnd and even harry is getting nowhere with his uontauts in the mod. we both agree that the silenue is very worrying. this is ulearly an area of interest as it presents a urcuial front in any potential invasion so we wocld have expeuted some interest in ocr intelligenue, or at least some pcsh bauk warning cs to keep away from basiu defenue installations like listening posts. the faut that no-one wants to talk aboct the fauilities in the area scggests that it is all very hcsh hcsh. something important is happening there and we probably want to find oct what.\n", + "\n", + "ocr agents in london kept watuh for the tocring party and reuorded them as arriving at liverpool street. the grocp uonsisted of twenty three uyulists who split cp and stayed with members of loual suoct grocps while their leader was hosted by a member of the loual ortsgrcppe. we reueived reports from k's network that the grocp has been invited to stay with the spalding rotary ulcb in linuoln and we need yoc to investigate any reports yoc uan find aboct that visit. i will uontince to press for information aboct strategiu developments in norwiuh and norfolk.\n", + "\n", + "the akela initiative has been given approval and i will be setting that cp this week. the intention is to enroll leaders and members of loual suoct grocps, train them in uocnter-intelligenue and cse them to host the spyulist tocring grocps in the hope of getting inside their operation. sinue fctcre uommcniuations may inulcde sensitive operational details of this initiative i intend to inurease seucrity by moving to a blouked keyword uipher.\n", + "\n", + "the attauhed doucment was interuepted by ocr london agents when the party posted it on arrival at liverpool street. as cscal it was addressed to tirpitzcfer. primary analysis scggests that it does not cse a scbstitction uipher.\n", + "\n", + "more to follow.\n", + "\n", + "pearl.\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "akelmnopqrstuvwxyzbcdfghij \n", + "\n", + "i have drawn a blank in my enquiries about caistor st edmund and even harry is getting nowhere with his contacts in the mod. we both agree that the silence is very worrying. this is clearly an area of interest as it presents a crucial front in any potential invasion so we would have expected some interest in our intelligence, or at least some push back warning us to keep away from basic defence installations like listening posts. the fact that no-one wants to talk about the facilities in the area suggests that it is all very hush hush. something important is happening there and we probably want to find out what.\n", + "\n", + "our agents in london kept watch for the touring party and recorded them as arriving at liverpool street. the group consisted of twenty three cyclists who split up and stayed with members of local scout groups while their leader was hosted by a member of the local ortsgruppe. we received reports from k's network that the group has been invited to stay with the spalding rotary club in lincoln and we need you to investigate any reports you can find about that visit. i will continue to press for information about strategic developments in norwich and norfolk.\n", + "\n", + "the akela initiative has been given approval and i will be setting that up this week. the intention is to enroll leaders and members of local scout groups, train them in counter-intelligence and use them to host the spyclist touring groups in the hope of getting inside their operation. since future communications may include sensitive operational details of this initiative i intend to increase security by moving to a blocked keyword cipher.\n", + "\n", + "the attached document was intercepted by our london agents when the party posted it on arrival at liverpool street. as usual it was addressed to tirpitzufer. primary analysis suggests that it does not use a substitution cipher.\n", + "\n", + "more to follow.\n", + "\n", + "pearl.\n", + "\n" + ] + } + ], + "source": [ + "word_a, score_a = simulated_annealing_break(sca, fitness=Ptrigrams,\n", + " plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('akkad', wrap_alphabet=KeywordWrapAlphabet.from_largest))\n", + "print(word_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i have drawn a blank in my enquiries about caistor st edmund and even harry is getting nowhere with his contacts in the mod. we both agree that the silence is very worrying. this is clearly an area of interest as it presents a crucial front in any potential invasion so we would have expected some interest in our intelligence, or at least some push back warning us to keep away from basic defence installations like listening posts. the fact that no-one wants to talk about the facilities in the area suggests that it is all very hush hush. something important is happening there and we probably want to find out what.\n", + "\n", + "our agents in london kept watch for the touring party and recorded them as arriving at liverpool street. the group consisted of twenty three cyclists who split up and stayed with members of local scout groups while their leader was hosted by a member of the local ortsgruppe. we received reports from k's network that the group has been invited to stay with the spalding rotary club in lincoln and we need you to investigate any reports you can find about that visit. i will continue to press for information about strategic developments in norwich and norfolk.\n", + "\n", + "the akela initiative has been given approval and i will be setting that up this week. the intention is to enroll leaders and members of local scout groups, train them in counter-intelligence and use them to host the spyclist touring groups in the hope of getting inside their operation. since future communications may include sensitive operational details of this initiative i intend to increase security by moving to a blocked keyword cipher.\n", + "\n", + "the attached document was intercepted by our london agents when the party posted it on arrival at liverpool street. as usual it was addressed to tirpitzufer. primary analysis suggests that it does not use a substitution cipher.\n", + "\n", + "more to follow.\n", + "\n", + "pearl.\n", + "\n" + ] + } + ], + "source": [ + "pa = keyword_decipher(ca, 'akela', wrap_alphabet=KeywordWrapAlphabet.from_largest)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1883" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "clue_dict = ['alerting', 'altering', 'integral', 'relating', 'triangle', 'angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers', \n", + " 'dniester', 'inserted', 'nerdiest', 'resident', 'trendies', 'respects', 'scepters', 'sceptres', 'specters', 'spectres', 'restrain', \n", + " 'retrains', 'strainer', 'terrains', 'trainers']\n", + "clue_trans = [transpositions_of(w) for w in clue_dict]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 2, 3, 5, 0, 4) True False \n", + "\n", + "REERNLNHNRTAANNBSCROIAUSHOALISICTETSIEAARASTSOSLNOIOOWESEIOGMHISTXDIEGEAGATTADRVSICAYSITREARESOFNCFFWPNSPPTNTAELHYBNRRAMNSMSXOENGPNINFAFOGDLOMENOORHNTNERMTATFTWATFAESOGRYNCSHSENTEDAOTRKIBPPARHCERRTTHNNTGIREITMVHEDCONTCTUWPDOIROENHEGIKIATNCWLNODRSSNTEOGAFREBTAEHOLWHOSSITPTRNCUNLECLOUTDSTHNTSLLHTRTGNDCRERSESALLBEOCOAUEOEOUAEHIDVADSAHETISIVTGLNNESTTPCIWUFRAETIRHIIWFLEREYTEEOKHYRFOTIRERNERTSFIILFCINYTSALGAHHSDIVSLLSUTWSTELNPOOSISOSHAYNEGNLOGTORDTHTRRORRSDISUEOEIALSTKGASPUNBNLUMYIIBSIELHEEAIGIRISSCRCVNATGTYIOIAIUTTEANNNURSCMMHEEAPEOIRIRTESOODTHILWCESTTYSRALHUROOSAAGRRIOEIAHHFSOYTRMATSEAUSNKVVSWTLSNTDONOENFTYMRHTCNETHLDEWWHSPHNSTALNIIEEETTAFTASSFHASRAEOSEPUEOXAOOHHTTTNIEENYAIOYATVIEIISEOLIYGEIEIROTPUTASARUETHONOIPNIHUUTOEHIUNTUWISTNRYNSREAOUNCTEMFEIFGEISNRHOCYORTRLANATASOYHIFTHHHAGMNTNMWOICTPIRAEEAIARNNLDUNYFEHRYURTOONDIONTAOOIEUWLJEOWODMHITGGRHKOPENNIEAYMMANETIRPDRBYACCRPUTOHRSRSIMOBSUMEOWPHTATORENNBHHNTAIHNALIDCOOLWOPUFODIFAEOIFELITHNBEEAEOSTNIDIERILBDOAQTEVGEUEWLUEIDSRBEDEDAETHVBOTISHTTNTMEWOSTFEEDCODTDUMEATLISLOETVOLSHIJGETTASAHEIEBIHFSERHNHREROOUDDTTTTYGNATOHAGWIVISGTACENOIRUHRNAUDAEUTPNHYPETSRCY \n", + "DNIMOYNARCIENTATITSUELDTDIDBOPBPSHRAREYLTVROYERSNAGEUTTBFRHTONUIEEFYHRUXGEOEEDHCTETPCTIUTUVAMLRNLTTERRRTONOOHEDUOCSRFAAOTINWENEETSNUISIEASSEURHNOUTRRSRTSTHEEERELSESYTEETIUTIOIAIARMHISEMBIECISSSREMIEOAOLNOIDPLESCYUNATMROETIOIMNUTANSHHHOHTKOUENONOIAUTHRHSNRTATEEPPCFRMRSAGASOSEESE\n" + ] + } + ], + "source": [ + "(trans_b, fill_b, empty_b), score_b = column_transposition_break(scb, translist=clue_trans, fitness=Ptrigrams)\n", + "print(trans_b, fill_b, empty_b, '\\n')\n", + "pb = column_transposition_decipher(cb, trans_b, \n", + " fillcolumnwise=fill_b,\n", + " emptycolumnwise=empty_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 2, 4, 0, 3) False False \n", + "\n" + ] + } + ], + "source": [ + "(trans_b, fill_b, empty_b), score_b = column_transposition_break(scb, fitness=Ptrigrams)\n", + "print(trans_b, fill_b, empty_b, '\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dear uncle wilhelm our journey to london was short and charming the trains rattling along the\n", + "british tracks through open fields and countryside their roads maybe almost impassable in places but\n", + "these iron tracks provide a very usable way to travel across country at speed our hosts in london\n", + "have organised for us to stay with members of the british scouting movement though i will spend the\n", + "next few days with the orts gruppe exchanging news about the fatherland and their activities herein\n", + "the capital city it was difficult to tear ourselves away from the pleasures of norfolk and the city\n", + "offers far fewer opportunities for open exploration on the other hand the bustle of the city as in\n", + "berlin offers a certain anonymity and it is in some ways relaxing to leave behind the gossip and\n", + "inquisitiveness of village life as you suggested we will use our time herein london to support our\n", + "brothers and sisters and to reassure them that they have not been forgotten i will pass on the gifts\n", + "that you entrusted to me together with your instructions for their use as we did in caistor st\n", + "edmund the radio you sent me is remarkable it is able to pickup signals across the spectrum even\n", + "from berlin itself though i am enjoying listening to british radio especially the home service they\n", + "are building a chain of transmitters across the country which provide information throughout the day\n", + "and night something that i think you might want to take into account when planning our own radio\n", + "services i am assuming that there are no changes planned for our itinerary but if there are then\n", + "perhaps you could forward them to our hosts in spalding with a copy sent post restante to cse yours\n", + "sincerely\n" + ] + } + ], + "source": [ + "pb = prettify(column_transposition_decipher(scb, trans_b, \n", + " fillcolumnwise=fill_b,\n", + " emptycolumnwise=empty_b))\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['fable',\n", + " 'gable',\n", + " 'nacre',\n", + " 'nahum',\n", + " 'oakum',\n", + " 'odium',\n", + " 'padre',\n", + " 'pinto',\n", + " 'salvo',\n", + " 'santo',\n", + " 'scour',\n", + " 'tabus',\n", + " 'tagus',\n", + " 'talus',\n", + " 'thous',\n", + " 'timur',\n", + " 'torus',\n", + " 'torys',\n", + " 'whizs',\n", + " 'gabble',\n", + " 'kabuki',\n", + " 'lactic',\n", + " 'ladoga',\n", + " 'leftie',\n", + " 'madrid',\n", + " 'megohm',\n", + " 'oberon',\n", + " 'raisin',\n", + " 'refuel',\n", + " 'refuge',\n", + " 'salvos',\n", + " 'santos',\n", + " 'scours',\n", + " 'tabbys',\n", + " 'tabula',\n", + " 'taffys',\n", + " 'taguss',\n", + " 'taiwan',\n", + " 'tallys',\n", + " 'tammys',\n", + " 'tanyas',\n", + " 'telexs',\n", + " 'tenure',\n", + " 'terrys',\n", + " 'tethys',\n", + " 'thrush',\n", + " 'thrust',\n", + " 'timmys',\n", + " 'toruss',\n", + " 'velezs',\n", + " 'vilyui',\n", + " 'weepys',\n", + " 'whizzs',\n", + " 'willys',\n", + " 'worrys',\n", + " 'lactate',\n", + " 'macrame',\n", + " 'palazzo',\n", + " 'raisins',\n", + " 'raritan',\n", + " 'refresh',\n", + " 'refugee',\n", + " 'sabbath',\n", + " 'salazar',\n", + " 'sinuous',\n", + " 'tactual',\n", + " 'tarawas',\n", + " 'telexes',\n", + " 'tethyss',\n", + " 'thrushs',\n", + " 'thrusts',\n", + " 'maharaja',\n", + " 'nakayama',\n", + " 'ramayana',\n", + " 'sabbaths',\n", + " 'salazars',\n", + " 'semester',\n", + " 'sensuous',\n", + " 'teletype',\n", + " 'tortuous',\n", + " 'maharajah',\n", + " 'refresher',\n", + " 'refreshes',\n", + " 'semesters',\n", + " 'refreshers',\n", + " 'sensuousness',\n", + " 'sensuousnesss']" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transpositions[trans_b]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1685" + ] + }, + "execution_count": 21, + "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 +} diff --git a/2020/2020-a-challenge4.md b/2020/2020-a-challenge4.md new file mode 100644 index 0000000..032af74 --- /dev/null +++ b/2020/2020-a-challenge4.md @@ -0,0 +1,99 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.support.text_prettify import * +``` + +```python Collapsed="false" +challenge_number = 4 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +sca = sanitise(ca) +cb = open(ciphertext_b_filename).read() +scb = sanitise(cb) +``` + +```python Collapsed="false" +(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python Collapsed="false" +word_a, score_a = simulated_annealing_break(sca, fitness=Ptrigrams, + plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('akkad', wrap_alphabet=KeywordWrapAlphabet.from_largest)) +print(word_a, '\n') +pa = keyword_decipher(ca, word_a) +print(pa) +``` + +```python Collapsed="false" +pa = keyword_decipher(ca, 'akela', wrap_alphabet=KeywordWrapAlphabet.from_largest) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +clue_dict = ['alerting', 'altering', 'integral', 'relating', 'triangle', 'angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers', + 'dniester', 'inserted', 'nerdiest', 'resident', 'trendies', 'respects', 'scepters', 'sceptres', 'specters', 'spectres', 'restrain', + 'retrains', 'strainer', 'terrains', 'trainers'] +clue_trans = [transpositions_of(w) for w in clue_dict] +``` + +```python Collapsed="false" +(trans_b, fill_b, empty_b), score_b = column_transposition_break(scb, translist=clue_trans, fitness=Ptrigrams) +print(trans_b, fill_b, empty_b, '\n') +pb = column_transposition_decipher(cb, trans_b, + fillcolumnwise=fill_b, + emptycolumnwise=empty_b) +print(pb) +``` + +```python Collapsed="false" +(trans_b, fill_b, empty_b), score_b = column_transposition_break(scb, fitness=Ptrigrams) +print(trans_b, fill_b, empty_b, '\n') +``` + +```python Collapsed="false" +pb = prettify(column_transposition_decipher(scb, trans_b, + fillcolumnwise=fill_b, + emptycolumnwise=empty_b)) +print(pb) +``` + +```python Collapsed="false" +transpositions[trans_b] +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2020/challenge3-clue.ipynb b/2020/challenge3-clue.ipynb index ada4445..a79b199 100644 --- a/2020/challenge3-clue.ipynb +++ b/2020/challenge3-clue.ipynb @@ -3,7 +3,9 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "Collapsed": "false" + }, "outputs": [], "source": [ "from szyfrow.support.language_models import *\n", @@ -14,7 +16,9 @@ { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "Collapsed": "false" + }, "outputs": [ { "data": { @@ -34,8 +38,10 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, + "execution_count": 3, + "metadata": { + "Collapsed": "false" + }, "outputs": [], "source": [ "anags8 = collections.defaultdict(list)\n", @@ -45,8 +51,10 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": {}, + "execution_count": 4, + "metadata": { + "Collapsed": "false" + }, "outputs": [ { "data": { @@ -54,7 +62,7 @@ "['aegilnrt', 'aeginrst', 'deeinrst', 'ceeprsst', 'aeinrrst']" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -66,8 +74,10 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": {}, + "execution_count": 5, + "metadata": { + "Collapsed": "false" + }, "outputs": [ { "name": "stdout", @@ -86,10 +96,34 @@ " print(c, anags8[c])" ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"alerting', 'altering', 'integral', 'relating', 'triangle', 'angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers', 'dniester', 'inserted', 'nerdiest', 'resident', 'trendies', 'respects', 'scepters', 'sceptres', 'specters', 'spectres', 'restrain', 'retrains', 'strainer', 'terrains', 'trainers\"" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"', '\".join(w for c in cands for w in anags8[c])" + ] + }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "Collapsed": "false" + }, "outputs": [], "source": [] } diff --git a/2020/ciphertext.4a.txt b/2020/ciphertext.4a.txt new file mode 100644 index 0000000..0d2f887 --- /dev/null +++ b/2020/ciphertext.4a.txt @@ -0,0 +1,11 @@ +Q PAFM LZAGV A KTAVS QV UI MVYDQZQMB AKWDC EAQBCWZ BC MLUDVL AVL MFMV PAZZI QB OMCCQVO VWGPMZM GQCP PQB EWVCAECB QV CPM UWL. GM KWCP AOZMM CPAC CPM BQTMVEM QB FMZI GWZZIQVO. CPQB QB ETMAZTI AV AZMA WN QVCMZMBC AB QC XZMBMVCB A EZDEQAT NZWVC QV AVI XWCMVCQAT QVFABQWV BW GM GWDTL PAFM MHXMECML BWUM QVCMZMBC QV WDZ QVCMTTQOMVEM, WZ AC TMABC BWUM XDBP KAES GAZVQVO DB CW SMMX AGAI NZWU KABQE LMNMVEM QVBCATTACQWVB TQSM TQBCMVQVO XWBCB. CPM NAEC CPAC VW-WVM GAVCB CW CATS AKWDC CPM NAEQTQCQMB QV CPM AZMA BDOOMBCB CPAC QC QB ATT FMZI PDBP PDBP. BWUMCPQVO QUXWZCAVC QB PAXXMVQVO CPMZM AVL GM XZWKAKTI GAVC CW NQVL WDC GPAC. + +WDZ AOMVCB QV TWVLWV SMXC GACEP NWZ CPM CWDZQVO XAZCI AVL ZMEWZLML CPMU AB AZZQFQVO AC TQFMZXWWT BCZMMC. CPM OZWDX EWVBQBCML WN CGMVCI CPZMM EIETQBCB GPW BXTQC DX AVL BCAIML GQCP UMUKMZB WN TWEAT BEWDC OZWDXB GPQTM CPMQZ TMALMZ GAB PWBCML KI A UMUKMZ WN CPM TWEAT WZCBOZDXXM. GM ZMEMQFML ZMXWZCB NZWU S'B VMCGWZS CPAC CPM OZWDX PAB KMMV QVFQCML CW BCAI GQCP CPM BXATLQVO ZWCAZI ETDK QV TQVEWTV AVL GM VMML IWD CW QVFMBCQOACM AVI ZMXWZCB IWD EAV NQVL AKWDC CPAC FQBQC. Q GQTT EWVCQVDM CW XZMBB NWZ QVNWZUACQWV AKWDC BCZACMOQE LMFMTWXUMVCB QV VWZGQEP AVL VWZNWTS. + +CPM ASMTA QVQCQACQFM PAB KMMV OQFMV AXXZWFAT AVL Q GQTT KM BMCCQVO CPAC DX CPQB GMMS. CPM QVCMVCQWV QB CW MVZWTT TMALMZB AVL UMUKMZB WN TWEAT BEWDC OZWDXB, CZAQV CPMU QV EWDVCMZ-QVCMTTQOMVEM AVL DBM CPMU CW PWBC CPM BXIETQBC CWDZQVO OZWDXB QV CPM PWXM WN OMCCQVO QVBQLM CPMQZ WXMZACQWV. BQVEM NDCDZM EWUUDVQEACQWVB UAI QVETDLM BMVBQCQFM WXMZACQWVAT LMCAQTB WN CPQB QVQCQACQFM Q QVCMVL CW QVEZMABM BMEDZQCI KI UWFQVO CW A KTWESML SMIGWZL EQXPMZ. + +CPM ACCAEPML LWEDUMVC GAB QVCMZEMXCML KI WDZ TWVLWV AOMVCB GPMV CPM XAZCI XWBCML QC WV AZZQFAT AC TQFMZXWWT BCZMMC. AB DBDAT QC GAB ALLZMBBML CW CQZXQCJDNMZ. XZQUAZI AVATIBQB BDOOMBCB CPAC QC LWMB VWC DBM A BDKBCQCDCQWV EQXPMZ. + +UWZM CW NWTTWG. + +XMAZT. diff --git a/2020/ciphertext.4b.txt b/2020/ciphertext.4b.txt new file mode 100644 index 0000000..84feab4 --- /dev/null +++ b/2020/ciphertext.4b.txt @@ -0,0 +1 @@ +EAUDR CLWNE LHLIE OUJMR UREON TOOYL DOWNN SSOAH TADRN HAMCR NGHIT TRIEA SRTNA LIGTN LOGAN HERTB TIHIS RAKTC THOSR GHPUO NFEEI DSNLA CONDU RYITS ETEDH RRAIO SMYDA EAMBL STMOI ASAPS LENBI LAEPC BUTST ESIHE ONRRT CKPAS OVDRI AVREE USBYA EWYLA OTATR ELCVA OSCRS UNROT ATPYS EDUEO HOTRS INOSL DOHNN VERAO ANSGI DFREO STSUO AYITW HMMTE EROBS THBFE ITSRI SCUHO INMTG VEEOM TTONH GHWUI LLPIS NDHET NETEX EWAFD SWTYI THOHE TSRRG PPEUE CHNXA INNGG WSBEA UTHOT FAHET RLNEA ANTDD EIAHR TIICV IEHTS RENEI HEATC ITLPA ITICY WADTS FFCII LTOUT EAOTR RSLUE ESWVA YFOAR THPME EAULS ESFRO ORONF KADLN HEITC YOFTF RSAEF FEERW OPORP TUIRN IEFTS ROEOP EXLNP RAIOT NOTON EOHHT RHNEA THBDE STEUL FTEOH ITACY INESB LIORN FESFR CETAR INNAA NYIOM YADTN TIIIS SOENM AYRWS LAIEX GTLNO AVBEE HIDEN HEOTG SIASP DIQNN ISTUI VEEIN SOVSF LLGIA LIEEF SYUAO UGESG TEWSD WILEL SEUUO TIERM ERIHE LODNN NTSOO PPRUO OUBTR OTERH SADRN ISEST SADRN ORATE SUESR HETTM ATHHT YHVEA NOBET ENOEF GOTRT NIIEW LPSLA ONHST GITEF THTSA OUNYE RUTTS DTMEO TOEEG HEWTR THOIY RISUN RUTTC ONFIS RTEOH RUEIS SWDAE DICIN ISOAT STDRE UNTMD ERDHA OYUIO ENMST ISEER ARAMK LETBI SALIB TOIEP KUSCP GNLIA ACOSR STESH PETSC UMVRE NFOER BELMR NISIT LFHET UGIOH MEJAN YIGON ISELT INTNG BRTOI SHAIR IOSDE ECAPI LYHLT HOEEM ERISV ETECH ARBYE ILIUD GAHNC INFAO RASTN ITEMT SARRC SSHOT CONEU RYHTW CHRIP VIEOD NFRIO ATOMI THONR GHUUO THDTE YADAN IGTNH OMTSE INTHG ATTHI INYHK UMGOI TWNHA TOATT EITKN ACOOC NTHUW NPAEL NIGNN URWOO RAIND SEVOR CEIIS MASAS MIGUN HATTT ERAHE ENCRO ANEHG PLNSA EDONF OUIRR INRTE RYUAB IFHTT REREA THNEE ERAPH SYUPO OUDCL ORAFW DTERH TOUMO HOTRS INPSS LDNAI WIHGT COYAP ENPST STEOR TATSN TOSEC YOREU SICSN REYEL diff --git a/2020/plaintext.4a.txt b/2020/plaintext.4a.txt new file mode 100644 index 0000000..2de18c2 --- /dev/null +++ b/2020/plaintext.4a.txt @@ -0,0 +1,11 @@ +i have drawn a blank in my enquiries about caistor st edmund and even harry is getting nowhere with his contacts in the mod. we both agree that the silence is very worrying. this is clearly an area of interest as it presents a crucial front in any potential invasion so we would have expected some interest in our intelligence, or at least some push back warning us to keep away from basic defence installations like listening posts. the fact that no-one wants to talk about the facilities in the area suggests that it is all very hush hush. something important is happening there and we probably want to find out what. + +our agents in london kept watch for the touring party and recorded them as arriving at liverpool street. the group consisted of twenty three cyclists who split up and stayed with members of local scout groups while their leader was hosted by a member of the local ortsgruppe. we received reports from k's network that the group has been invited to stay with the spalding rotary club in lincoln and we need you to investigate any reports you can find about that visit. i will continue to press for information about strategic developments in norwich and norfolk. + +the akela initiative has been given approval and i will be setting that up this week. the intention is to enroll leaders and members of local scout groups, train them in counter-intelligence and use them to host the spyclist touring groups in the hope of getting inside their operation. since future communications may include sensitive operational details of this initiative i intend to increase security by moving to a blocked keyword cipher. + +the attached document was intercepted by our london agents when the party posted it on arrival at liverpool street. as usual it was addressed to tirpitzufer. primary analysis suggests that it does not use a substitution cipher. + +more to follow. + +pearl. diff --git a/2020/plaintext.4b.txt b/2020/plaintext.4b.txt new file mode 100644 index 0000000..51f55ce --- /dev/null +++ b/2020/plaintext.4b.txt @@ -0,0 +1,18 @@ +dear uncle wilhelm our journey to london was short and charming the trains rattling along the +british tracks through open fields and countryside their roads maybe almost impassable in places but +these iron tracks provide a very usable way to travel across country at speed our hosts in london +have organised for us to stay with members of the british scouting movement though i will spend the +next few days with the orts gruppe exchanging news about the fatherland and their activities herein +the capital city it was difficult to tear ourselves away from the pleasures of norfolk and the city +offers far fewer opportunities for open exploration on the other hand the bustle of the city as in +berlin offers a certain anonymity and it is in some ways relaxing to leave behind the gossip and +inquisitiveness of village life as you suggested we will use our time herein london to support our +brothers and sisters and to reassure them that they have not been forgotten i will pass on the gifts +that you entrusted to me together with your instructions for their use as we did in caistor st +edmund the radio you sent me is remarkable it is able to pickup signals across the spectrum even +from berlin itself though i am enjoying listening to british radio especially the home service they +are building a chain of transmitters across the country which provide information throughout the day +and night something that i think you might want to take into account when planning our own radio +services i am assuming that there are no changes planned for our itinerary but if there are then +perhaps you could forward them to our hosts in spalding with a copy sent post restante to cse yours +sincerely \ No newline at end of file -- 2.34.1 From fb27ec808421a2bd8dd5c253138a23db12a9aefa Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 26 Nov 2020 15:54:36 +0000 Subject: [PATCH 04/16] Done challenge 5 --- ...challenge1.ipynb => 2020-challenge1.ipynb} | 0 ...020-a-challenge1.md => 2020-challenge1.md} | 0 ...challenge2.ipynb => 2020-challenge2.ipynb} | 0 ...020-a-challenge2.md => 2020-challenge2.md} | 0 ...challenge3.ipynb => 2020-challenge3.ipynb} | 0 ...020-a-challenge3.md => 2020-challenge3.md} | 0 ...challenge4.ipynb => 2020-challenge4.ipynb} | 0 ...020-a-challenge4.md => 2020-challenge4.md} | 0 2020/2020-challenge5.ipynb | 593 ++++++++++++++++++ 2020/2020-challenge5.md | 107 ++++ 2020/ciphertext.5a.txt | 1 + 2020/ciphertext.5b.txt | 1 + 2020/plaintext.5a.txt | 1 + 2020/plaintext.5b.txt | 19 + 14 files changed, 722 insertions(+) rename 2020/{2020-a-challenge1.ipynb => 2020-challenge1.ipynb} (100%) rename 2020/{2020-a-challenge1.md => 2020-challenge1.md} (100%) rename 2020/{2020-a-challenge2.ipynb => 2020-challenge2.ipynb} (100%) rename 2020/{2020-a-challenge2.md => 2020-challenge2.md} (100%) rename 2020/{2020-a-challenge3.ipynb => 2020-challenge3.ipynb} (100%) rename 2020/{2020-a-challenge3.md => 2020-challenge3.md} (100%) rename 2020/{2020-a-challenge4.ipynb => 2020-challenge4.ipynb} (100%) rename 2020/{2020-a-challenge4.md => 2020-challenge4.md} (100%) create mode 100644 2020/2020-challenge5.ipynb create mode 100644 2020/2020-challenge5.md create mode 100644 2020/ciphertext.5a.txt create mode 100644 2020/ciphertext.5b.txt create mode 100644 2020/plaintext.5a.txt create mode 100644 2020/plaintext.5b.txt diff --git a/2020/2020-a-challenge1.ipynb b/2020/2020-challenge1.ipynb similarity index 100% rename from 2020/2020-a-challenge1.ipynb rename to 2020/2020-challenge1.ipynb diff --git a/2020/2020-a-challenge1.md b/2020/2020-challenge1.md similarity index 100% rename from 2020/2020-a-challenge1.md rename to 2020/2020-challenge1.md diff --git a/2020/2020-a-challenge2.ipynb b/2020/2020-challenge2.ipynb similarity index 100% rename from 2020/2020-a-challenge2.ipynb rename to 2020/2020-challenge2.ipynb diff --git a/2020/2020-a-challenge2.md b/2020/2020-challenge2.md similarity index 100% rename from 2020/2020-a-challenge2.md rename to 2020/2020-challenge2.md diff --git a/2020/2020-a-challenge3.ipynb b/2020/2020-challenge3.ipynb similarity index 100% rename from 2020/2020-a-challenge3.ipynb rename to 2020/2020-challenge3.ipynb diff --git a/2020/2020-a-challenge3.md b/2020/2020-challenge3.md similarity index 100% rename from 2020/2020-a-challenge3.md rename to 2020/2020-challenge3.md diff --git a/2020/2020-a-challenge4.ipynb b/2020/2020-challenge4.ipynb similarity index 100% rename from 2020/2020-a-challenge4.ipynb rename to 2020/2020-challenge4.ipynb diff --git a/2020/2020-a-challenge4.md b/2020/2020-challenge4.md similarity index 100% rename from 2020/2020-a-challenge4.md rename to 2020/2020-challenge4.md diff --git a/2020/2020-challenge5.ipynb b/2020/2020-challenge5.ipynb new file mode 100644 index 0000000..0023d1c --- /dev/null +++ b/2020/2020-challenge5.ipynb @@ -0,0 +1,593 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.support.text_prettify import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 5\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": 3, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "sca = sanitise(ca)\n", + "cb = open(ciphertext_b_filename).read()\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "aile KeywordWrapAlphabet.from_a \n", + "\n", + "whike wecic notha vetim etopk adean ytrai necag entsw ithth ekonc onsdo utgro upsth eabek aoper ation cicma naget oredr uitan clrie fseve rakme mlers ofthe kindo knsdo uting assod iatio nanco neoft hemha smace amajo rlrea bthro ughsp ottin gsome thing thato urreg ukara gents hacno tnoti decth ekonc onpar tydon siste coftw entyt hreed ydkis tslut thegr oupar rivin ginki ndokn hacon kytwe ntyme mlers atfir stias sumec hehac misdo untec lutth ephot ograp hinth ekoda kpape raddo mpany ingth eirre porto nthev isitd onfir mecth enuml eriwi kkmab eenqu iries witho urkon conag entst oseei fthey havea nythi ngont heoth erthr eeanc wikkl riefy ouont hatne xttim etheg roupw astra dbeca sthey retur necso uthsp kitup ancvi sitec adhai nofes sexan cbent vikka gesak ongth etham eslut cespi tethe irdon tinui ngint erest inkan cmarb snoth ingol vious inthe irleh aviou rsugg estec anypa rtidu karpk anthe north erngr oupar enows tayin gwith sdout sinda newco nanca bekah asred ruite coneo fthem tospy onthe party ourai rmini stryd ontad tsare indre asing kyaka rmeca loutt hespy dkist sluta resti kknot prepa recto tekku swhat itist hatis worry ingth emthe yarep artid ukark yagit ateca loutt hepre sende atdai stora ncnow atdan ewcon ancth isdon derna louta dtivi tyine astan gkiaa ncess exmab esmew oncer ifiti sdonn edtec witha ircef endef orthe dapit aklut theya reref using totek kanci twikk lehar cforu stohe kpthe mifth eywon ttekk uswha twear esupp osect olepr otedt ingth eatta dhect ekegr amwas dopie clyan abeka agent inspa kcing hissi sterw orbsa tthet ekegr aphyo ffide ancga vehim addes sthem essag ewasc ekive recly oneof thesp ydkis tsanc ondem oreit wasac cress ectow ikhek minti rpitz ufert hespy dkist shave rever tecto asuls titut iondi pherf orthi smess agelu tlkod becit tocis guise theme ssage strud turet hatma ceita kotha rcert odrad bluti amgka cicic ithas asedr etmes sageh iccen inthe cedip herec textw hidhs ugges tstha tthes pydki stmis sioni sdkos ingon itsai msiam notsu rewha tthei nitia ksrcf stanc forlu tiwik kgola dbtot heair minis tryto asbif theyh avean ysugg estio nsiti sakso dkear fromt hedon tents ofthi smess ageth atthe germa nsare getti ngaki ttkes uspid iouss owewi kknee ctost epupo urown sedur ityiw ikkse ncmyn extlr iefin gusin gavig enere diphe rwith beyke ngtht hreem oreto fokko wpear k\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'while wedid notha vetim etopl acean ytrai nedag entsw ithth elond onsco utgro upsth eakel aoper ation didma naget orecr uitan dbrie fseve ralme mbers ofthe linco lnsco uting assoc iatio nando neoft hemha smade amajo rbrea kthro ughsp ottin gsome thing thato urreg ulara gents hadno tnoti cedth elond onpar tycon siste doftw entyt hreec yclis tsbut thegr oupar rivin ginli ncoln hadon lytwe ntyme mbers atfir stias sumed hehad misco unted butth ephot ograp hinth eloca lpape racco mpany ingth eirre porto nthev isitc onfir medth enumb eriwi llmak eenqu iries witho urlon donag entst oseei fthey havea nythi ngont heoth erthr eeand willb riefy ouont hatne xttim etheg roupw astra ckeda sthey retur nedso uthsp litup andvi sited achai nofes sexan dkent villa gesal ongth etham esbut despi tethe ircon tinui ngint erest inlan dmark snoth ingob vious inthe irbeh aviou rsugg ested anypa rticu larpl anthe north erngr oupar enows tayin gwith scout sinca newdo nanda kelah asrec ruite doneo fthem tospy onthe party ourai rmini stryc ontac tsare incre asing lyala rmeda boutt hespy clist sbuta resti llnot prepa redto tellu swhat itist hatis worry ingth emthe yarep artic ularl yagit ateda boutt hepre sence atcai stora ndnow atcan ewdon andth iscon cerna bouta ctivi tyine astan gliaa ndess exmak esmew onder ifiti sconn ected witha irdef encef orthe capit albut theya reref using totel landi twill behar dforu stohe lpthe mifth eywon ttell uswha twear esupp osedt obepr otect ingth eatta chedt elegr amwas copie dbyan akela agent inspa lding hissi sterw orksa tthet elegr aphyo ffice andga vehim acces sthem essag ewasd elive redby oneof thesp yclis tsand oncem oreit wasad dress edtow ilhel minti rpitz ufert hespy clist shave rever tedto asubs titut ionci pherf orthi smess agebu tbloc kedit todis guise theme ssage struc turet hatma deita lotha rdert ocrac kbuti amgla didid ithas asecr etmes sageh idden inthe decip hered textw hichs ugges tstha tthes pycli stmis sioni sclos ingon itsai msiam notsu rewha tthei nitia lsrdf stand forbu tiwil lgoba cktot heair minis tryto askif theyh avean ysugg estio nsiti salso clear fromt hecon tents ofthi smess ageth atthe germa nsare getti ngali ttles uspic iouss owewi llnee dtost epupo urown secur ityiw illse ndmyn extbr iefin gusin gavig enere ciphe rwith keyle ngtht hreem oreto follo wpear l\\n'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "keyword_decipher(ca, 'akela', wrap_a)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "akelbcdfghijmnopqrstuvwxyz \n", + "\n", + "while wedid notha vetim etopl acean ytrai nedag entsw ithth elond onsco utgro upsth eakel aoper ation didma naget orecr uitan dbrie fseve ralme mbers ofthe linco lnsco uting assoc iatio nando neoft hemha smade amajo rbrea kthro ughsp ottin gsome thing thato urreg ulara gents hadno tnoti cedth elond onpar tycon siste doftw entyt hreec yclis tsbut thegr oupar rivin ginli ncoln hadon lytwe ntyme mbers atfir stias sumed hehad misco unted butth ephot ograp hinth eloca lpape racco mpany ingth eirre porto nthev isitc onfir medth enumb eriwi llmak eenqu iries witho urlon donag entst oseei fthey havea nythi ngont heoth erthr eeand willb riefy ouont hatne xttim etheg roupw astra ckeda sthey retur nedso uthsp litup andvi sited achai nofes sexan dkent villa gesal ongth etham esbut despi tethe ircon tinui ngint erest inlan dmark snoth ingob vious inthe irbeh aviou rsugg ested anypa rticu larpl anthe north erngr oupar enows tayin gwith scout sinca newdo nanda kelah asrec ruite doneo fthem tospy onthe party ourai rmini stryc ontac tsare incre asing lyala rmeda boutt hespy clist sbuta resti llnot prepa redto tellu swhat itist hatis worry ingth emthe yarep artic ularl yagit ateda boutt hepre sence atcai stora ndnow atcan ewdon andth iscon cerna bouta ctivi tyine astan gliaa ndess exmak esmew onder ifiti sconn ected witha irdef encef orthe capit albut theya reref using totel landi twill behar dforu stohe lpthe mifth eywon ttell uswha twear esupp osedt obepr otect ingth eatta chedt elegr amwas copie dbyan akela agent inspa lding hissi sterw orksa tthet elegr aphyo ffice andga vehim acces sthem essag ewasd elive redby oneof thesp yclis tsand oncem oreit wasad dress edtow ilhel minti rpitz ufert hespy clist shave rever tedto asubs titut ionci pherf orthi smess agebu tbloc kedit todis guise theme ssage struc turet hatma deita lotha rdert ocrac kbuti amgla didid ithas asecr etmes sageh idden inthe decip hered textw hichs ugges tstha tthes pycli stmis sioni sclos ingon itsai msiam notsu rewha tthei nitia lsrdf stand forbu tiwil lgoba cktot heair minis tryto askif theyh avean ysugg estio nsiti salso clear fromt hecon tents ofthi smess ageth atthe germa nsare getti ngali ttles uspic iouss owewi llnee dtost epupo urown secur ityiw illse ndmyn extbr iefin gusin gavig enere ciphe rwith keyle ngtht hreem oreto follo wpear l\n", + "\n" + ] + } + ], + "source": [ + "word_a, score_a = simulated_annealing_break(sca, fitness=Ptrigrams,\n", + " plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('akkad', wrap_alphabet=KeywordWrapAlphabet.from_largest))\n", + "print(word_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "while we did not have time to place any trained agents with the london scout groups the akela\n", + "operation did manage to recruit and brief several members of the lincoln scouting association and\n", + "one of them has made a major breakthrough spotting something that our regular agents had not noticed\n", + "the london party consisted of twenty three cyclists but the group arriving in lincoln had only\n", + "twenty members at first i assumed he had mis counted but the photograph in the local paper\n", + "accompanying their report on the visit confirmed the number i will make enquiries with our london\n", + "agents to see if they have anything on the other three and will brief you on that next time the\n", + "group was tracked as they returned south split up and visited a chain of essex and kent villages\n", + "along the thames but despite their continuing interest in landmarks nothing obvious in their\n", + "behaviour suggested any particular plan the northern group are now staying with scouts in ca new don\n", + "and akela has recruited one of them to spy on the part your air ministry contacts are increasingly\n", + "alarmed about the spy c lists but are still not prepared to tell us what it is that is worrying them\n", + "they are particularly agitated about the presence at caistor and now at ca new don and this concern\n", + "about activity in east anglia and essex makes me wonder if it is connected with air defence for the\n", + "capital but they are refusing to tell and it will be hard for us to help them if they wont tell us\n", + "what we are supposed to be protecting the attached telegram was copied by an akela agent in spalding\n", + "his sister works at the telegraphy office and gave him access the message was delivered by one of\n", + "the spy c lists and once more it was addressed to wilhelm in tirpitz ufer the spy c lists have\n", + "reverted to a substitution cipher for this message but blocked it to disguise the message structure\n", + "that made it alot harder to crack but i am glad i did it has a secret message hidden in the\n", + "deciphered text which suggests that the spy c list mission is closing on its aim siam not sure what\n", + "the initials rdf stand for but i will go back to the air ministry to ask if they have any\n", + "suggestions it is also clear from the contents of this message that the germans are getting a little\n", + "suspicious so we will need to step up our own security i will send my next briefing using avi genere\n", + "cipher with key length three more to follow pearl\n" + ] + } + ], + "source": [ + "pa = prettify(keyword_decipher(sca, 'akela', wrap_alphabet=KeywordWrapAlphabet.from_a))\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2336" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wilhelm KeywordWrapAlphabet.from_last \n", + "\n", + "dearu nclew ilhel masyo uprom isedw ethor oughl yenjo yedou rvisi ttoyo urcou sinin linco lnand found itmos tinfo rmati vesto ptheb eauti fulca thedr alalm ostju stifi edour visit onits ownan dourh ostss hared withu ssome inter estin gdraw ingso fthet owers youme ntion edsto pthey graci ously allow edmet ocopy thesk etche sande xplai nedmu chabo uthow theto wersa rebui ltand whyst opasu suali wills endyo umyno tesan dsket chesv iaour dearf riend jessi cawho haspr omise dtoen suret heirs afede liver ystop reall yimus tcong ratul ateou rhost sinth eloca lscou tgrou psfor thema rvell ouswa yinwh ichth eyhav eorga nised ourtr avelt hough someo fthes couts haveb eenra therm oreso licit ousth anweh adexp ected askin grath eralo tofqu estio nsabo utour plans stopg enera llyih opeth eywer esati sfied witht heans werst hatwe gaveb utwef eelth atwea reatr iskof overs tayin gourw elcom esowe willr eturn tolon donon tuesd aysto peven thoug hweha veenj oyedo urtim etoge thert hereh asbee nsome debat eamon gtheg roupa boutw herew eshou ldvis itnex tstop there areso manyi ntere sting sites tovis italo ngthe majes ticth amese stuar ysowe haved ecide dtosp litin totwo group sstop ralfw illle adone party onato uroft heken tcoas twhil eiamv erymu chloo kingf orwar dtoex plori ngthe essex marsh essto pdole tmekn owify ouhav eabet terid eabut ihave beent oldth atcan ewdon sfift eenth centu rychu rchaf fords anele vatio nwith awide viewo fthes urrou nding lands inthi sothe rwise rathe rflat lands capea ndist hesit eofan other fasci natin gtowe rwhic hiwil lbece rtain toske tchfo ryous topfi nally ifyou havea nyfur therr eques tsfor speci ficin forma tiont henpe rhaps youco uldle aveam essag eform eatth epost offic ether estop karlm essag eends \n", + "\n" + ] + } + ], + "source": [ + "(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams)\n", + "print(word_b, wrap_b, '\\n')\n", + "pb = keyword_decipher(cb, word_b, wrap_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dear uncle wilhelm as you promised we thoroughly enjoyed our visit to your cousin in lincoln and\n", + "found it most informative stop the beautiful cathedral almost justified our visit on its own and our\n", + "hosts shared with us some interesting drawings of the towers you mentioned stop they graciously\n", + "allowed me to copy the sketches and explained much about how the towers are built and why stop as\n", + "usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure\n", + "their safe delivery stop really i must congratulate our hosts in the local scout groups for the\n", + "marvellous way in which they have organised our travel though some of the scouts have been rather\n", + "more solicitous than we had expected asking rather alot of questions about our plans stop generally\n", + "i hope they were satisfied with the answers that we gave but we feel that we are at risk of\n", + "overstaying our welcome so we will return to london on tuesday stop eventhough we have enjoyed our\n", + "time together there has been some debate among the group about where we should visit next stop there\n", + "are so many interesting sites to visit along the majestic thames estuary so we have decided to split\n", + "into two groups stop ralf will lead one party on at our of the kent coast while i am very much\n", + "looking forward to exploring the essex marshes stop do let me know if you have a better idea but i\n", + "have been told that ca new dons fifteenth century church afford san elevation with a wide view of\n", + "the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating\n", + "tower which i will be certain to sketch for you stop finally if you have any further requests for\n", + "specific information then perhaps you could leave a message for meat the post office there stop karl\n", + "message ends\n" + ] + } + ], + "source": [ + "pb = prettify(keyword_decipher(scb, word_b, wrap_b))\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1782" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['the',\n", + " 'they',\n", + " 'as',\n", + " 'really',\n", + " 'generally',\n", + " 'eventhough',\n", + " 'there',\n", + " 'ralf',\n", + " 'do',\n", + " 'finally',\n", + " 'karl']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pbs = pb.split()\n", + "[pbs[i+1] for i, w in enumerate(pbs) if w == 'stop']" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'duwaypwteovtycilafimistbcajovoioaohswusidottymstgamtctsaemahttabawsauiwsymnasvodfjwhptetsdsrimcohitlsgftmwiwthoottsotshbrmstwhearaoqaopsgihtwswtatwgbwftwaarooowswwrtlotsewheottthbsdatgawwsvnstasmistvatmteswhdtsitgsrwlopoaootkcwiavmlftetemsdlmkiyhabibihbttcndfccasewawvotslitorflaitsoaftwiwbctsfysfiyhafrfsitpyclamfmtpotskme'" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat(w[0] for w in pbs)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[21, 24, 19, 23, 44, 32, 21, 22, 24, 56, 23, 3]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[len(s.strip().split()) for s in pb.split('stop')]" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'DeaR uncle wilhelm as you pRomiseD we thoRoughly enjoyeD ouR visit to youR cousin in lincoln anD FounD it most inFoRmative stop the beautiFul catheDRal almost justiFieD ouR visit on its own anD ouR hosts shaReD with us some inteResting DRawings oF the toweRs you mentioneD stop they gRaciously alloweD me to copy the sketches anD explaineD much about how the toweRs aRe built anD why stop as usual i will senD you my notes anD sketches via ouR DeaR FRienD jessica who has pRomiseD to ensuRe theiR saFe DeliveRy stop Really i must congRatulate ouR hosts in the local scout gRoups FoR the maRvellous way in which they have oRganiseD ouR tRavel though some oF the scouts have been RatheR moRe solicitous than we haD expecteD asking RatheR alot oF questions about ouR plans stop geneRally i hope they weRe satisFieD with the answeRs that we gave but we Feel that we aRe at Risk oF oveRstaying ouR welcome so we will RetuRn to lonDon on tuesDay stop eventhough we have enjoyeD ouR time togetheR theRe has been some Debate among the gRoup about wheRe we shoulD visit next stop theRe aRe so many inteResting sites to visit along the majestic thames estuaRy so we have DeciDeD to split into two gRoups stop RalF will leaD one paRty on at ouR oF the kent coast while i am veRy much looking FoRwaRD to exploRing the essex maRshes stop Do let me know iF you have a betteR iDea but i have been tolD that ca new Dons FiFteenth centuRy chuRch aFFoRD san elevation with a wiDe view oF the suRRounDing lanDs in this otheRwise RatheR Flat lanDscape anD is the site oF anotheR Fascinating toweR which i will be ceRtain to sketch FoR you stop Finally iF you have any FuRtheR Requests FoR speciFic inFoRmation then peRhaps you coulD leave a message FoR meat the post oFFice theRe stop kaRl message enDs'" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tt = ''.maketrans('rdf', 'RDF')\n", + "pbcap = wcat(pb.split()).translate(tt)\n", + "pbcap" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Dea\n", + "R uncle wilhelm as you p\n", + "Romise\n", + "D we tho\n", + "Roughly enjoye\n", + "D ou\n", + "R visit to you\n", + "R cousin in lincoln an\n", + "D \n", + "Foun\n", + "D it most in\n", + "Fo\n", + "Rmative stop the beauti\n", + "Ful cathe\n", + "D\n", + "Ral almost justi\n", + "Fie\n", + "D ou\n", + "R visit on its own an\n", + "D ou\n", + "R hosts sha\n", + "Re\n", + "D with us some inte\n", + "Resting \n", + "D\n", + "Rawings o\n", + "F the towe\n", + "Rs you mentione\n", + "D stop they g\n", + "Raciously allowe\n", + "D me to copy the sketches an\n", + "D explaine\n", + "D much about how the towe\n", + "Rs a\n", + "Re built an\n", + "D why stop as usual i will sen\n", + "D you my notes an\n", + "D sketches via ou\n", + "R \n", + "Dea\n", + "R \n", + "F\n", + "Rien\n", + "D jessica who has p\n", + "Romise\n", + "D to ensu\n", + "Re thei\n", + "R sa\n", + "Fe \n", + "Delive\n", + "Ry stop \n", + "Really i must cong\n", + "Ratulate ou\n", + "R hosts in the local scout g\n", + "Roups \n", + "Fo\n", + "R the ma\n", + "Rvellous way in which they have o\n", + "Rganise\n", + "D ou\n", + "R t\n", + "Ravel though some o\n", + "F the scouts have been \n", + "Rathe\n", + "R mo\n", + "Re solicitous than we ha\n", + "D expecte\n", + "D asking \n", + "Rathe\n", + "R alot o\n", + "F questions about ou\n", + "R plans stop gene\n", + "Rally i hope they we\n", + "Re satis\n", + "Fie\n", + "D with the answe\n", + "Rs that we gave but we \n", + "Feel that we a\n", + "Re at \n", + "Risk o\n", + "F ove\n", + "Rstaying ou\n", + "R welcome so we will \n", + "Retu\n", + "Rn to lon\n", + "Don on tues\n", + "Day stop eventhough we have enjoye\n", + "D ou\n", + "R time togethe\n", + "R the\n", + "Re has been some \n", + "Debate among the g\n", + "Roup about whe\n", + "Re we shoul\n", + "D visit next stop the\n", + "Re a\n", + "Re so many inte\n", + "Resting sites to visit along the majestic thames estua\n", + "Ry so we have \n", + "Deci\n", + "De\n", + "D to split into two g\n", + "Roups stop \n", + "Ral\n", + "F will lea\n", + "D one pa\n", + "Rty on at ou\n", + "R o\n", + "F the kent coast while i am ve\n", + "Ry much looking \n", + "Fo\n", + "Rwa\n", + "R\n", + "D to explo\n", + "Ring the essex ma\n", + "Rshes stop \n", + "Do let me know i\n", + "F you have a bette\n", + "R i\n", + "Dea but i have been tol\n", + "D that ca new \n", + "Dons \n", + "Fi\n", + "Fteenth centu\n", + "Ry chu\n", + "Rch a\n", + "F\n", + "Fo\n", + "R\n", + "D san elevation with a wi\n", + "De view o\n", + "F the su\n", + "R\n", + "Roun\n", + "Ding lan\n", + "Ds in this othe\n", + "Rwise \n", + "Rathe\n", + "R \n", + "Flat lan\n", + "Dscape an\n", + "D is the site o\n", + "F anothe\n", + "R \n", + "Fascinating towe\n", + "R which i will be ce\n", + "Rtain to sketch \n", + "Fo\n", + "R you stop \n", + "Finally i\n", + "F you have any \n", + "Fu\n", + "Rthe\n", + "R \n", + "Requests \n", + "Fo\n", + "R speci\n", + "Fic in\n", + "Fo\n", + "Rmation then pe\n", + "Rhaps you coul\n", + "D leave a message \n", + "Fo\n", + "R meat the post o\n", + "F\n", + "Fice the\n", + "Re stop ka\n", + "Rl message en\n", + "Ds\n" + ] + } + ], + "source": [ + "pbcap2 = cat(('\\n' + c) if c.isupper() else c for c in pbcap)\n", + "print(pbcap2)" + ] + }, + { + "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 +} diff --git a/2020/2020-challenge5.md b/2020/2020-challenge5.md new file mode 100644 index 0000000..55703b7 --- /dev/null +++ b/2020/2020-challenge5.md @@ -0,0 +1,107 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.support.text_prettify import * +``` + +```python Collapsed="false" +challenge_number = 5 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +sca = sanitise(ca) +cb = open(ciphertext_b_filename).read() +scb = sanitise(cb) +``` + +```python Collapsed="false" +(word_a, wrap_a), score_a = keyword_break_mp(sca, fitness=Ptrigrams) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python Collapsed="false" +keyword_decipher(ca, 'akela', wrap_a) +``` + +```python Collapsed="false" +word_a, score_a = simulated_annealing_break(sca, fitness=Ptrigrams, + plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('akkad', wrap_alphabet=KeywordWrapAlphabet.from_largest)) +print(word_a, '\n') +pa = keyword_decipher(ca, word_a) +print(pa) +``` + +```python Collapsed="false" +pa = prettify(keyword_decipher(sca, 'akela', wrap_alphabet=KeywordWrapAlphabet.from_a)) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +(word_b, wrap_b), score_b = keyword_break_mp(scb, fitness=Ptrigrams) +print(word_b, wrap_b, '\n') +pb = keyword_decipher(cb, word_b, wrap_b) +print(pb) +``` + +```python Collapsed="false" +pb = prettify(keyword_decipher(scb, word_b, wrap_b)) +print(pb) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" +pbs = pb.split() +[pbs[i+1] for i, w in enumerate(pbs) if w == 'stop'] +``` + +```python Collapsed="false" +cat(w[0] for w in pbs) +``` + +```python Collapsed="false" +[len(s.strip().split()) for s in pb.split('stop')] +``` + +```python Collapsed="false" +tt = ''.maketrans('rdf', 'RDF') +pbcap = wcat(pb.split()).translate(tt) +pbcap +``` + +```python Collapsed="false" +pbcap2 = cat(('\n' + c) if c.isupper() else c for c in pbcap) +print(pbcap2) +``` + +```python Collapsed="false" + +``` diff --git a/2020/ciphertext.5a.txt b/2020/ciphertext.5a.txt new file mode 100644 index 0000000..31b021d --- /dev/null +++ b/2020/ciphertext.5a.txt @@ -0,0 +1 @@ +WFGJB WBLGL NOTFA VBTGM BTOPJ AEBAN YTRAG NBLAD BNTSW GTFTF BJONL ONSEO UTDRO UPSTF BAIBJ AOPBR ATGON LGLMA NADBT ORBER UGTAN LKRGB CSBVB RAJMB MKBRS OCTFB JGNEO JNSEO UTGND ASSOE GATGO NANLO NBOCT FBMFA SMALB AMAHO RKRBA ITFRO UDFSP OTTGN DSOMB TFGND TFATO URRBD UJARA DBNTS FALNO TNOTG EBLTF BJONL ONPAR TYEON SGSTB LOCTW BNTYT FRBBE YEJGS TSKUT TFBDR OUPAR RGVGN DGNJG NEOJN FALON JYTWB NTYMB MKBRS ATCGR STGAS SUMBL FBFAL MGSEO UNTBL KUTTF BPFOT ODRAP FGNTF BJOEA JPAPB RAEEO MPANY GNDTF BGRRB PORTO NTFBV GSGTE ONCGR MBLTF BNUMK BRGWG JJMAI BBNQU GRGBS WGTFO URJON LONAD BNTST OSBBG CTFBY FAVBA NYTFG NDONT FBOTF BRTFR BBANL WGJJK RGBCY OUONT FATNB XTTGM BTFBD ROUPW ASTRA EIBLA STFBY RBTUR NBLSO UTFSP JGTUP ANLVG SGTBL AEFAG NOCBS SBXAN LIBNT VGJJA DBSAJ ONDTF BTFAM BSKUT LBSPG TBTFB GREON TGNUG NDGNT BRBST GNJAN LMARI SNOTF GNDOK VGOUS GNTFB GRKBF AVGOU RSUDD BSTBL ANYPA RTGEU JARPJ ANTFB NORTF BRNDR OUPAR BNOWS TAYGN DWGTF SEOUT SGNEA NBWLO NANLA IBJAF ASRBE RUGTB LONBO CTFBM TOSPY ONTFB PARTY OURAG RMGNG STRYE ONTAE TSARB GNERB ASGND JYAJA RMBLA KOUTT FBSPY EJGST SKUTA RBSTG JJNOT PRBPA RBLTO TBJJU SWFAT GTGST FATGS WORRY GNDTF BMTFB YARBP ARTGE UJARJ YADGT ATBLA KOUTT FBPRB SBNEB ATEAG STORA NLNOW ATEAN BWLON ANLTF GSEON EBRNA KOUTA ETGVG TYGNB ASTAN DJGAA NLBSS BXMAI BSMBW ONLBR GCGTG SEONN BETBL WGTFA GRLBC BNEBC ORTFB EAPGT AJKUT TFBYA RBRBC USGND TOTBJ JANLG TWGJJ KBFAR LCORU STOFB JPTFB MGCTF BYWON TTBJJ USWFA TWBAR BSUPP OSBLT OKBPR OTBET GNDTF BATTA EFBLT BJBDR AMWAS EOPGB LKYAN AIBJA ADBNT GNSPA JLGND FGSSG STBRW ORISA TTFBT BJBDR APFYO CCGEB ANLDA VBFGM AEEBS STFBM BSSAD BWASL BJGVB RBLKY ONBOC TFBSP YEJGS TSANL ONEBM ORBGT WASAL LRBSS BLTOW GJFBJ MGNTG RPGTZ UCBRT FBSPY EJGST SFAVB RBVBR TBLTO ASUKS TGTUT GONEG PFBRC ORTFG SMBSS ADBKU TKJOE IBLGT TOLGS DUGSB TFBMB SSADB STRUE TURBT FATMA LBGTA JOTFA RLBRT OERAE IKUTG AMDJA LGLGL GTFAS ASBER BTMBS SADBF GLLBN GNTFB LBEGP FBRBL TBXTW FGEFS UDDBS TSTFA TTFBS PYEJG STMGS SGONG SEJOS GNDON GTSAG MSGAM NOTSU RBWFA TTFBG NGTGA JSRLC STANL CORKU TGWGJ JDOKA EITOT FBAGR MGNGS TRYTO ASIGC TFBYF AVBAN YSUDD BSTGO NSGTG SAJSO EJBAR CROMT FBEON TBNTS OCTFG SMBSS ADBTF ATTFB DBRMA NSARB DBTTG NDAJG TTJBS USPGE GOUSS OWBWG JJNBB LTOST BPUPO UROWN SBEUR GTYGW GJJSB NLMYN BXTKR GBCGN DUSGN DAVGD BNBRB EGPFB RWGTF IBYJB NDTFT FRBBM ORBTO COJJO WPBAR J diff --git a/2020/ciphertext.5b.txt b/2020/ciphertext.5b.txt new file mode 100644 index 0000000..7581eac --- /dev/null +++ b/2020/ciphertext.5b.txt @@ -0,0 +1 @@ +HEWZC ULSEF PSOES TWAJV CXZVT PAEHF EBOVZ VCNOS JEUQV JEHVC ZDPAP BBVJV CZLVC APUPU SPULV SUWUH MVCUH PBTVA BPUMV ZTWBP DEABV XBOEI EWCBP MCSLW BOEHZ WSWST VABQC ABPMP EHVCZ DPAPB VUPBA VFUWU HVCZO VABAA OWZEH FPBOC AAVTE PUBEZ EABPU NHZWF PUNAV MBOEB VFEZA JVCTE UBPVU EHABV XBOEJ NZWLP VCASJ WSSVF EHTEB VLVXJ BOEAR EBLOE AWUHE GXSWP UEHTC LOWIV CBOVF BOEBV FEZAW ZEICP SBWUH FOJAB VXWAC ACWSP FPSSA EUHJV CTJUV BEAWU HAREB LOEAD PWVCZ HEWZM ZPEUH QEAAP LWFOV OWAXZ VTPAE HBVEU ACZEB OEPZA WMEHE SPDEZ JABVX ZEWSS JPTCA BLVUN ZWBCS WBEVC ZOVAB APUBO ESVLW SALVC BNZVC XAMVZ BOETW ZDESS VCAFW JPUFO PLOBO EJOWD EVZNW UPAEH VCZBZ WDESB OVCNO AVTEV MBOEA LVCBA OWDEI EEUZW BOEZT VZEAV SPLPB VCABO WUFEO WHEGX ELBEH WARPU NZWBO EZWSV BVMYC EABPV UAWIV CBVCZ XSWUA ABVXN EUEZW SSJPO VXEBO EJFEZ EAWBP AMPEH FPBOB OEWUA FEZAB OWBFE NWDEI CBFEM EESBO WBFEW ZEWBZ PARVM VDEZA BWJPU NVCZF ESLVT EAVFE FPSSZ EBCZU BVSVU HVUVU BCEAH WJABV XEDEU BOVCN OFEOW DEEUQ VJEHV CZBPT EBVNE BOEZB OEZEO WAIEE UAVTE HEIWB EWTVU NBOEN ZVCXW IVCBF OEZEF EAOVC SHDPA PBUEG BABVX BOEZE WZEAV TWUJP UBEZE ABPUN APBEA BVDPA PBWSV UNBOE TWQEA BPLBO WTEAE ABCWZ JAVFE OWDEH ELPHE HBVAX SPBPU BVBFV NZVCX AABVX ZWSMF PSSSE WHVUE XWZBJ VUWBV CZVMB OEREU BLVWA BFOPS EPWTD EZJTC LOSVV RPUNM VZFWZ HBVEG XSVZP UNBOE EAAEG TWZAO EAABV XHVSE BTERU VFPMJ VCOWD EWIEB BEZPH EWICB POWDE IEEUB VSHBO WBLWU EFHVU AMPMB EEUBO LEUBC ZJLOC ZLOWM MVZHA WUESE DWBPV UFPBO WFPHE DPEFV MBOEA CZZVC UHPUN SWUHA PUBOP AVBOE ZFPAE ZWBOE ZMSWB SWUHA LWXEW UHPAB OEAPB EVMWU VBOEZ MWALP UWBPU NBVFE ZFOPL OPFPS SIELE ZBWPU BVARE BLOMV ZJVCA BVXMP UWSSJ PMJVC OWDEW UJMCZ BOEZZ EYCEA BAMVZ AXELP MPLPU MVZTW BPVUB OEUXE ZOWXA JVCLV CSHSE WDEWT EAAWN EMVZT EWBBO EXVAB VMMPL EBOEZ EABVX RWZST EAAWN EEUHA diff --git a/2020/plaintext.5a.txt b/2020/plaintext.5a.txt new file mode 100644 index 0000000..ff6e2f9 --- /dev/null +++ b/2020/plaintext.5a.txt @@ -0,0 +1 @@ +while wedid notha vetim etopl acean ytrai nedag entsw ithth elond onsco utgro upsth eakel aoper ation didma naget orecr uitan dbrie fseve ralme mbers ofthe linco lnsco uting assoc iatio nando neoft hemha smade amajo rbrea kthro ughsp ottin gsome thing thato urreg ulara gents hadno tnoti cedth elond onpar tycon siste doftw entyt hreec yclis tsbut thegr oupar rivin ginli ncoln hadon lytwe ntyme mbers atfir stias sumed hehad misco unted butth ephot ograp hinth eloca lpape racco mpany ingth eirre porto nthev isitc onfir medth enumb eriwi llmak eenqu iries witho urlon donag entst oseei fthey havea nythi ngont heoth erthr eeand willb riefy ouont hatne xttim etheg roupw astra ckeda sthey retur nedso uthsp litup andvi sited achai nofes sexan dkent villa gesal ongth etham esbut despi tethe ircon tinui ngint erest inlan dmark snoth ingob vious inthe irbeh aviou rsugg ested anypa rticu larpl anthe north erngr oupar enows tayin gwith scout sinca newdo nanda kelah asrec ruite doneo fthem tospy onthe party ourai rmini stryc ontac tsare incre asing lyala rmeda boutt hespy clist sbuta resti llnot prepa redto tellu swhat itist hatis worry ingth emthe yarep artic ularl yagit ateda boutt hepre sence atcai stora ndnow atcan ewdon andth iscon cerna bouta ctivi tyine astan gliaa ndess exmak esmew onder ifiti sconn ected witha irdef encef orthe capit albut theya reref using totel landi twill behar dforu stohe lpthe mifth eywon ttell uswha twear esupp osedt obepr otect ingth eatta chedt elegr amwas copie dbyan akela agent inspa lding hissi sterw orksa tthet elegr aphyo ffice andga vehim acces sthem essag ewasd elive redby oneof thesp yclis tsand oncem oreit wasad dress edtow ilhel minti rpitz ufert hespy clist shave rever tedto asubs titut ionci pherf orthi smess agebu tbloc kedit todis guise theme ssage struc turet hatma deita lotha rdert ocrac kbuti amgla didid ithas asecr etmes sageh idden inthe decip hered textw hichs ugges tstha tthes pycli stmis sioni sclos ingon itsai msiam notsu rewha tthei nitia lsrdf stand forbu tiwil lgoba cktot heair minis tryto askif theyh avean ysugg estio nsiti salso clear fromt hecon tents ofthi smess ageth atthe germa nsare getti ngali ttles uspic iouss owewi llnee dtost epupo urown secur ityiw illse ndmyn extbr iefin gusin gavig enere ciphe rwith keyle ngtht hreem oreto follo wpear l diff --git a/2020/plaintext.5b.txt b/2020/plaintext.5b.txt new file mode 100644 index 0000000..5ee6388 --- /dev/null +++ b/2020/plaintext.5b.txt @@ -0,0 +1,19 @@ +dear uncle wilhelm as you promised we thoroughly enjoyed our visit to your cousin in lincoln and +found it most informative stop the beautiful cathedral almost justified our visit on its own and our +hosts shared with us some interesting drawings of the towers you mentioned stop they graciously +allowed me to copy the sketches and explained much about how the towers are built and why stop as +usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure +their safe delivery stop really i must congratulate our hosts in the local scout groups for the +marvellous way in which they have organised our travel though some of the scouts have been rather +more solicitous than we had expected asking rather alot of questions about our plans stop generally +i hope they were satisfied with the answers that we gave but we feel that we are at risk of +overstaying our welcome so we will return to london on tuesday stop eventhough we have enjoyed our +time together there has been some debate among the group about where we should visit next stop there +are so many interesting sites to visit along the majestic thames estuary so we have decided to split +into two groups stop ralf will lead one party on at our of the kent coast while i am very much +looking forward to exploring the essex marshes stop do let me know if you have a better idea but i +have been told that ca new dons fifteenth century church afford san elevation with a wide view of +the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating +tower which i will be certain to sketch for you stop finally if you have any further requests for +specific information then perhaps you could leave a message for meat the post office there stop karl +message ends \ No newline at end of file -- 2.34.1 From 4fa45dec7e940fe93f664e40808e372e4ad272e1 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 27 Nov 2020 13:36:22 +0000 Subject: [PATCH 05/16] Fixed wordbreaks in the plaintext --- 2020/2020-challenge5.ipynb | 460 ++++++++++++++++++++++++++++++++++--- 2020/2020-challenge5.md | 99 +++++++- 2020/plaintext.5b.txt | 10 +- 3 files changed, 537 insertions(+), 32 deletions(-) diff --git a/2020/2020-challenge5.ipynb b/2020/2020-challenge5.ipynb index 0023d1c..363693c 100644 --- a/2020/2020-challenge5.ipynb +++ b/2020/2020-challenge5.ipynb @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "metadata": { "Collapsed": "false" }, @@ -183,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "metadata": { "Collapsed": "false" }, @@ -208,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": { "Collapsed": "false" }, @@ -246,7 +246,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 87, "metadata": { "Collapsed": "false" }, @@ -254,10 +254,10 @@ { "data": { "text/plain": [ - "1782" + "1783" ] }, - "execution_count": 27, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } @@ -268,7 +268,47 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 86, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "pb = \"\"\"dear uncle wilhelm as you promised we thoroughly enjoyed our visit to your cousin in lincoln and\n", + "found it most informative stop the beautiful cathedral almost justified our visit on its own and our\n", + "hosts shared with us some interesting drawings of the towers you mentioned stop they graciously\n", + "allowed me to copy the sketches and explained much about how the towers are built and why stop as\n", + "usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure\n", + "their safe delivery stop really i must congratulate our hosts in the local scout groups for the\n", + "marvellous way in which they have organised our travel though some of the scouts have been rather\n", + "more solicitous than we had expected asking rather a lot of questions about our plans stop generally\n", + "i hope they were satisfied with the answers that we gave but we feel that we are at risk of\n", + "overstaying our welcome so we will return to london on tuesday stop even though we have enjoyed our\n", + "time together there has been some debate among the group about where we should visit next stop there\n", + "are so many interesting sites to visit along the majestic thames estuary so we have decided to split\n", + "into two groups stop ralf will lead one party on a tour of the kent coast while i am very much\n", + "looking forward to exploring the essex marshes stop do let me know if you have a better idea but i\n", + "have been told that canewdons fifteenth century church affords an elevation with a wide view of\n", + "the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating\n", + "tower which i will be certain to sketch for you stop finally if you have any further requests for\n", + "specific information then perhaps you could leave a message for me at the post office there stop karl\n", + "message ends\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "spb = sanitise(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, "metadata": { "Collapsed": "false" }, @@ -281,7 +321,7 @@ " 'as',\n", " 'really',\n", " 'generally',\n", - " 'eventhough',\n", + " 'even',\n", " 'there',\n", " 'ralf',\n", " 'do',\n", @@ -289,7 +329,7 @@ " 'karl']" ] }, - "execution_count": 23, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -301,7 +341,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 90, "metadata": { "Collapsed": "false" }, @@ -309,21 +349,21 @@ { "data": { "text/plain": [ - "'duwaypwteovtycilafimistbcajovoioaohswusidottymstgamtctsaemahttabawsauiwsymnasvodfjwhptetsdsrimcohitlsgftmwiwthoottsotshbrmstwhearaoqaopsgihtwswtatwgbwftwaarooowswwrtlotsewheottthbsdatgawwsvnstasmistvatmteswhdtsitgsrwlopoaootkcwiavmlftetemsdlmkiyhabibihbttcndfccasewawvotslitorflaitsoaftwiwbctsfysfiyhafrfsitpyclamfmtpotskme'" + "'duwaypwteovtycilafim is tbcajovoioaohswusi dotty mst ga mtct sae mah ttab aws a uiwsymnasvodfjwhptet sds rim co hit lsgftmwiwthoottsotsh brms tw hear al oqaopsgihtwswtatwgbw ft waar ooo wsw wrt lot set wheottthbsdatgawwsvn st as mist vat mteswhdtsitgsrwlopoa to tk cwiavmlftetemsdlmkiy habibi hbttcfccaaewawvotsl it or fla its oaftwiwbctsfysfiyhaf rfs it py clam fm at pots k me'" ] }, - "execution_count": 35, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cat(w[0] for w in pbs)" + "wcat(segment(cat(w[0] for w in pbs)))" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 91, "metadata": { "Collapsed": "false" }, @@ -331,10 +371,76 @@ { "data": { "text/plain": [ - "[21, 24, 19, 23, 44, 32, 21, 22, 24, 56, 23, 3]" + "'en is or eh nui oo on i not on the a luu in twn uo his on rfhooethrleoohknxu boho run hts sie oy on kiuereharonhaeteuou on hoc roh a an hharurhofhcaeaooheax sa of ubulteoheaihnheauee her tif vue oeieoonutvheanuiohae oem hrb he hie thro an i oil hahsoeaeopnwrtaien an of he ohm eu ooo x hsa to eenfoaeduaeohaiehfnl ii if huan ht alan sh if naoh i eeo koot if oanueopnheooeeoeth of hta en'" ] }, - "execution_count": 26, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wcat(segment(cat(w[1] for w in pbs if len(w) > 1)))" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'sel pee teter eaedusnncrsryeufypu rhone li hr gr fees de tres ns gef we a hnnshyhstdneitaraeuf we top sxe god ghy miette fr any ed lfp soo to deeoyscegtosgyoeeptt deet peg een ser erde ehnpynnonleoergfkte et let eet sehdeyeiypsrtsftargd denser nesefehlrdeyhnyserst lens reti ypyereodsoadrrasdsyu d lil spy dtesewthddseyoedyypd use fsgeshdsrdnsntrdtlle pet tdd nnn rotr dyed us mer'" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wcat(segment(cat(w[-1] for w in reversed(pbs))))" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max([len(w) for w in pbs])" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[21, 24, 19, 23, 45, 32, 22, 22, 24, 54, 24, 3]" + ] + }, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -345,7 +451,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 95, "metadata": { "Collapsed": "false" }, @@ -353,10 +459,10 @@ { "data": { "text/plain": [ - "'DeaR uncle wilhelm as you pRomiseD we thoRoughly enjoyeD ouR visit to youR cousin in lincoln anD FounD it most inFoRmative stop the beautiFul catheDRal almost justiFieD ouR visit on its own anD ouR hosts shaReD with us some inteResting DRawings oF the toweRs you mentioneD stop they gRaciously alloweD me to copy the sketches anD explaineD much about how the toweRs aRe built anD why stop as usual i will senD you my notes anD sketches via ouR DeaR FRienD jessica who has pRomiseD to ensuRe theiR saFe DeliveRy stop Really i must congRatulate ouR hosts in the local scout gRoups FoR the maRvellous way in which they have oRganiseD ouR tRavel though some oF the scouts have been RatheR moRe solicitous than we haD expecteD asking RatheR alot oF questions about ouR plans stop geneRally i hope they weRe satisFieD with the answeRs that we gave but we Feel that we aRe at Risk oF oveRstaying ouR welcome so we will RetuRn to lonDon on tuesDay stop eventhough we have enjoyeD ouR time togetheR theRe has been some Debate among the gRoup about wheRe we shoulD visit next stop theRe aRe so many inteResting sites to visit along the majestic thames estuaRy so we have DeciDeD to split into two gRoups stop RalF will leaD one paRty on at ouR oF the kent coast while i am veRy much looking FoRwaRD to exploRing the essex maRshes stop Do let me know iF you have a betteR iDea but i have been tolD that ca new Dons FiFteenth centuRy chuRch aFFoRD san elevation with a wiDe view oF the suRRounDing lanDs in this otheRwise RatheR Flat lanDscape anD is the site oF anotheR Fascinating toweR which i will be ceRtain to sketch FoR you stop Finally iF you have any FuRtheR Requests FoR speciFic inFoRmation then peRhaps you coulD leave a message FoR meat the post oFFice theRe stop kaRl message enDs'" + "'DeaR uncle wilhelm as you pRomiseD we thoRoughly enjoyeD ouR visit to youR cousin in lincoln anD FounD it most inFoRmative stop the beautiFul catheDRal almost justiFieD ouR visit on its own anD ouR hosts shaReD with us some inteResting DRawings oF the toweRs you mentioneD stop they gRaciously alloweD me to copy the sketches anD explaineD much about how the toweRs aRe built anD why stop as usual i will senD you my notes anD sketches via ouR DeaR FRienD jessica who has pRomiseD to ensuRe theiR saFe DeliveRy stop Really i must congRatulate ouR hosts in the local scout gRoups FoR the maRvellous way in which they have oRganiseD ouR tRavel though some oF the scouts have been RatheR moRe solicitous than we haD expecteD asking RatheR a lot oF questions about ouR plans stop geneRally i hope they weRe satisFieD with the answeRs that we gave but we Feel that we aRe at Risk oF oveRstaying ouR welcome so we will RetuRn to lonDon on tuesDay stop even though we have enjoyeD ouR time togetheR theRe has been some Debate among the gRoup about wheRe we shoulD visit next stop theRe aRe so many inteResting sites to visit along the majestic thames estuaRy so we have DeciDeD to split into two gRoups stop RalF will leaD one paRty on a touR oF the kent coast while i am veRy much looking FoRwaRD to exploRing the essex maRshes stop Do let me know iF you have a betteR iDea but i have been tolD that canewDons FiFteenth centuRy chuRch aFFoRDs an elevation with a wiDe view oF the suRRounDing lanDs in this otheRwise RatheR Flat lanDscape anD is the site oF anotheR Fascinating toweR which i will be ceRtain to sketch FoR you stop Finally iF you have any FuRtheR Requests FoR speciFic inFoRmation then peRhaps you coulD leave a message FoR me at the post oFFice theRe stop kaRl message enDs'" ] }, - "execution_count": 30, + "execution_count": 95, "metadata": {}, "output_type": "execute_result" } @@ -364,12 +470,13 @@ "source": [ "tt = ''.maketrans('rdf', 'RDF')\n", "pbcap = wcat(pb.split()).translate(tt)\n", + "spbcap = wcat(spb.split()).translate(tt)\n", "pbcap" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 96, "metadata": { "Collapsed": "false" }, @@ -448,7 +555,7 @@ "D expecte\n", "D asking \n", "Rathe\n", - "R alot o\n", + "R a lot o\n", "F questions about ou\n", "R plans stop gene\n", "Rally i hope they we\n", @@ -465,7 +572,7 @@ "Retu\n", "Rn to lon\n", "Don on tues\n", - "Day stop eventhough we have enjoye\n", + "Day stop even though we have enjoye\n", "D ou\n", "R time togethe\n", "R the\n", @@ -485,7 +592,7 @@ "Ral\n", "F will lea\n", "D one pa\n", - "Rty on at ou\n", + "Rty on a tou\n", "R o\n", "F the kent coast while i am ve\n", "Ry much looking \n", @@ -499,7 +606,7 @@ "F you have a bette\n", "R i\n", "Dea but i have been tol\n", - "D that ca new \n", + "D that canew\n", "Dons \n", "Fi\n", "Fteenth centu\n", @@ -508,7 +615,7 @@ "F\n", "Fo\n", "R\n", - "D san elevation with a wi\n", + "Ds an elevation with a wi\n", "De view o\n", "F the su\n", "R\n", @@ -542,7 +649,7 @@ "Rhaps you coul\n", "D leave a message \n", "Fo\n", - "R meat the post o\n", + "R me at the post o\n", "F\n", "Fice the\n", "Re stop ka\n", @@ -556,6 +663,307 @@ "print(pbcap2)" ] }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'dearu nclew ilhel masyo uprom isedw ethor oughl yenjo yedou rvisi ttoyo urcou sinin linco lnand found itmos tinfo rmati vesto ptheb eauti fulca thedr alalm ostju stifi edour visit onits ownan dourh ostss hared withu ssome inter estin gdraw ingso fthet owers youme ntion edsto pthey graci ously allow edmet ocopy thesk etche sande xplai nedmu chabo uthow theto wersa rebui ltand whyst opasu suali wills endyo umyno tesan dsket chesv iaour dearf riend jessi cawho haspr omise dtoen suret heirs afede liver ystop reall yimus tcong ratul ateou rhost sinth eloca lscou tgrou psfor thema rvell ouswa yinwh ichth eyhav eorga nised ourtr avelt hough someo fthes couts haveb eenra therm oreso licit ousth anweh adexp ected askin grath eralo tofqu estio nsabo utour plans stopg enera llyih opeth eywer esati sfied witht heans werst hatwe gaveb utwef eelth atwea reatr iskof overs tayin gourw elcom esowe willr eturn tolon donon tuesd aysto peven thoug hweha veenj oyedo urtim etoge thert hereh asbee nsome debat eamon gtheg roupa boutw herew eshou ldvis itnex tstop there areso manyi ntere sting sites tovis italo ngthe majes ticth amese stuar ysowe haved ecide dtosp litin totwo group sstop ralfw illle adone party onato uroft heken tcoas twhil eiamv erymu chloo kingf orwar dtoex plori ngthe essex marsh essto pdole tmekn owify ouhav eabet terid eabut ihave beent oldth atcan ewdon sfift eenth centu rychu rchaf fords anele vatio nwith awide viewo fthes urrou nding lands inthi sothe rwise rathe rflat lands capea ndist hesit eofan other fasci natin gtowe rwhic hiwil lbece rtain toske tchfo ryous topfi nally ifyou havea nyfur therr eques tsfor speci ficin forma tiont henpe rhaps youco uldle aveam essag eform eatth epost offic ether estop karlm essag eends'" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wcat(chunks(spb, 5))" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'uwlomwrlouiounoddsoiobiarmuirtsnhsduernwotsenoyiywtykeeiuowoaidtuisoontvrfdiorentserplsgluthauuralahhvadrthossbamothhpdnhouoorsgahhridtstebfharfsnwmernnndongajometheetngawwusxpeoiegssoesheredepnoppweeyotnslvuofrxiexhoenyvtdtethnnthuufseoheosugsieeetsattnrinecleneosiyuarrsrinatesoemgmhtcrpmgs'" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat(w[-1] for w in chunks(spb, 5))" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(87, 47, 35)" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "locR = [i for i, c in enumerate(spb) if c == 'r']\n", + "locD = [i for i, c in enumerate(spb) if c == 'd']\n", + "locF = [i for i, c in enumerate(spb) if c == 'f']\n", + "len(locR), len(locD), len(locF)" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(3, 586, 1169, 583),\n", + " (34, 350, 666, 316),\n", + " (50, 519, 988, 469),\n", + " (124, 395, 666, 271),\n", + " (163, 769, 1375, 606),\n", + " (197, 337, 477, 140),\n", + " (305, 337, 369, 32),\n", + " (368, 769, 1170, 401),\n", + " (370, 866, 1362, 496),\n", + " (419, 830, 1241, 411),\n", + " (440, 769, 1098, 329),\n", + " (450, 798, 1146, 348),\n", + " (485, 958, 1431, 473),\n", + " (512, 830, 1148, 318),\n", + " (522, 594, 666, 72),\n", + " (558, 960, 1362, 402),\n", + " (563, 866, 1169, 303),\n", + " (976, 1173, 1370, 197),\n", + " (1002, 1086, 1170, 84),\n", + " (1011, 1193, 1375, 182),\n", + " (1160, 1248, 1336, 88),\n", + " (1165, 1256, 1347, 91)]" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "triples = []\n", + "for r in locR:\n", + " for d in locD:\n", + " for f in locF:\n", + " if d > r:\n", + " if d - r == f - d:\n", + " triples += [(r, d, f, d - r)]\n", + "triples" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dearunclewilhelma s youpromisedwet\n", + "horoughlyenjoyedo u rvisittoyourco\n", + "usininlincolnandf o unditmostinfor\n", + "mativestopthebeau t ifulcathedrala\n", + "lmostjustifiedour v isitonitsownan\n", + "dourhostssharedwi t hussomeinteres\n", + "tingdrawingsofthe t owersyoumentio\n", + "nedstoptheygracio u slyallowedmeto\n", + "copythesketchesan d explainedmucha\n", + "bouthowthetowersa r ebuiltandwhyst\n", + "opasusualiwillsen d youmynotesands\n", + "ketchesviaourdear f riendjessicawh\n", + "ohaspromisedtoens u retheirsafedel\n", + "iverystopreallyim u stcongratulate\n", + "ourhostsintheloca l scoutgroupsfor\n", + "themarvellouswayi n whichtheyhaveo\n", + "rganisedourtravel t houghsomeofthe\n", + "scoutshavebeenrat h ermoresolicito\n", + "usthanwehadexpect e daskingrathera\n", + "lotofquestionsabo u tourplansstopg\n", + "enerallyihopethey w eresatisfiedwi\n", + "ththeanswersthatw e gavebutwefeelt\n", + "hatweareatriskofo v erstayingourwe\n", + "lcomesowewillretu r ntolondonontue\n", + "sdaystopeventhoug h wehaveenjoyedo\n", + "urtimetogetherthe r ehasbeensomede\n", + "bateamongthegroup a boutwherewesho\n", + "uldvisitnextstopt h erearesomanyin\n", + "terestingsitestov i sitalongthemaj\n", + "esticthamesestuar y sowehavedecide\n", + "dtosplitintotwogr o upsstopralfwil\n", + "lleadonepartyonat o urofthekentcoa\n", + "stwhileiamverymuc h lookingforward\n", + "toexploringtheess e xmarshesstopdo\n", + "letmeknowifyouhav e abetterideabut\n", + "ihavebeentoldthat c anewdonsfiftee\n", + "nthcenturychurcha f fordsanelevati\n", + "onwithawideviewof t hesurroundingl\n", + "andsinthisotherwi s eratherflatlan\n", + "dscapeandisthesit e ofanotherfasci\n", + "natingtowerwhichi w illbecertainto\n", + "sketchforyoustopf i nallyifyouhave\n", + "anyfurtherrequest s forspecificinf\n", + "ormationthenperha p syoucouldleave\n", + "amessageformeatth e postofficether\n", + "estopkarlmessagee n ds\n" + ] + } + ], + "source": [ + "t = cat(c if c.isupper() else '.' for c in pbscap)\n", + "col = 305 % 32\n", + "tcs = chunks(spb, 32)\n", + "stcs = [wcat([c[:col], c[col], c[col+1:]]) for c in tcs]\n", + "print(lcat(stcs))" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "780" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results = []\n", + "for l in range(1, 40):\n", + " for i in range(l):\n", + " cs = chunks(spb, l, fillvalue=' ')\n", + " t = cat(c[i] for c in cs)\n", + " f = Ptrigrams(t)\n", + " results += [{'l': l, 'i': i, 't': t, 'f': f * l}]\n", + "len(results)" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'l': 39,\n", + " 'i': 37,\n", + " 't': 'gnfsihalnpaseseasemerenhworttaragsods ',\n", + " 'f': -5279.032049169729},\n", + " {'l': 38,\n", + " 'i': 35,\n", + " 't': 'ocatteseoslsuteerefloatsoralycanaepsls ',\n", + " 'f': -5213.417095225861},\n", + " {'l': 39,\n", + " 'i': 24,\n", + " 't': 'mosdsepenjessoloitatmeegdemraceshotes ',\n", + " 'f': -5197.69063368185},\n", + " {'l': 1,\n", + " 'i': 0,\n", + " 't': 'dearunclewilhelmasyoupromisedwethoroughlyenjoyedourvisittoyourcousininlincolnandfounditmostinformativestopthebeautifulcathedralalmostjustifiedourvisitonitsownandourhostssharedwithussomeinterestingdrawingsofthetowersyoumentionedstoptheygraciouslyallowedmetocopythesketchesandexplainedmuchabouthowthetowersarebuiltandwhystopasusualiwillsendyoumynotesandsketchesviaourdearfriendjessicawhohaspromisedtoensuretheirsafedeliverystopreallyimustcongratulateourhostsinthelocalscoutgroupsforthemarvellouswayinwhichtheyhaveorganisedourtravelthoughsomeofthescoutshavebeenrathermoresolicitousthanwehadexpectedaskingratheralotofquestionsaboutourplansstopgenerallyihopetheyweresatisfiedwiththeanswersthatwegavebutwefeelthatweareatriskofoverstayingourwelcomesowewillreturntolondonontuesdaystopeventhoughwehaveenjoyedourtimetogethertherehasbeensomedebateamongthegroupaboutwhereweshouldvisitnextstoptherearesomanyinterestingsitestovisitalongthemajesticthamesestuarysowehavedecidedtosplitintotwogroupsstopralfwillleadonepartyonatourofthekentcoastwhileiamverymuchlookingforwardtoexploringtheessexmarshesstopdoletmeknowifyouhaveabetterideabutihavebeentoldthatcanewdonsfifteenthcenturychurchaffordsanelevationwithawideviewofthesurroundinglandsinthisotherwiseratherflatlandscapeandisthesiteofanotherfascinatingtowerwhichiwillbecertaintosketchforyoustopfinallyifyouhaveanyfurtherrequestsforspecificinformationthenperhapsyoucouldleaveamessageformeatthepostofficetherestopkarlmessageends',\n", + " 'f': -4923.336122800165}]" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(sorted(results, key=lambda r: r['f']))[-4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rdfresults = [r for r in results if 'rdf' in r['t']]\n", + "len(rdfresults)" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'l': 32,\n", + " 'i': 17,\n", + " 't': 'suotvttudrdfuulntheuwevrhrahiyooheecftsewispen',\n", + " 'f': -6630.535098505313}]" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rdfresults" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/2020/2020-challenge5.md b/2020/2020-challenge5.md index 55703b7..4f3b7ea 100644 --- a/2020/2020-challenge5.md +++ b/2020/2020-challenge5.md @@ -78,13 +78,51 @@ print(pb) open(plaintext_b_filename, 'w').write(pb) ``` +```python Collapsed="false" +pb = """dear uncle wilhelm as you promised we thoroughly enjoyed our visit to your cousin in lincoln and +found it most informative stop the beautiful cathedral almost justified our visit on its own and our +hosts shared with us some interesting drawings of the towers you mentioned stop they graciously +allowed me to copy the sketches and explained much about how the towers are built and why stop as +usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure +their safe delivery stop really i must congratulate our hosts in the local scout groups for the +marvellous way in which they have organised our travel though some of the scouts have been rather +more solicitous than we had expected asking rather a lot of questions about our plans stop generally +i hope they were satisfied with the answers that we gave but we feel that we are at risk of +overstaying our welcome so we will return to london on tuesday stop even though we have enjoyed our +time together there has been some debate among the group about where we should visit next stop there +are so many interesting sites to visit along the majestic thames estuary so we have decided to split +into two groups stop ralf will lead one party on a tour of the kent coast while i am very much +looking forward to exploring the essex marshes stop do let me know if you have a better idea but i +have been told that canewdons fifteenth century church affords an elevation with a wide view of +the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating +tower which i will be certain to sketch for you stop finally if you have any further requests for +specific information then perhaps you could leave a message for me at the post office there stop karl +message ends""" +``` + +```python Collapsed="false" +spb = sanitise(pb) +``` + ```python Collapsed="false" pbs = pb.split() [pbs[i+1] for i, w in enumerate(pbs) if w == 'stop'] ``` ```python Collapsed="false" -cat(w[0] for w in pbs) +wcat(segment(cat(w[0] for w in pbs))) +``` + +```python Collapsed="false" +wcat(segment(cat(w[1] for w in pbs if len(w) > 1))) +``` + +```python Collapsed="false" +wcat(segment(cat(w[-1] for w in reversed(pbs)))) +``` + +```python Collapsed="false" +max([len(w) for w in pbs]) ``` ```python Collapsed="false" @@ -94,6 +132,7 @@ cat(w[0] for w in pbs) ```python Collapsed="false" tt = ''.maketrans('rdf', 'RDF') pbcap = wcat(pb.split()).translate(tt) +spbcap = wcat(spb.split()).translate(tt) pbcap ``` @@ -102,6 +141,64 @@ pbcap2 = cat(('\n' + c) if c.isupper() else c for c in pbcap) print(pbcap2) ``` +```python Collapsed="false" +wcat(chunks(spb, 5)) +``` + +```python Collapsed="false" +cat(w[-1] for w in chunks(spb, 5)) +``` + +```python Collapsed="false" +locR = [i for i, c in enumerate(spb) if c == 'r'] +locD = [i for i, c in enumerate(spb) if c == 'd'] +locF = [i for i, c in enumerate(spb) if c == 'f'] +len(locR), len(locD), len(locF) +``` + +```python Collapsed="false" +triples = [] +for r in locR: + for d in locD: + for f in locF: + if d > r: + if d - r == f - d: + triples += [(r, d, f, d - r)] +triples +``` + +```python Collapsed="false" +t = cat(c if c.isupper() else '.' for c in pbscap) +col = 305 % 32 +tcs = chunks(spb, 32) +stcs = [wcat([c[:col], c[col], c[col+1:]]) for c in tcs] +print(lcat(stcs)) +``` + +```python Collapsed="false" +results = [] +for l in range(1, 40): + for i in range(l): + cs = chunks(spb, l, fillvalue=' ') + t = cat(c[i] for c in cs) + f = Ptrigrams(t) + results += [{'l': l, 'i': i, 't': t, 'f': f * l}] +len(results) +``` + +```python Collapsed="false" +list(sorted(results, key=lambda r: r['f']))[-4:] +``` + +```python Collapsed="false" +rdfresults = [r for r in results if 'rdf' in r['t']] +len(rdfresults) +``` + +```python Collapsed="false" +rdfresults +``` + ```python Collapsed="false" ``` diff --git a/2020/plaintext.5b.txt b/2020/plaintext.5b.txt index 5ee6388..957229f 100644 --- a/2020/plaintext.5b.txt +++ b/2020/plaintext.5b.txt @@ -5,15 +5,15 @@ allowed me to copy the sketches and explained much about how the towers are buil usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure their safe delivery stop really i must congratulate our hosts in the local scout groups for the marvellous way in which they have organised our travel though some of the scouts have been rather -more solicitous than we had expected asking rather alot of questions about our plans stop generally +more solicitous than we had expected asking rather a lot of questions about our plans stop generally i hope they were satisfied with the answers that we gave but we feel that we are at risk of -overstaying our welcome so we will return to london on tuesday stop eventhough we have enjoyed our +overstaying our welcome so we will return to london on tuesday stop even though we have enjoyed our time together there has been some debate among the group about where we should visit next stop there are so many interesting sites to visit along the majestic thames estuary so we have decided to split -into two groups stop ralf will lead one party on at our of the kent coast while i am very much +into two groups stop ralf will lead one party on a tour of the kent coast while i am very much looking forward to exploring the essex marshes stop do let me know if you have a better idea but i -have been told that ca new dons fifteenth century church afford san elevation with a wide view of +have been told that canewdons fifteenth century church affords an elevation with a wide view of the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating tower which i will be certain to sketch for you stop finally if you have any further requests for -specific information then perhaps you could leave a message for meat the post office there stop karl +specific information then perhaps you could leave a message for me at the post office there stop karl message ends \ No newline at end of file -- 2.34.1 From 31de8482cc0ad3d8a1f4813cf78f9ac6e2c1ffe8 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sat, 5 Dec 2020 09:25:10 +0000 Subject: [PATCH 06/16] Done challenge 6 --- 2020/2020-challenge5.ipynb | 23 +++ 2020/2020-challenge5.md | 5 + 2020/2020-challenge6.ipynb | 356 +++++++++++++++++++++++++++++++++++++ 2020/2020-challenge6.md | 98 ++++++++++ 2020/ciphertext.6a.txt | 1 + 2020/ciphertext.6b.txt | 1 + 2020/plaintext.6a.txt | 39 ++++ 2020/plaintext.6b.txt | 20 +++ 8 files changed, 543 insertions(+) create mode 100644 2020/2020-challenge6.ipynb create mode 100644 2020/2020-challenge6.md create mode 100644 2020/ciphertext.6a.txt create mode 100644 2020/ciphertext.6b.txt create mode 100644 2020/plaintext.6a.txt create mode 100644 2020/plaintext.6b.txt diff --git a/2020/2020-challenge5.ipynb b/2020/2020-challenge5.ipynb index 363693c..fbedeb9 100644 --- a/2020/2020-challenge5.ipynb +++ b/2020/2020-challenge5.ipynb @@ -339,6 +339,29 @@ "[pbs[i+1] for i, w in enumerate(pbs) if w == 'stop']" ] }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'ttargetrdfk'" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pbs = pb.split()\n", + "cat(pbs[i+1][0] for i, w in enumerate(pbs) if w == 'stop')" + ] + }, { "cell_type": "code", "execution_count": 90, diff --git a/2020/2020-challenge5.md b/2020/2020-challenge5.md index 4f3b7ea..63d6351 100644 --- a/2020/2020-challenge5.md +++ b/2020/2020-challenge5.md @@ -109,6 +109,11 @@ pbs = pb.split() [pbs[i+1] for i, w in enumerate(pbs) if w == 'stop'] ``` +```python Collapsed="false" +pbs = pb.split() +cat(pbs[i+1][0] for i, w in enumerate(pbs) if w == 'stop') +``` + ```python Collapsed="false" wcat(segment(cat(w[0] for w in pbs))) ``` diff --git a/2020/2020-challenge6.ipynb b/2020/2020-challenge6.ipynb new file mode 100644 index 0000000..da53ea3 --- /dev/null +++ b/2020/2020-challenge6.ipynb @@ -0,0 +1,356 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 21, + "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", + "import collections" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 6\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": 8, + "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 = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "fc = collections.Counter(sca)\n", + "plot_frequency_histogram(fc, sort_key=fc.get)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "held KeywordWrapAlphabet.from_last \n", + "\n", + "eutzo propo khzdc gowfs jovhp ahbsa euvwn ctotq lwssk bdtsd ukcvv dnorc shhgm ebpqf unotk enwhc putjs eqjat egceo giutb femtq jcuwt ebuop ategj euuss ebfiz dvhkp ewpio fsoaq urwag pyier hwhpg auwfh btuwn oesvq dussv vatsw ehnqi ikbhv erhfo tiwjw ejwsp etega ezswg ptwsh osxys cgowf ierdn gaery xstvs fezov egvva oongt owbfp etjwn ciots pqgtv vafga eytjg owuia omhki hbops oiiih zdprl erchh mhbtk enhrt jotuv ayosu ofves hsihg ptsvk euuga uwfhb tnsdx ssqhu grapz yfctc zdgii eitjs yjoff sapob nstqg aaemo snghu avdpw ehgar zdasm hbtie rvvai zdvwm kuivv dxsmk hshrt jscof otidp qaqtt jwsfc tysih orgii hhdos sverd otvvr hsfkt ghgap idgrr hhshh cpiih sduia proiz oprop olnkc vvtjs sedag spegt wgago thong iieie qwnaw fhrwk iivva qgccw nezdt gcxol qttjs srmen wsvio wgcpu hteur trqdn qggqz kqbaq ttjsl ebfno fkssj ofuem hkiei gqgtw wtqcs nmkhf tegaa ergeg vvaae mkbhu onguo kbhue gjsrt sskra piseb fyose plhio gssag cfsvk hcver uiovv agspe gthrt hbdpi tjsrh vdgpa hbdpw nagae hakbt jsnwd bhgox srvva vvrhs whsku zaerc puuri ovvak gfhfd tiuts dprtj otgot hqokb ekrag kcvvt jsdtg cxolq ttjss rmenw sviow gcpuh teurw nvvaw ycawr aclei agrau qrkft kenue gvvag spegt hrthb dpisv eowgd csnvh dviih fotid wiiqg cvwau ongii hmwhg aeplh ioaen iwroi ieidc gowfm eiejw nciih rauqr kftke njofn sgvii hqowb ttmtj sfemd iiati ihhpd qlkht cgowf dtgcx sfeik kbhuq rqhsq creua piseb feyan ohteu rhcps susxe bfmsn vkats duyag iotsp qgtqb tjssr menws vurqc puwnv vakgn hwhjp owgiq efuon gpovv thomu hapim holkh tqttj stqcr kbhro rvwau gaaen awlkb hvvao ohewn uitjs pegtd egvka piyvv dvhav egitr qdlkb eqzny sieja nesvo nqiih ggkja ezopu tjswe mlwqk kzyvv aeyan ohteu rwnhh shlie rbhsn yotav cpugq gtjsf hfdti utsgt emvva hosvs ngong hoysk pewvv dviih tunzt ysnvm shioi tdnen ciihi iedau wnvko cgowf sqtth bwkii hwhji dtgcx wncwn ukdns dprsh japot aonhk fqbtj sdago uicaw nvvan osvia nshto myscp iatqa riagh phzlh rowit jsmhh seuae itegh hirgt dprct onvvd vfdui mdoct dcpws vgyae nvoev hwjed vzdui dcgah rtqpr ksgos opiih wraen asrph rgtsv onghg qgrer cqrct sevwo pongt cprcp ucsca uicqb agiik htjwn mwncw tyose batgo tongi ieitj syosd pirer cqrct sevwo ptcpr cputj snejc cotke numsv smysu usbwi drfdt snvzy vvcuw suemh iikbh pswig ooiih poitc phopi ihicb orgqo odcvi ahiih meezl kiejo cpvoo sdprc vgais ruioe bayoa tepno nhrav sevwo phyui aoiie iuuss tsgns evwop egtof kewej auiot oncsg kbfeh whzle hcprc aothp aegcp ugtem ewrvv rhotu iihmi ejafs apsxr srkda picpu wkiiv vcuto towjw lhong orhbo ypukz fkbhq cteha twaue goosv htquc xsgte nvzcp swegn kbhqt dkgdv idays vvaiw ruigh ksvot kenuo rhpak bhfcc nicpb otton ylkbe qzneb fhhsh ltqfr qjcgs dtwnc eggsg hbeho rqcng zopro pongw tneom hlkya qcruf yazcu igtwa prseg ajcnv wncto twnie rootk enepo witjw svsej boneh dwtkh nqien sdtwg vvady nqkwj otkic upuvw tkheh gtewn vvdvk ajovh iouio riihd gkbfk bhqct komez sqbov hutsw jotvv aowsu wncfd tiyos mfsru orhro kbhki eebtf sjwht oerhh pdwnc osvva kgeqj atkcv vtjst qcrkb hrorv wauol newhr tjsme hmwqi eqehh sehtj syysr hzcms ldioc stues qdavv cpuan hakhu rwdov orwnc iieit jsdvi davag wnvsr aspvk cnzhk jawhd azuhk aebdn mshrt jsapq rdfth rthza cgdoo ngtow bfvvd vwtwh auoen osuwe ergcj xawpj srkiu ussvv auomh yadko trgqg tjstt onufo uwtke nuidc soiii hqcrv atosk vdxsu usfie rvvcu jccsn hgaaw pjsre bfmbo ywnci ieicv hiqcl gpats duene pldht toccv tiery orgio agday tjsct dauhd csbwi yqcwk zljov hioav aaytj sfhid kzsie rdeut hantd uwiej avehq vdtgy joseh khrmh iovgd xslve eewsv erves hiuro eqdme bfres votvv atrgv ewhgc pqdus whbah rtqoe vaukq knmci kaaon agday tjwsq baebf yerme uvkie icuuo kbhqb tjsnk vorsw hqdpd owbte qowbt hgtqi ihhpd qlkht qfato tkenf sgqga kiswq ehsfu faegl\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break_mp(rsca, fitness=Pletters)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rdf \n", + "\n", + "ourlondonakelagroupshavebeenscoutingforcluesinareaswithalargegermanpopulationusingthecoverofgoodturndaytovisitanumberofhousesandflatsknowntobeoccupiedbyforeignresidentsinmostcasestherewasnothingtoreportwhichisnotarealsurpriseasvksgrouphadalreadyvettedalotofthemandfoundnothingtoreportthebreakthroughcamewhenoneofthelandladiesmentionedthatshewassadtoseeherpreviousresidentleavesosuddenlybutgladthattheyhadbeenabletorecommendsuchanicereplacementfortheflatimighthavemissedtheimportanceofthisbutweheardthesamestoryatthreedifferentaddressesintheeastendoflondonallwiththesamedeparturedateandthatcoincidedwiththeoriginalarrivalofthespyclisttouringgroupfromnorfolkoneofthelandladieshadsomewhatfortuitouslykeptarecordofthecomingsandgoingsofherresidentsandwasabletodescribevisitorstothedepartedtenanttherehadbeenanincreaseinthenumberoverthethreeweeksleadinguptotheirdepartureandthatdatecoincidedwiththearrivalofthespyclisttouringgroupintheukicirculateddescriptionsofthedepartedtenantstoouragentsattheportauthoritiesandtheywereabletoconfirmthatagroupmatchingthedescriptionhadleftthecountrythedayafterthespyclistgrouparrivedatkingscrossouragentsandakelagroupsinessexandkentwereaskedtoreportonthespyclistgroupsintheirneighbourhoodsandbothteamssentmealistofthetouringpartiesreconcilingthemagainstthepartyoftwentythatsetofffromlincolnwehavelostanotherfivealongthewayluckilytheakelagroupinessexhadbeenwatchingforthedeparturefromtheeastendandsoweknowthatthefulltwentysetoffalongthethamesintwogroupsoftenwitheightarrivinginswaleandsevenatcanewdontheacrosticinthelasttelegramweinterceptedspelledoutthemessageattargetrdfandiranthatpastmyairministrycontactswhoatlastagreedtobriefmeontheirconcernsrdfstandsforradiodirectionandfindingiquestionedthisthinkingitwasanerrorandthattheymeantradiodirectionfindingthenavigationsystemweusebutapparentlythisissomethingnewfromtheboffinsonthetizardcommitteetheycallitchainhomeanditreferstoanewaeroplanedetectionsystemthatusesreflectionofradiowavestorangefindaswellasindicatebearingfromairthreatstheyhavebeenexperimentingwiththisforawhileandarenowbuildingoutaseriesofmaststogivefrontlinewarningofairattacksthefirstfewstationsarebeingbuiltinnorfolklincolnandessextoprovidearingofdefencearoundlondonanditlookslikeourspyclistfriendsarehuntingforinformationaboutthistechnologyitisnotcleariftheyknowwhatitisbutitiscertainthatwehavetostopthemfindingoutiamalsonotsurewhatthemissingpartymembersaredoingitcantbejustmorespyingastheircoverwiththetouringpartiesallowedthemasmuchaccessastheywerelikelytogetsosomethingelseisupiamhopingthattheattachedinterceptwillgiveusaclueweanalysedtheencryptedtelegramandfoundthatitusesaclassicadfgvxcipheritusesthesamekeywordforthetranspositionstageofthecipherasihaveusedforthisvigenerecipherandknowingthatitshouldbereasonablystraightforwardtocracktheirmessagebutyouwillhavetocheckthedetailsforyourselfasihavetogoharryhasaskedmetotraveltocaistortosetupacommandpostattherdftowerincaseweneedtoactquicklyifwecancrackthisoneandworkoutwhatisgoingonthenihopewecanmountacountertothespyclistoperationbeforeitsucceedspearl\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": 19, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "our london akela groups have been scouting for clues in areas with a large german population using\n", + "the cover of good turn day to visit a number of house sandflats known to be occupied by foreign\n", + "residents in most cases there was nothing to report which is not a real surprise as v ks group had\n", + "already vetted alot of them and found nothing to report the breakthrough came when one of the land\n", + "ladies mentioned that she was sad to see her previous resident leave so suddenly but glad that they\n", + "had be enable to recommend such a nice replacement for the flat i might have missed the importance\n", + "of this but we heard the same story at three different addresses in the east end of london all with\n", + "the same departure date and that coincided with the original arrival of the spy c list touring group\n", + "from norfolk one of the land ladies had somewhat fortuitously kept a record of the comings and\n", + "goings of her residents and was able to describe visitors to the departed tenant there had been an\n", + "increase in the number over the three weeks leading up to their departure and that date coincided\n", + "with the arrival of the spy c list touring group in the uk i circulated descriptions of the departed\n", + "tenants to our agents at the port authorities and they were able to confirm that a group matching\n", + "the description had left the country the day after the spy c list group arrived at kings cross our\n", + "agents and akela groups in essex and kent were asked to report on the spy c list groups in their\n", + "neighbourhoods and both teams sent me a list of the touring parties reconciling them against the\n", + "party of twenty that set off from lincoln we have lost another five along the way luckily the akela\n", + "group in essex had been watching for the departure from the east end and so we know that the full\n", + "twenty set off along the thames in two groups often with eight arriving in swale and seven at ca new\n", + "don the acrostic in the last telegram we intercepted spelled out the message at target rdf and iran\n", + "that past my air ministry contacts who at last agreed to brief me on their concerns rdf stands for\n", + "radio direction and finding i questioned this thinking it was an error and that they meant radio\n", + "direction finding the navigation system we use but apparently this is something new from the boffins\n", + "on the tizard committee they call it chain home and it refers to a new aeroplane detection system\n", + "that uses reflection of radiowaves to range find as well as indicate bearing from air threats they\n", + "have been experimenting with this for a while and are now building out a series of masts to give\n", + "frontline warning of air attacks the first few stations are being built in norfolk lincoln and essex\n", + "to provide a ring of defence around london and it looks like our spy c list friends are hunting for\n", + "information about this technology it is not clear if they know what it is but it is certain that we\n", + "have to stop them finding out i am also not sure what the missing party members are doing it cant be\n", + "just more spying as their cover with the touring parties allowed them as much access as they were\n", + "likely to get so something else is up i am hoping that the attached intercept will give usa clue we\n", + "analysed the encrypted telegram and found that it uses a classic adfg vx cipher it uses the same\n", + "keyword for the transposition stage of the cipher as i have used for this vi genere cipher and\n", + "knowing that it should be reasonably straightforward to crack their message but you will have to\n", + "check the details for yourself as i have to go harry has asked me to travel to caistor to setup a\n", + "command post at the rdf tower in case we need to act quickly if we can crack this one and workout\n", + "what is going on then i hope we can mount a counter to the spy c list operation before it succeeds\n", + "pearl\n" + ] + } + ], + "source": [ + "pa = prettify(vigenere_decipher(sca, key_a))\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3756" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'addfaagdgvfgddfddfgxdvfddgdffdffggdgdfggfvgxdfgdaaggddaafgdfgxadfvfgdvgfaagfdvfgggdfgddfgfggdvfgagaagfvafvgvdgaaadgfgvagagdfgfggdfaddvgggxfvgvfdaddadfaafgaddvddaafggfdfdfdgfvgxdvgggxfvgvfdadfddvafggggdgdfgffxdvgddvgggffvaffvgvgddffgagfddvgfdgdgfvgfgggfffaafadvfgagggdgdfffafdfdffdgfaaafdfaafgadgfdfddgvgddfdvfgggdgdfdvgdaffvgdgggddfgfgfdvgffdaafgadgfggfvfxfgdfavdfgdggdgdffddfgfgffgfvggdgdvfgagfvfgggdgdfdfaagdggdgdvgfaffvgddfavdfgdaafgaddvggdgdvfgfaggdgdfvaffaavadgaaavdfaaffdvgffxfdaadddfadafaadvggdgdvfgggdgdvgfaafgadggdgdfdgdfaaavdffgfdvafxfvgxdfgdgfffaavafgfvggdadfgfgggdfvfgagdffgfvgvagdgggfvfxgdfvggdfddggggdgdfffafgdfvffggdgdffvfgddfvffdvfgaggfggfvgdffgfggfvfxggdgdffdfvddaafdfvgdgggfaggdgvfxfxdfgfdgaagddfadgxdvggdgffdfvafvgvgdfdaaggdfgfggagdvafggggdgdfdadfaagvggdvafgvfdddfdfvddfaaddfavdvdddfaafgadgxdfdgaaavdfgffxdffgggffgvdddgggdvffdfaaadffdvgddvfgagdvgggfggfvfxdvgggfgfdvfffxfddvdddvggvadvgfaaadffdvgdaadafddfaafgadfvfgdddfgxdfdgaaavdffddfaagdfgdfadggfvgvgfdfdvggfxgdfvfxdfgdfdvadvgggxdvfdfdfxgdfvavdvaddfgvgfaafdfdgxdvggdgaaavdfgdvadgdvagdgfddfavdffdfvafgfdfddgvgddvggvagfggfvfxgfaaafdfggvaffgvgfggdadffvgvgdfxgddvffaagdvaddfvfgdddfgdfgfgfvgxaagfaafdaaddfafvafddfvfgdddffggggdaaggdvfvfgaaggggdgdvgffxfvdvfgggddfvgvfdaddagddvfgagaddvgfaagfggdfgdgfggfvfxgdaafdafdgaagfdadfdffgagdvavdffgggdgdfaaddddfvfffxaafgvadvfgagfadfvadavaggdgdffvgdgggfaggdgvfxfxdfdvfgfadffgggaafgadfvfgdddfgxdfaagddfgddfgvfgdvggdfaddvgxdvfdfdgvgfdfggdgdvgfggfvgfdfddgvgddffvgvgdafgvgggvgddfddfvffffgvfgdvddaaggdvfvfggfgfggfvfxdfgfggaadafddvgfdgdvfgagaagfaaafdffxfdaafgaffvgdfvgvgddxfvgvgdfgdfvadgfvffdfdvgfdfgfgfdffgggdvaafddvfgfvgdaddfgdggfvaaavfvdvadgvfgfxfddfaagfaafggggfgvgdfxgddvgfdfgfgfggfvfxgagvaagdgddffdgfgxdvggdgfvgvgddgfvgfgggxfvgvfdaddadfaddvafafdvddgvfdggggfvgddfgffvfdavdfaafgaddvgxfvgvfdadfxgddfafdfgddvggdvafgxdfddfvgvfdadgffddvfxaagxaavagvfggddfffaagdfadfadgfggfvfxgvgfdffvafggdgdffdfvddaafdafdvgfdgdvfgagdafvaagggfffdvagdgggdadffxfvgfgfdvdafddfdagvggdvafaafgvaggdgdvfgaggxdfgddfggfvaafdaagdffggdgdffdfvddaafdgfggdgaaggffdvagdggggxdffdfdfxgddfavdffgggfvgvgdaddffxaagdgggvgddfaafgadggdgdfddfdfvddfaddfvgvfdadafaafdfddvfgggfvggdgdfgxgdfvfgagdgaafgadgfgfggfvfxdvafvafvgvdgaaavdfaagfgvagagdfgfggdvfvfgaadafvgvggdgfvgxdadfgfggggfvaagdgdaafgagdffvgvgdgggdaaavdffdggdgdffgfxfddfaagfdffddfgggvgffafgfvgxaafgadgxdfgxdvfdfdffaafadfggdgdfgddfgagvdvgddfadaagdgdaafgagdfffdffggggfgfggfvfxgdaafdafgffxaagdggvagxdvfdfdgddfgggvgdfgggfvfdfvfgadfvfgggdgdvgfgxdfdffaaafgadgxdvfdfdggdgdffggggdaaavdffdggfvffdfdfgggxdvggdggvgfaffvgdggdgdfafdvfgaafdgfggaaagdffvaffvgvgdaaadavdffggggvgddfgxdgdffggxdfgxdvfdfdaafdfdgddfaggdfvgvfxdadfaffvgddfgddfgggvgdfgdvfgagdgfvffdfgfggfvfxdfavdffgdvafvafvgvadfvfgfvgggxdvgfdggvgfggfvfxgdfvdddfdfadgxdvggdgfvgvgdfvgddvagdvfgaafdfxfdaafgggdgdffggxdfaagddfaadafddfggfvgddfgggvgdfggxdvggdgaagxdgfvfddfgggddfaagfgvgddffvafadgdaagxdvfgaggffxdgfvggfvaggdaafxdggfaafgadaddfgfddgddvfxggdvfvfggffvafggdgdfgfdfdvfffxfvgdggaafgggfdaafgadffaagdfagfaffvgdvafvgvaafgadvafvgvgdafgddvdffgadgfggfvgfgggvadvagfggfvfxaddfggaadvfdgffvafvafvgvgdgxdvgfdgdfgfgfdgfvgvfdaddadfgfdffgggdvfgggdgdfgvgfgvaafdgxaavagvgfdvfgagvafvgvgdgddfffaagdfaaadafddfddfdfvddfaaddfavdvdddfgfggfvfxfaaagdfd'" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tscb = column_transposition_decipher(scb, 'rdf', fillcolumnwise=False, emptycolumnwise=True)\n", + "tscb" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'biauxqhoiylokiopwkiwryiuawhaqiybrqlvavlqwiuivwlqdavzrxkabvxddivwiblwyrxobgiaqblhaqviikrylwyrxobolcwwkivslulwvrcrxuiqdolvkkrvwvpanlqdwkipciiovaciaqbvihxuilqwkilucruwuivvlvoaqbvwrsqieiuwkioivvqrwklqdrqwkiiauwklvcruieiuaqblwklqnwkizpazkaeiaplvsoahibcalwklqwklvaqbwkikiaeiqozsryiuvpazqrwgivwurqdiqrxdkwrsurwihwwkipcurpwkirqhrplqdvwrupvwrswkiorhaoruwvduxssivkauibylwkpizrxuoawivwdlcwwkigiaxwlcxohorhnbielhiaqbyikaeivsiqwpxhkwlpiabplulqdlwvwrslwvvlpsolhlwzlvabpluagoiaqbrqhiyikaeioiauqibwrxvilwsursiuozlwyloosurelbixvaooylwkaeiuzkldkoieiorcvihxulwzvwrsvaciwzpxvwgirxusulpauzhrqhiuqqryavaoahnrchrqhiqwuawlrqawwklvsrlqwhrxobgulqdblvavwiuvwrsuaockavgiiqdleiqwkiahhrpsaqzlqdnizgzwkiruwvduxssilqniqwaqbrqhiyiauiuixqlwiblylooxviwklvwrvihxuirxucxwxuihrppxqlhawlrqvvwrsivwagolvklqdavacisoaqcrurxumrxuqizkrpilvivviqwlaolqrubiuwraerlbxqsoiavaqwvxusulvivvwrstxauuiovylwkrxukrvwyrxobgiblcclhxowwruivroeiaqblyrxobsuiciulwlcyihrxobvolsayazxquipaunibvwrsxvircwkiorhaoclvklqdgrawvpldkwgisrvvlgoigxwlcaqzwklqdyiuiwraoaupwkiorhaovwkawpldkwyioosuieiqwrxubisauwxuiaqbwkihorhnhrxobcaoolqwrwkiyurqdkaqbvvwrslczrxkaeiavxddivwlrqagrxwkrygivwwrauuaqdirxuwuaeiowkiqsoiavioiwxvnqryaqbyiyloopaniwkiuitxluibauuaqdipiqwvvwrsuaocvsauwzyloouiwxuqwrorqbrqwklvyiinaqbyloowkiqwuaeiowrpiiwylwkxvcruwkiclqaovwadircrxuabeiqwxuiykiqyiylooaoouidurxsgicruiuiwxuqlqdkrpivwrsieiqlczrxbrqrwylvkxvwrsurhiibylwkrxuruldlqaosoaqwkiqyiauiagoiwruiwxuqylwkaykroiwuiavxuircbuaylqdvskrwrduaskvaqbbivhulswlrqvrcwkivilpsruwaqwoaqbpaunvcruzrxaqbzrxuculiqbvwrvwxbzvwrsbiwalovrczrxuylvkivvkrxobgiviqwlqwkixvxaoyazxvlqdzrxuuipaunagoihorhnbielhivwrsnauo'" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ptscb = polybius_decipher(tscb, 'a', 'adfgvx', 'adfgvx', wrap_alphabet=KeywordWrapAlphabet.from_last)\n", + "ptscb" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "aghbicdklmnopqrstuvwxeyfzj \n", + "\n", + "dearunclewilhelmthetoweratcanewdonisasinterestingasyouhadsuggesteditwouldbeandicanseehowitwouldliftthespiritsofourenglishhostsmakingthemfeelsafeandsecureintheirfortressislandstopneverthelessnothingontheearthisforeverandithinktheymayhaveamisplacedfaithinthisandtheheavenlypowersmaynotbestrongenoughtoprotectthemfromtheoncomingstormstopthelocalortsgruppesharedwithmeyourlatestgiftthebeautifulclockdeviceandwehavespentmuchtimeadmiringitstopitssimplicityisadmirableandoncewehavelearnedtouseitproperlyitwillprovideusallwithaveryhighlevelofsecuritystopsafetymustbeourprimaryconcernnowasalackofconcentrationatthispointcouldbringdisasterstopralfhasbeengiventheaccompanyingkeybytheortsgruppeinkentandoncewearereunitediwillusethistosecureourfuturecommunicationsstopestablishingasafeplanforourjourneyhomeisessentialinordertoavoidunpleasantsurprisesstopquarrelswithourhostwouldbedifficulttoresolveandiwouldpreferitifwecouldslipawayunremarkedstopuseofthelocalfishingboatsmightbepossiblebutifanythingweretoalarmthelocalsthatmightwellpreventourdepartureandtheclockcouldfallintothewronghandsstopifyouhaveasuggestionabouthowbesttoarrangeourtravelthenpleaseletusknowandwewillmaketherequiredarrangementsstopralfspartywillreturntolondonthisweekandwillthentraveltomeetwithusforthefinalstageofouradventurewhenwewillallregroupbeforereturninghomestopevenifyoudonotwishustoproceedwithouroriginalplanthenweareabletoreturnwithawholetreasureofdrawingsphotographsanddescriptionsoftheseimportantlandmarksforyouandyourfriendstostudystopdetailsofyourwishesshouldbesentintheusualwayusingyourremarkableclockdevicestopkarl\n" + ] + } + ], + "source": [ + "word_b, score_b = simulated_annealing_break(ptscb, fitness=Ptrigrams,\n", + " plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('rdf', wrap_alphabet=KeywordWrapAlphabet.from_largest))\n", + "print(word_b, '\\n')\n", + "pb = keyword_decipher(ptscb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dear uncle wilhelm the tower at ca new don is as interesting as you had suggested it would be and i\n", + "can see how it would lift the spirits of our english hosts making them feel safe and secure in their\n", + "fortress islands top nevertheless nothing on the earth is forever and i think they may have a\n", + "misplaced faith in this and the heavenly powers may not be strong enough to protect them from the on\n", + "coming storms top the local orts gruppe shared with me your latest gift the beautiful clock device\n", + "and we have spent much time admiring its top its simplicity is admirable and once we have learned to\n", + "use it properly it will provide us all with a very high level of security stop safety must be our\n", + "primary concern no was a lack of concentration at this point could bring disasters top ralf has been\n", + "given the accompanying key by the orts gruppe in kent and once we are reunited i will use this to\n", + "secure our future communications stop establishing a safe plan for our journey home is essential in\n", + "order to avoid unpleasant surprises stop quarrels with our host would be difficult to resolve and i\n", + "would prefer it if we could slip away unremarked stop use of the local fishing boats might be\n", + "possible but if anything were to alarm the locals that might well prevent our departure and the\n", + "clock could fall into the wrong hands stop if you have a suggestion about how best to arrange our\n", + "travel then please let us know and we will make the required arrangements stop ralf s party will\n", + "return to london this week and will then travel to meet with us for the final stage of our adventure\n", + "when we will all re group before returning home stop even if you do not wish us to proceed with our\n", + "original plan then we are able to return with a whole treasure of drawings photographs and\n", + "descriptions of these important landmarks for you and your friends to study stop details of your\n", + "wishes should be sent in the usual way using your remarkable clock devices top karl\n" + ] + } + ], + "source": [ + "ppb = prettify(pb)\n", + "print(ppb)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1950" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(ppb)" + ] + }, + { + "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 +} diff --git a/2020/2020-challenge6.md b/2020/2020-challenge6.md new file mode 100644 index 0000000..167b5bf --- /dev/null +++ b/2020/2020-challenge6.md @@ -0,0 +1,98 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.support.text_prettify import * +from szyfrow.polybius import * +import collections +``` + +```python Collapsed="false" +challenge_number = 6 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +sca = sanitise(ca) +rsca = cat(reversed(sca)) +cb = open(ciphertext_b_filename).read() +scb = sanitise(cb) +``` + +```python Collapsed="false" +fc = collections.Counter(sca) +plot_frequency_histogram(fc, sort_key=fc.get) +``` + +```python Collapsed="false" +(word_a, wrap_a), score_a = keyword_break_mp(rsca, fitness=Pletters) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python Collapsed="false" +key_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams) +print(key_a, '\n') +pa = vigenere_decipher(sca, key_a) +print(pa) +``` + +```python Collapsed="false" +pa = prettify(vigenere_decipher(sca, key_a)) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +tscb = column_transposition_decipher(scb, 'rdf', fillcolumnwise=False, emptycolumnwise=True) +tscb +``` + +```python Collapsed="false" +ptscb = polybius_decipher(tscb, 'a', 'adfgvx', 'adfgvx', wrap_alphabet=KeywordWrapAlphabet.from_last) +ptscb +``` + +```python Collapsed="false" +word_b, score_b = simulated_annealing_break(ptscb, fitness=Ptrigrams, + plain_alphabet=string.ascii_lowercase, cipher_alphabet=keyword_cipher_alphabet_of('rdf', wrap_alphabet=KeywordWrapAlphabet.from_largest)) +print(word_b, '\n') +pb = keyword_decipher(ptscb, word_b) +print(pb) +``` + +```python Collapsed="false" +ppb = prettify(pb) +print(ppb) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(ppb) +``` + +```python Collapsed="false" + +``` diff --git a/2020/ciphertext.6a.txt b/2020/ciphertext.6a.txt new file mode 100644 index 0000000..979b721 --- /dev/null +++ b/2020/ciphertext.6a.txt @@ -0,0 +1 @@ +FXWCR SURSR NJCDL IRZGV MRYJS HJEVH FXYZQ LWRWT OZVVN EDWVD XNLYY DQRUL VJJIP FESTG XQRWN FQZJL SXWMV FTMHW FILFR IKXWE GFPWT MLXZW FEXRS HWFIM FXXVV FEGKC DYJNS FZSKR GVRHT XUZHI SBKFU JZJSI HXZGJ EWXZQ RFVYT DXVVY YHWVZ FJQTK KNEJY FUJGR WKZMZ FMZVS FWFIH FCVZI SWZVJ RVABV LIRZG KFUDQ IHFUB AVWYV GFCRY FIYYH RRQIW RZEGS FWMZQ LKRWV STIWY YHGIH FBWMI RZXKH RPJNK JERSV RKKKJ CDSUO FULJJ PJEWN FQJUW MRWXY HBRVX RGYFV JVKJI SWVYN FXXIH XZGJE WQVDA VVTJX IUHSC BGLWL CDIKK FKWMV BMRGG VHSRE QVWTI HHFPR VQIJX HYDSZ FJIHU CDHVP JEWKF UYYHK CDYZP NXKYY DAVPN JVJUW MVLRG RWKDS THTWW MZVGL WBVKJ RUIKK JJDRV VYFUD RWYYU JVGNW IJIHS KDIUU JJVJJ LSKKJ VDXKH SURKC RSURS ROQNL YYWMV VFDHI VSFIW ZIHIR WJRQI KKFKF TZQHZ GJUZN KKYYH TILLZ QFCDW ILARO TWWMV VUPFQ ZVYKR ZILSX JWFXU WUTDQ TIITC NTEHT WWMVO FEGQR GNVVM RGXFP JNKFK ITIWZ ZWTLV QPNJG WFIHH FUIFI YYHHF PNEJX RQIXR NEJXF IMVUW VVNUH SKVFE GBRVF SOJKR IVVHI LGVYN JLYFU XKRYY HIVSF IWJUW JEDSK WMVUJ YDISH JEDSZ QHIHF JHNEW MVQZD EJIRA VUYYH YYUJV ZJVNX CHFUL SXXUK RYYHN IGJGD WKXWV DSUWM RWIRW JTRNE FNUHI NLYYW MVDWI LAROT WWMVV UPFQZ VYKRZ ILSXJ WFXUZ QYYHZ BLHZU HLOFK HIUHX TUNGW NFQXF IYYHI VSFIW JUWJE DSKVY FRZID LVQYJ DYKKJ GRWKD ZKKTI LYZHX RQIKK JPZJI HFSOJ KRHFQ KZURK KFKDL IRZGP FKFMZ QLKKJ UHXTU NGWNF QMRGQ VIYKK JTRZE WWPWM VGFPD KKHWK KJJSD TONJW LIRZG DWILA VGFKN NEJXT UTJVT LUFXH SKVFE GFBHQ RJWFX UJLSV VXVAF EGPVQ YNHWV DXBHI KRWVS TIWTE WMVVU PFQZV YXUTL SXZQY YHNIQ JZJMS RZIKT FGXRQ ISRYY WJRPX JHSKP JRONJ WTWWM VWTLU NEJUR UYZHX IHHFQ HZONE JYYHR RJFZQ XKWMV SFIWD FIYNH SKBYY DYJHY FIKWU TDONE FTCQB VKFMH QFVYR QTKKJ IINMH FCRSX WMVZF POZTN NCBYY HFBHQ RJWFX UZQJJ VJOKF UEJVQ BRWHY LSXIT IWMVG JGDWK XWVIW FPYYH JRVYV QIRQI JRBVN SFZYY DYKKJ WXQCW BVQYP VJKRK WDQFQ LKKJK KFDHX ZQYNR LIRZG VTWWJ EZNKK JZJMK DWILA ZQLZQ XNDQV DSUVJ MHSRW HRQJN GTEWM VDHIR XKLHZ QYYHQ RVYKH QVJWR PBVLS KHWTH UKHIJ SJCOJ URZKW MVPJJ VFXHF KWFIJ JKUIW DSULW RQYYD YGDXK PDRLW DLSZV YIBHF QYRFY JZMFD YCDXK DLIHJ UWTSU NVIRV RSKKJ ZUHFQ HVUSJ UIWVY RQIJI TIUFU LTULW VFYZR SRQIW LSULS XLVLH XKLTE HIKKN JWMZQ PZQLZ WBRVF EHWIR WRQIK KFKWM VBRVD SKUFU LTULW VFYZR SWLSU LSXWM VQFML LRWNF QXPVY VPBVX XVEZK DUGDW VQYCB YYLXZ VXFPJ KKNEJ SVZKI RRKKJ SRKWL SJRSK KJKLE RUITR RDLYK HJKKJ PFFCO NKFMR LSYRR VDSUL YIHKV UXKRF EHBRH WFSQR QJUHY VFYZR SJBXK HRKKF KXXVV WVIQV FYZRS FIWRG NFZFM HXKRW RQLVI NEGFJ ZJCOF JLSUL HRWJS HFILS XIWFP FZUYY UJRWX KKJPK FMHGV HSVAU VUNDH SKLSX ZNKKY YLXWR WRZMZ OJRQI RUJER BSXNC GNEJT LWFJH WZHXF IRRVY JWTXL AVIWF QYCLS VZFIQ NEJTW DNIDY KDHBV YYHKZ UXKIJ NVYRW NFQXR UJSHN EJGLL QKLSE RWWRQ BONEF TCQFE GJJVJ OWTGU TMLIV DWZQL FIIVI JEFJR UTLQI CRSUR SRQIZ WQFRP JONBH TLUXG BHCLX KIWZH SUVFI HMLQY ZQLWR WZQKF URRWN FQFSR ZKWMZ VYVFM ERQFJ DZWNJ QTKFQ VDWZI YYHDB QTNZM RWNKL XSXYZ WNJFJ IWFZQ YYDYN HMRYJ KRXKR UKKJD INEGN EJTLW NRPFC VTERY JXWVZ MRWYY HRZVX ZQLGD WKBRV PGVUX RUJUR NEJNK FFEWG VMZJW RFUJJ SDZQL RVYYH NIFTM HWNLY YWMVW TLUNE JURUY ZHXRO QFZJU WMVPF JPZTK FTFJJ VFJWM VBBVU JCLPV ODKRL VWXFV TDHYY LSXHQ JHNJX UZDRY RUZQL KKFKW MVDYK DHYHI ZQYVU HVSYN LQCJN MHZJD HCXJN HFEDQ PVJUW MVHST UDGWJ UWJCH LIDRR QIWRZ EGYYD YZWZJ HXRFQ RVXZF FUILM AHZSM VUNKX XVVYY HXRPJ BHDNR WUITI WMVWW RQXGR XZWNF QXKDL VRKKK JTLUY HWRVN YDAVX XVGKF UYYLX MLLVQ JIHHZ SMVUF EGPER BZQLK KFKLY JKTLO ISHWV DXFQF SODJW WRLLY WKFUB RUIKR HIDHB WMVLW DHXJD LVEZK BTLZN COMRY JKRHY HHBWM VGJKD NCVKF UDFXW JHQWD XZKFM HYFJT YDWIB MRVFJ NJUPJ KRYID AVOYF FFZVY FUYFV JKXUR FTDPF EGUFV YRWYY HWUIY FZJIL STDXV ZJEHJ UWTRF YHXNT NQPLK NHHRQ HIDHB WMZVT EHFEG BFUPF XYNKF KLXXR NEJTE WMVQN YRUVZ JTDSD RZEWF TRZEW JIWTK KJJSD TONJW TGHWR WNFQG VITIH NKVZT FJVGX GHFIO diff --git a/2020/ciphertext.6b.txt b/2020/ciphertext.6b.txt new file mode 100644 index 0000000..5722228 --- /dev/null +++ b/2020/ciphertext.6b.txt @@ -0,0 +1 @@ +DADFD DXFGF FDFFX GADAD XFGGA DGDDG GFGGA GGAFA GGGAV GVFDD AAVAG DFFXG XGDFV GGDFD DGFAV GFADG GFFGF FVAGD FDFGA DAAFD VDVGG DDFDG FGVFA AFFXD VGGDD GFFGD GFGDF ADDVA VDVGA AVDVF GDAAA AVAFG XADAF DGDGD VAGGG DFAFF AFXGF AAFGD FGVAF FVDGF DGFGG DFGVG GFGFF FGGVF FFXDF FDFVG FGVFF DADDD GFFFV FADFA VGGDA AVDFF DFDAF DDAGG FAVGX FGGDG VDAFV DGDGG VDGGV FDDVV VADDD DDAGF GDXDA DDADD DFVDV FDFFF AGXFD GVDDG FFDDG AVGAD GFFDD AFDVD GGGFF AFVFG GDVGX DFGAF GDDFV AFFAF VDVDF GDGVF AGGGX DGDVF DGVAD GAGFG GFDFF AFDFA VDGDF DDFXF AFGDA VGDVG FGVFF FAFGF DFDGF GFDVD GAVDD GFGGG GGFGD FVAVG DDVFV DDGVF FGVDF AADFD GAFAF FAAVF VDVGG VGFFG FGFGV FVFDD DFAFV GGFFG AGFGX DFGFF XGAGF GXGGG DFFGV FDDDA FDVGG GFFDD AAVFV AXDFG VDFDD GDGDF AAAFD FAFFG GFVDV GGFVA DDFDG DVGFD GGAFV GVFFG GAAVG DGGFD GADGF DFFDF FDAFV DGDDF DAFGV GDFAG VDAAG DDFDD VFDAD DGFGD XFGDA AFGVD FFVAV AFAGG GFGDV GGGAG GFAGA AFGDG ADDDF FDAFF FGFFV AGGFD DFADG DDGVG FADAG DFFGG GFDFF FAGAD DGFGD GVFGF GDVGF FAAXF DDFGD AFGVD FGVDV AVGGA VADGA DVFVA DDGGD GGFXG VFAFD ADGXD FGFDG GGFGF FGGFF DGAAG DFVGV DVGVG VDFGV DVGVD GFAFD FGDGD ADAFF FDGVF XGGGG FFGFG VDVAD GVAFD VFGAX GAADG DDXDV GVGGG FFXGG FGAGF AFFFD FVFDF VADDG GGGGA AGVAF AVGVV VGXGG GFFVA AGFGV GGGFA DAAGV AAGDD FGADD DDDAD VDFGV FAFDA GGFFD DDDGG GVDDG DFFAV DFGVG FDFDG AFFVA DGGDF DDGXG DDFFD DAGFD VDGFV ADAGD FFVDG FFGDF GDFDV GFAAF GDFAF FFAFF DDDGF FGDVA VGDGF GDFDG VFFDD DFDFF VDVAV GGDAG GGFGF DDFDG GFADF FADAD ADFFA DDAVD VGGGA AGDGA VFDFV DDFAF VDFGD FGFVA GFXFG DGDFA DFGDV DVDGG GGFGV GGFVA DGGAD FXGGG FGVDF VVGDG FGGAG DFDAG VGDFV FDAVD AAXDA DFDGF VDGFF AFGVA VGGFV GFFXD DGAGA FVAAD AAVDF DGAFD AFFGV GFGXF XGDDG DDFDA VDVAD GVDAD DDVDD AFFFD DGVVF FXAFG AGFDF GDGVA DDVDF FGGAA DDAAD FDFGA GFGGG DFFVG DGDDD FGDFG GGFFX ADDAD FFGAF GGADF FAGDG FFDAD FGGAD FXDGD GAGFG DXADG FFVDD GVFVD GDFFF DVDVG FGVDD FFFVA GFGGG FFGAF VDVAA AFFDF FGVGX GDDAF FDFGF FGADF VAFGV AVAVF DAFFG GDGVD FGVGV GDFFD GFVDV GXGDD FDFDD FGFDG VAFFD GVFDG FDDGV GFFVA FDXGA GGDFG AAFFX GFAGD DDAAV DVAAA GFVDG DXGFD DDVDF FADVA XGFFA ADGGF VADGG GFAGG FFXDV FGGDD XGGGF FDDFF VFDGD AAFVG VDFGV AGFDG GFVVV DADAG GDFDV AAGGF XDFGV GDFGF VGDAF GGFXD ADDGV FGGAA XGVFF FFDFD ADDAA GAAFD GGFFX ADGXG GGVFD GVFGF VAVGG GXDAF DDDGG FGAVF GFFGX GGGFG GDFFA GGAFA VGAAF GVDXD GDXFD FDDGF VDFFD GFGDD GDVDF FXAFD FFVFG GXGGG GFDDF AXGGG DGVDG FXAGD FGFGF DDGVD GGGDG AXFDG DAFGF ADAXF GFGGV GADFF DDFGV GVFFA GDFDF FDAGF AAFGA AVVVA GVVGF DFAFF FGDGG FDGAF FAAGD DFDFD VFDDF FGFGD VGAGA GFFGF VGFAD AADDF DAFDD GGFAG DAFGV DDGVD FFGDG GFAGA GGDFV AFFGG FGVAA VVDAG VAFGF DGFVA AAGDD FFDGG VGVFD DFGGG XGVGV FVDGF VDGGG FADGG GFFDD AFAGG FGDDG DFGFG GDFDF AGGGF GAFGG FFGGG GFGFG DFGGD FFDAF AGDGD GGGVF VGAFF VFDDF AAGGF GDFFD DFDAD GVXGF GFVGG AGGFG DGGGG VGVDD GGFFF FDFFD FVAFF DGGFG DDDAF DGGGX DFADA XGGDA GDAGG GDFGG DFGGA VDDDA DVDFF DDGAF FFGFD GDFAD DDFGG FFXGF DFFVD GDFAF GAFFF DFDGF AVFFG GAGGF DGGVD DVVGV FXFVA FGAFX GGAFV GAGDV FVGFG DGAGV GADGF VGAFV FDFAV DFDGG FXGAA DFFFG DGGAD VAGDV FVFGF VAADG AVAFD DGVGA AGGAD GDVFG DADVF AVVAA VAGGF DGGGX DVFFG AAVDF DADDG GGFDX FDGFD VGVDD GFGDG GGFFF GGDAD VGFFX GGDDG GFGGA DXAGF DGDFV FFDVD VDFDG DADGG DGGAV DDFXD AAGGV FDGFG GFAAD DDGVD VGGGG FVAAA VAVGD GVDFF VAGDX GDFDA FDGAX DVFDF VAXVV GFADD DGVGF FFDFF DFFGG FGFAG FAGDF FFDAD AGVAG GGFGD DGVFA FGDDD AGGAG DGGXF DGFDG FVAFA DGDAG GGDDD AFVAF FDFGG GGDFG AGGFF XAAGG AFGVA FGVFA FVDVD FGGAD AGDVG GAVFG DGFFG FDGGA FXFDD XFDAA GGGFG VDDGD FGFFG FGVGA AFADV XFDDG GGFDF DFGDF DFAGG VFGDG GADDF FDGDG GFFDD FDGFF AGFFG DAVFG GFDFG FDDAD GFGVF AAVDD GVFVA GFFGV DVFVV VAVFG DFGFF XFDDD DGFVF DAVAD FAGGF XADAA DGGFG DGVDA DVDGD AGDFF GADGG XFGAD FGAGA FDDFG FGFFD FDVFV GAGDF DADGF GAGAA AGDGV FDGVG VVFFX DGDDF FFVGV DFGGG DDFDG DGDFG VFXVV DGVVG DFAFA FFFVF DAVDF FXAD diff --git a/2020/plaintext.6a.txt b/2020/plaintext.6a.txt new file mode 100644 index 0000000..e12c118 --- /dev/null +++ b/2020/plaintext.6a.txt @@ -0,0 +1,39 @@ +our london akela groups have been scouting for clues in areas with a large german population using +the cover of good turn day to visit a number of house sandflats known to be occupied by foreign +residents in most cases there was nothing to report which is not a real surprise as v ks group had +already vetted alot of them and found nothing to report the breakthrough came when one of the land +ladies mentioned that she was sad to see her previous resident leave so suddenly but glad that they +had be enable to recommend such a nice replacement for the flat i might have missed the importance +of this but we heard the same story at three different addresses in the east end of london all with +the same departure date and that coincided with the original arrival of the spy c list touring group +from norfolk one of the land ladies had somewhat fortuitously kept a record of the comings and +goings of her residents and was able to describe visitors to the departed tenant there had been an +increase in the number over the three weeks leading up to their departure and that date coincided +with the arrival of the spy c list touring group in the uk i circulated descriptions of the departed +tenants to our agents at the port authorities and they were able to confirm that a group matching +the description had left the country the day after the spy c list group arrived at kings cross our +agents and akela groups in essex and kent were asked to report on the spy c list groups in their +neighbourhoods and both teams sent me a list of the touring parties reconciling them against the +party of twenty that set off from lincoln we have lost another five along the way luckily the akela +group in essex had been watching for the departure from the east end and so we know that the full +twenty set off along the thames in two groups often with eight arriving in swale and seven at ca new +don the acrostic in the last telegram we intercepted spelled out the message at target rdf and iran +that past my air ministry contacts who at last agreed to brief me on their concerns rdf stands for +radio direction and finding i questioned this thinking it was an error and that they meant radio +direction finding the navigation system we use but apparently this is something new from the boffins +on the tizard committee they call it chain home and it refers to a new aeroplane detection system +that uses reflection of radiowaves to range find as well as indicate bearing from air threats they +have been experimenting with this for a while and are now building out a series of masts to give +frontline warning of air attacks the first few stations are being built in norfolk lincoln and essex +to provide a ring of defence around london and it looks like our spy c list friends are hunting for +information about this technology it is not clear if they know what it is but it is certain that we +have to stop them finding out i am also not sure what the missing party members are doing it cant be +just more spying as their cover with the touring parties allowed them as much access as they were +likely to get so something else is up i am hoping that the attached intercept will give usa clue we +analysed the encrypted telegram and found that it uses a classic adfg vx cipher it uses the same +keyword for the transposition stage of the cipher as i have used for this vi genere cipher and +knowing that it should be reasonably straightforward to crack their message but you will have to +check the details for yourself as i have to go harry has asked me to travel to caistor to setup a +command post at the rdf tower in case we need to act quickly if we can crack this one and workout +what is going on then i hope we can mount a counter to the spy c list operation before it succeeds +pearl \ No newline at end of file diff --git a/2020/plaintext.6b.txt b/2020/plaintext.6b.txt new file mode 100644 index 0000000..9a7f2f5 --- /dev/null +++ b/2020/plaintext.6b.txt @@ -0,0 +1,20 @@ +dear uncle wilhelm the tower at ca new don is as interesting as you had suggested it would be and i +can see how it would lift the spirits of our english hosts making them feel safe and secure in their +fortress islands top nevertheless nothing on the earth is forever and i think they may have a +misplaced faith in this and the heavenly powers may not be strong enough to protect them from the on +coming storms top the local orts gruppe shared with me your latest gift the beautiful clock device +and we have spent much time admiring its top its simplicity is admirable and once we have learned to +use it properly it will provide us all with a very high level of security stop safety must be our +primary concern no was a lack of concentration at this point could bring disasters top ralf has been +given the accompanying key by the orts gruppe in kent and once we are reunited i will use this to +secure our future communications stop establishing a safe plan for our journey home is essential in +order to avoid unpleasant surprises stop quarrels with our host would be difficult to resolve and i +would prefer it if we could slip away unremarked stop use of the local fishing boats might be +possible but if anything were to alarm the locals that might well prevent our departure and the +clock could fall into the wrong hands stop if you have a suggestion about how best to arrange our +travel then please let us know and we will make the required arrangements stop ralf s party will +return to london this week and will then travel to meet with us for the final stage of our adventure +when we will all re group before returning home stop even if you do not wish us to proceed with our +original plan then we are able to return with a whole treasure of drawings photographs and +descriptions of these important landmarks for you and your friends to study stop details of your +wishes should be sent in the usual way using your remarkable clock devices top karl \ No newline at end of file -- 2.34.1 From 3a96c110b057a527f91b4a166c5c5bc91b67fd49 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 16 Dec 2020 18:19:44 +0000 Subject: [PATCH 07/16] Done challenge 7 --- 2020/2020-challenge7.ipynb | 1037 ++++++++++++++++++++++++++++++++++++ 2020/2020-challenge7.md | 285 ++++++++++ 2020/ciphertext.7a.txt | 1 + 2020/ciphertext.7b.txt | 1 + 2020/plaintext.7a.txt | 30 ++ 2020/plaintext.7b.txt | 75 +++ 6 files changed, 1429 insertions(+) create mode 100644 2020/2020-challenge7.ipynb create mode 100644 2020/2020-challenge7.md create mode 100644 2020/ciphertext.7a.txt create mode 100644 2020/ciphertext.7b.txt create mode 100644 2020/plaintext.7a.txt create mode 100644 2020/plaintext.7b.txt diff --git a/2020/2020-challenge7.ipynb b/2020/2020-challenge7.ipynb new file mode 100644 index 0000000..f6bc948 --- /dev/null +++ b/2020/2020-challenge7.ipynb @@ -0,0 +1,1037 @@ +{ + "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 +} diff --git a/2020/2020-challenge7.md b/2020/2020-challenge7.md new file mode 100644 index 0000000..68c2660 --- /dev/null +++ b/2020/2020-challenge7.md @@ -0,0 +1,285 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.support.text_prettify import * +from szyfrow.polybius import * +from szyfrow.caesar import * +import collections +from itertools import * +``` + +```python Collapsed="false" +challenge_number = 7 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +sca = sanitise(ca) +rsca = cat(reversed(sca)) +cb = open(ciphertext_b_filename).read() +scb = cat(c for c in cb if c in (string.ascii_letters + '#+')) +``` + +```python Collapsed="false" +key_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams) +print(key_a, '\n') +pa = vigenere_decipher(sca, key_a) +print(pa) +``` + +```python Collapsed="false" +pa = prettify(vigenere_decipher(sca, key_a)) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +crib = sanitise("tential stop the tripwire option is also deprecated since it is more likely that the expl") +crib +``` + +```python Collapsed="false" +cat(sorted(set(scb))) +``` + +```python Collapsed="false" +p_alpha = string.ascii_lowercase +c_alpha = string.ascii_uppercase + '#+' +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +``` + +```python Collapsed="false" +def decipher_letter(cipher_letter, stream): + stream = dropwhile(lambda p: p[1] != cipher_letter, stream) + stream, temp_stream = tee(stream, 2) + (plain_letter, c) = list(islice(temp_stream, 1))[0] + return (plain_letter, islice(stream, 1, None)) +``` + +```python Collapsed="false" +def encipher_letter(plain_letter, stream): + stream = dropwhile(lambda p: p[0] != plain_letter, stream) + stream, temp_stream = tee(stream, 2) + (p, cipher_letter) = list(islice(temp_stream, 1))[0] + return (cipher_letter, islice(stream, 1, None)) +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +p1, s1 = decipher_letter('B', cipherstream) +p2, s2 = decipher_letter('D', s1) +p3, s3 = decipher_letter('Z', s2) +p4, s4 = decipher_letter('+', s3) +p5, s5 = decipher_letter('B', s4) +p6, s6 = decipher_letter('D', s5) +p7, s7 = decipher_letter('D', s6) + +p1, p2, p3, p4, p5, p6, p7 +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +p1, s1 = decipher_letter('B', cipherstream) +p2, s2 = decipher_letter('B', s1) + +p1, p2 +``` + +```python Collapsed="false" +def decipher_message(ciphertext, stream): + plaintext = '' + for l in ciphertext: + p, stream = decipher_letter(l, stream) + plaintext += p + return plaintext, stream +``` + +```python Collapsed="false" +def encipher_message(plaintext, stream): + ciphertext = '' + for l in plaintext: + c, stream = encipher_letter(l, stream) + ciphertext += c + return ciphertext, stream +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +pb, s = decipher_message(scb[:20], cipherstream) +pb +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +c_gen, s = encipher_message(crib, cipherstream) +c_gen +``` + +```python Collapsed="false" +co = [(c_alpha.find(l), l) for i, l in enumerate(c_gen)] +co +``` + +```python Collapsed="false" +scb[:20] +``` + +```python Collapsed="false" +def offsets(ciphertext): + mappings = {} + letters_seen = 0 + offsets = [] + for l in ciphertext: + if l not in mappings: + mappings[l] = letters_seen + letters_seen += 1 + offsets.append(mappings[l]) + return offsets +``` + +```python Collapsed="false" +crib_offsets = offsets(c_gen) +len(crib_offsets) +``` + +```python Collapsed="false" +def plausible_samples(generated_text): + plausible_samples = {} + for i in range(len(scb)): + sample = scb[i:(i + len(crib))] + if len(sample) == len(crib): + ofs = offsets(sample) + if ofs == crib_offsets: + plausible_samples[i] = sample + return plausible_samples +``` + +```python Collapsed="false" +c_gen +``` + +```python Collapsed="false" +def plausible_mapping(crib_output): + mapping = {} + for n, l in crib_output: + if n in mapping: + if mapping[n] != l: + return {} + else: + mapping[n] = l + return mapping +``` + +```python Collapsed="false" + +``` + +```python Collapsed="false" +plausible_mapping(co[:3]) +``` + +```python Collapsed="false" +solutions = {} +for i in range(26): + cipherstream = zip(islice(cycle(p_alpha), i, None), + cycle(c_alpha)) + c_gen, s = encipher_message(crib, cipherstream) + solutions[i] = plausible_samples(c_gen) +solutions +``` + +```python Collapsed="false" +1026 % 26 +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(c_alpha)) +c_gen0, s = encipher_message(crib, cipherstream) +c_gen0 +``` + +```python Collapsed="false" +c_alpha +``` + +```python Collapsed="false" +soln = solutions[0][1026] +alpha_pos = [c_alpha.find(c) for c in c_gen0] +c_alpha_mapped = {} + +for p, c in zip(alpha_pos, soln): + c_alpha_mapped[p] = c +c_alpha_mapped +``` + +```python Collapsed="false" +discovered_c_alpha = cat(c_alpha_mapped[i] if i in c_alpha_mapped else ' ' for i in range(28)) +discovered_c_alpha +``` + +```python Collapsed="false" +len(c_alpha_mapped) +``` + +```python Collapsed="false" +rotated_c_alpha = discovered_c_alpha[12:] + discovered_c_alpha[:12] +rotated_c_alpha +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(discovered_c_alpha)) +c_gen, s = decipher_message(scb, cipherstream) +c_gen +``` + +```python Collapsed="false" +caesar_break(c_gen) +``` + +```python Collapsed="false" +caesar_decipher(c_gen, 12) +``` + +```python Collapsed="false" +cipherstream = zip(cycle(p_alpha), cycle(rotated_c_alpha)) +p_gen, s = decipher_message(scb, cipherstream) +p_gen +``` + +```python Collapsed="false" +pb = prettify(p_gen) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2020/ciphertext.7a.txt b/2020/ciphertext.7a.txt new file mode 100644 index 0000000..e529202 --- /dev/null +++ b/2020/ciphertext.7a.txt @@ -0,0 +1 @@ +MYMAG ZLGAV LDBIF QXEBW NYTRM VZCRV EIWSG HNXCC LKMAZ CSSAR DEZGY EZVLT BVWEG KIBHM ZRMYM CBSXY GZKAG OZREZ VEFUF XHWBI EVTXS LNEEU FVVIG PGGYE EPATF NLZXV FAZOY IWKPE POALX IBEKZ LRWKP EPGDI YZTEF GYHUV TIRBP XARBI GSLCU VZEYG EIWKW TUKHL XRBSG UYIVC WCXIT TAVZD RVFXR YMAQU QXAVL IIODM HEPAF CCMMK MNNHZ WLXCI QKESM YMSRI TTAVZ MNISM GVAAA JHIAR DENJO IWKPA GZZXA VKAFK QMEVA HNXCC LKMAZ GWWHI MCBBP VXUIS PXLTH WJUET ETTGM RSXZQ MYMAO CPLKY YWNYE IPYQC UILVK ZMSGN PJHCT OJOYK FVASN MPAAZ KHJKE LBESM VMSXU VXAEZ ZJMYM PYGTR MVFTG KYXBR TSGUA XAVBR VVHMK VWPGO ZRBJI LFUOI IIMCN ZPHLZ VCROE MLDWR RRTOX CGTUG EXAVM XCREL XEIVL XPTHI BEQZS EMRLU GISJB JPIAM GILJM LJGDM FGWUA JPHUP BHRTL DBRCT UUCMM ZMSVT MVXDM RUGGI GKPEP XPAPV ZEQKE EBEMD NTORX XWTVG EMHEA AEKFR WVZWN EMIMN MEAZS IWLBC UGYHZ VZMNT LYMYW RVZTI LKWTE EESZV BTUKQ MLYMR ZKYEG UBHRO CZXJA EYHLG DSCTV TELXD MAAZT QXIVP NZCSE JEIYR HEMTP OHZQS KKPEO ULXBE KAFKT XBJQN IUWZX UQNGN PSIVZ AGOZR MYMAV XXMGZ ATEES EOVJE RTMVB VNEQU YSNIN IAJTR ZJAOS GCEGU PAIKP QIYIS VYPHM YMIZV ZVMRV CRUQT KFBEP ZTRZK PEEJQ WRJBE ZCSMV YQAZZ ZPWKP ELILP ETPAV TSSFV DKVYD CFGIT UKEMV SCTGN PXAIM EBLFW TIMSG OWPPF ZRVKO EUFCT GNPRX NIGRT EWXDJ EQJPH BETOA JZRTE LWRGC IGFBS HXPLH NUUPN ZJTKP RRGEX AVGPB YPMMZ ACEAN MTCBH NZHIU IMAXZ SITKB APNPH VZXHR XEIQK ISSGD XTJXO FYTFE VAOJK NEGGC TRLQI VKQVR IZYGK MRZKL WNIMS VTAPT TMIGO DXXDX TVTRX HRZRR YEEEC BWRTE CMYZE RYACV CQSGY LRWRA KGNPQ WZZEP ZWCUL BWVZS SNKZE IKLPB EOTUK PBMVV TBLZY KJCRI KTPER VCRGY HVFLE OXPED ZVGNH TPBKG IGCTP EEWTO KASLJ QBYKE SIIWV RZSEM KPELN LZXSZ OXKYX AVTAJ YZAXN WUYJY SMSMA ORPXH UMTNO YSKUM PBXEX AVUIG CZYEU CSHGW PRSMB RZEIK KWWNZ NLTEL WNOEF NKBHR GTVFZ VIFZC CYVML FZSEM KPEEO DOMFW UEGTV WVNEA IPMLK WOTXP EMJWW RTPIW KWAPZ QELKQ FJKVR XNMXN IEPRN PEAGY HPYMR RZSIR ZVTRT OIWKW AGZLG DTPAV TSSFV BHRTH IFZOH GHPEU CMTBO YGKVI SRYPG NIQTL ZZTKV DEAZT XULBA TGTRP VZIFQ CIOVI LVTRS NIKOH TEIKZ VTRRW MZVVC RILTT SQLVZ TILYI REEDY ZXMSG KOXAR BWRIZ YEUWB FIFVX FCRGX LGDJJ YSGVM GXIVV YTXUP LITTT XTIQE FZZXA VBAEM PXLZB EFGDE VFDEE YESKP NOEOY GKVIS RJDIV LZIGE MYMNM CNTEQ TZVTN OYXAV QNPXP ELVNO ERZRZ NQTUU FXKRQ SVTRW NJXIP OZRLF QTVYN VNTQA YZZHX KMRZO YIMYM IEVWE GJEHN ZPZXI BHRGM AXYZA EKTRM VVDVT RXAVG WBTEA TEBTU KTVTX MNGYE SYRTL VTESH LZHNT OWXJX EPOLP EPIFG KCEWV UOYOE MHEAI AIPXA RBWBA WHZZD EHYEL XVFCH YPAXE MEQZZ EKIMS GZSIF ZBWBA WHUVO OBJES DEWWJ NLXMY MYUGG IBEUI AJQSK KPEVX PBYZT TEGEM HEBHV TRWTI MVRXJ JBEML LHLPT EKEQO QAXRK TGUZW HFVWR MTZXR EALUF VVICC VGWEW MINGG RIBEB HROYX XIKEC ZHEKZ NWRGN XMFWL NZPSN IMNRS TILTW UYJDI KZWUF RJHTD IGRUF VTZZD RLPRV VKACG MMEZB YVZTW VCMAE ZSEMK PIAMD EKVKO ZOYKM FIHRG OEGUQ TVYNV NTQAY ZSEMN MCEGN OMYMC YUNOV ZXHRX LWLFW NNYAS LJQBY KELXW ITRUQ XAVKO HTEVR CQEFO YCHLZ HNTOW IVIRY diff --git a/2020/ciphertext.7b.txt b/2020/ciphertext.7b.txt new file mode 100644 index 0000000..d7f4ef5 --- /dev/null +++ b/2020/ciphertext.7b.txt @@ -0,0 +1 @@ +VXLKV ZXZSZ XODRQ YFQEM OLMRT OFATI MXTAW AYANK RBPCE SXCUP OB#RT BXSEK RDSJ+ WYTG+ JDIKP NRJTP #AFYX BAZRO VAWUH RUYIZ RCOSX CBNW# VNIQS XJPEU YKCJO PSMCE QXBIC #HYIZ T+RBJ +MXPM TDSKR UNQ#U BIHZX VBZET EGSZE MWXQD UFQXS EKRZD ENOND SZEQU IXNGL +REON AHUOQ +ULFN ELDQB HKZGS QPSMC NRQ#O LMEOP FXLBU LSY#I C+IO# SGRDL VIMFU MPOTL UPADT SCAUW MSJGX VHWAH CIWBN KAPIZ EMWPX DBLCP +H#KN RJTPZ ELNZA WZRKS HKNDS LHJNK VFQHM O#ATL SPISE JFSTD SPQYQ FQEGZ HLNDX Z+VKB +JKSD FWZAT UXH#K M#XNH XHZTL UKBTE BWDPU #APXB POTGZ CHODT SQGNB J#IVU VMZXV +PFAN TRILP EMHYO ERKAR T+YDJ WOIHU IZFTX LWUB+ ZGSLN QYT+R +THCH TPBXZ JVLDT EIWIH KNDA# IQYCL WJVMO PWRFT GKXCQ EHCNH MBEQ+ MPUCO DSOLD JWKSH KNDA# ILUXV TOCHC KUVQR FBXJT AZAKU FHIYT BJNMC HSOXL XYJKM ZJWMD UGNWP BWYRX ISFUL YNTBZ WZKTY GRY+R QVH#S W#QBF YXW+W ZSIAS TI+VR GPXQM XEVUK QXJGN IXBGH EWYIY WYSXB L+JWG ZCHOQ HZWLX QBHVJ ZSDKW RGFTU GXTGW #MEOT NTEJA QH#JE AJWRQ GVKYX N#LOZ WUZTW PHWXB MPT+D LVZXJ HIONA TEUQO SRDLW YR+CP VQENQ MENKX Z+UBX KSMTO JWMI+ SUJND JMXI# HPMEO WUXYJ ZXJPM IKRZI QCXBO #HYAI FDUVQ KUBNH YVHWP RBTCJ +MPOR QVNEG IVXYJ KCRUI ZQDIH PJVLU IVGJB VXYWS QNH#V YQCJP VMGOQ FMNCK XFLDT SGRAS RHWC# FOFAV LNBIF HNELJ BNHYE MIAPS MCJPY IWQJH VCWDU RFBRT BNBJA UKW+A SVCND JM+BP M#PLJ HLNVZ LUPAX PR+HN LR+DI VHGPA SPBNU HFOIH PZTYX NS+QA #VD+B PHGLE QROFX QRNYD FSFJO IXAI+ QEIEM EOTXL NJBZW SGSFA XUOQF P+MQP HULTE GHPZT HBJKT KVNHM BEQEI EKVUS EFLPJ HOK#T DIARY FQPBO CPOWS ROENQ IJ+WC JZTRW OAX+Y FQPBO CPOW# ANPIX ALTVW KSHXQ MCENG MEOHU QPXBE ROCKC R+VQS PIVNQ LBAIN WILDT #DRHK OXWDR XIWCP CUCPC UFYJB WHQXY PER+G A#INQ PBOCP OWHZT XTPZM WYWSV JA#YF QSH#X EUOCJ FULRO EILZI JZXOD HOAX+ WMT+Z QG+SR UGPQH RNLDT CRNIS RYTDL VGWXH #SCKU NENUK TJKPA WIXJS V#KME N#TQW IXBJ+ WKJWO XMDLG VPWKC KUENU IPGJR WMKNP RDHWD LPBOC POW#J QTEGB +EJSH WAYTQ YCLWA HVLSO RSUZX NJ+BT ESGRA SRXMQ X+SCT PMULN YDHFO VKSYC JDRQN FYFW+ DHXVH WLYWY QLXYJ ZXJEQ UI+LX MQSI# XMHCT OB#TY H#NIX JHY#H #NYI# V+IVG ZCHOW #QBTI LDTGN EVZDS JLHIJ MINR+ UIFLJ M#OWR FYX+Z SOJPU KCQYD LVTZW OQTNC UQDLD TVJWU +LQFP GQPXV BZDHR FVBLB +JPVY DXDYW MISVW APCJS CILJH FYLDT ZGXK# SZDMX UWTC+ BPECU IOWAQ WKGCQ SNDSA WOHMY WMIRC +BPMR CNZDU RFBRT BNHYO CKCRY TOQGX KXMCK PWRNQ RXKJT IXD+N ITRUW DQPFP U#NBN UTEGZ TSODH KYHIY WTCBO CAH#C IXNXV HEYXP MHKND A#IZQ #HUXV CKNAT BNTZG KSWQM UTRCP MPUSO W#ANK UOTYX MUNLY FP+TW BYPUL RSOKA +WZSI YDWYQ ESFJV COPB# HVNLP CTSRP SCASG YFQ+B IMKYB NW#HZ XBXSV XYJRN GLUXI SFULY ZIWRV +HPZS YJPEU YJFSY WNMST JVDZU FVTAN O#EMW AXHI+ RCHE+ OFOHR A#ANG XHPYX ETU+A XRQ+W SMPAH CNPZU +OPJN TVOCK CRVI+ RHFOF ANQLE O+UTE SXKWP JADPD LV#GZ QJSKI SE+MX SZESN YKWL# XHIYQ GIEME OFUHR TESNI SECAK SHW+I RYFQC #SMQJ QSWAQ WKGCT ZWNSD J+A#S U+QIH MKJMR FTOQS RFKXS BJXEK NVXOD JEVGP CIPBU FYXHP QBTGM SRASA IDPGQ PMSAI F#ANV ZXZSZ XODLH YDLVK PRWBP #HQEH IVZGR YDRGU WJU#+ H#PWT SZTXF TKAQN ZJPCU AKVNY RVNJ# TJMRF APFW# HZQL+ NBLPE ZTBJY EUPYR GIJHB GSRAV SFSBF OENB+ JOASA IASXM TCPVG ZHXFU TKUQT IGRKJ O#VGM V#QFP SCILW UXVKM IJUVH KGRVY QCJES XAMCK XFLDU QRSVW YRWKN FHV+N DJM+B PCHVS NFHRH LDSZE MWBDW DRXBV WGH#B VNELH SREAQ AXDIP VLH#O HORQV Q+JBN HYQTK CA#IL ULGVM KQGVY PBOFY XRHED #LWAP RIMDL VIMKN VLHUV BOBXS ACOVA HMHUY VNR+I TAWCL SCIL# ANVKY RQRQA XIMNU GVGZU CTONT ELZIY RPVYD MVMD+ BPRVS CIDLT WB+JU TDKNQ HV+DL VUHUL BI#JH ZTEGB +NVAK UMRQD OR#FA PMEOL FQ#VT SZXOD KCQYI MNUGV TGZUC #AHRS OKA+W AYW+O AX+YF QMFOF LPBO+ OFUQN HYMIO LRYI+ SI#PA CKXFA JKISE RMXKP EQT+G BRYFQ JM+IW OLFVH K#YQL FYXSZ ERWXI OSYQT RCPIK PJXVC KXZNW HPHYP EUYKC RPNUI QPJMC KXFJV RQKDT KJ+AX YHTDQ HWTGW UC#XN PFYXT CUVDF OAIVW NDJGH #KONB US+VK QNZJP UYW+S GRPVJ GMQAR #NZIZ ULDTZ GRNWO FXDTU GZSMG ZORQH ZUJUZ EWX#H OAX+Y FQXNC #R#C# UTPIQ +HQD# HWAH+ CTJRS XMFIW #RTLB +JERA SRYNR CHE+O FOHRA #ANJB ZWSNP UKCQY PTUVH #RWLP #QLUR JZMOH BJUSD KOQGB JPWVO EQFUB NWRNI QOJYE U#A#I NQPXC VCXW# QBDVA YHIXY JKCRX +I+P+ ISFME OWX+Q FTUXB TWUPH CNHMB +QCEV YGRJW #QUXB +JKQT KCA#I NUMCW CMCOX VRTLB +JGON WNFYF Q#JPO LWCMS HFSBZ XJ+NJ MXYPU PA#TV CZJ#T GW#UJ DIXFS OKAQB SACFQ AX+WV WOSXO LBJLX FLDZT JMOKE IHWKR G#PCN HMUJH UIZ+W UB+WM R+GBV QS+QC EVYGR JWQDV KTZGX KESW+ NGYFQ +BIMG PHLCK JANEL DTVJR ARCO# XOCZL H+PAV OD+VW KQBHK ROVQT +G+RI Z+SVU VLNUN URILP SCHWE WIDQB MITBP OC#XP BOJVR JAYHQ EKNTI Q+IGJ MRFCK ULNJZ TBJKI NI+VF SUFWM IDVTJ HBSPB #AHRE XUX+# OVACN XBPCE NPCHU IVPXK MVZJR +J+WX MQHZG PCMEO ILULT LUPAV ZOATK XSRFD BVPLB OWRIX JQKSK CQYTE +HI#Q FPRBU HZT+F JKJT+ HIJZS AVWXH UYBTQ DVMUM EVLHJ UXJKB HKEJZ SDKOH UGRPI SFVLN YCXZX NV+B+ JOASA IASXM NDJMI EMEVS QHRIU PAVQS WSWLU YFQCI GNQLB DOIZK SJHSZ ESANF BPOTA PEWCH CKUST BMXNU KQSAC IUPYA #DIQP SRCUA HSPBE QEGPA IXD+Y GQPVQ +UVRH FMWBO PBNQV BGUKS ZXYJU PYSGY IC#IV HLUOU YDVBL QCT+N ACJYS NQGSG INX+S CNPZU MO+UN EWJBJ +NATR DFGSU YIMRC QHU#O ASEKS +PZQN TYPEM IAYFQ JMVMO MVRBN QWKGD SBJFS W+IXJ G+JWQ JHYXZ +JQSE JPV+K NFYFT NQV#J XQCVO WJUAT FXMNV SOZSA WLVMQ UGW#J HUFUF TUXKJ RNYOQ DU+MP ZH+BP UO#IZ JPMPQ VPEUY VWCQA IEQV# XFUYB O#QOE +UABE WESKC JOWDT UMKXM VCPWP ZQSEL DSZEM WGRVB I+RXT WIOIZ NWUB+ ZGSTD JASVC LH#KM EN#FY XWSEJ ERXJ+ WYFQ# VOKWL SPOZT KIUKB TYDTS RGQIN DJM+B PZHNY IYFYX JHQYE SAJ+A RMCRQ PFOHD FXZXY RQTVZ GSRNL RGVJQ MVOCB NBDSN WUAY# JURXJ +WIYQ GOVZE WCMCI DHRXV FXZ+J KTFW+ ASYPN DJMUB IFPME ODUXK JZSZX ODU#P QDVMZ +BPAH SCFSN FOVKP GZGSA F#OVU YIJPG VGZHU OB#LT KNPSY VOCKC JOX+I +P+IS FMEOZ IZ+VK BEXRD SGRHW C#KVR PNCIU ZRWBU KXWMD OQU#C JW#NO VCR+O I#GPL BPONE TXBHX YCUAX NHDZP +GLHF ZXZRI LPERN ZGOVK A#IW+ VJWRT LPNTL UPAVI JQT+G BROMP E#VGW IRBHF VBMZN ZXPMY GQGUG #HPI# VPOFV TEANB JPRKP +GIVQ XTOCN #PWPR FVZUG ZGSAW JOQGP QFPCP VGZUC QUVGN BIPGR OVASY XOGVJ NFKYH UXBFW BXMWY #TDKW YDTIH GPACK UZJVR Q+HQD #ILQG BTC+B PJUYR CNHUQ BNBJB NHYRD FYRYO +C+SG QCFP# GWDXZ QBHKA KUKWI YWMI+ BPQAH LCP#T QDLDT ZKTI+ WMIWN JZEU# HFUTL XZYHY JKWYT WJGJG +H#HP MRJWR FVZWX JWYCT DFNA# I+OPO TGW#C RMIPN LDTIW KFPAP RHTU# EZI#K QMIR# ODHD+ UJQDE KNRGU O+Q+B OMXHU XZSOE UBRNZ GOVKI +RYHT +WJZO VHLCW HZFYX JWATK IGOAX +YFQS ITJVR BJHEK MXZTX WK#SF QUVNU VPVTJ RBEJO +RTSR DSHQD VMDQV GZHV# SNAUF JILPE BHXYW AWQUI DLVTP OJFHF JV+B+ JDODF NGY+R H#VLH VCPWN LWXOJ AB+WE KCRQC TVWPI CZH#Y OCHXN JKMZG SIOUT VRHGP AUIDU GVPUV KSIRC NHDCT CESFU POB#R ILPEB +J#SE JIRQP C#SGA PUBZI JU+LP GWD+J +AXIM QSOBO FASNB DFYOI HIVZ# JEMWA X+G+R JGIGU JMRFP YJVRJ ZTSRY KPYRB DLV#G ZHUID UGVPU SODKI J+SGR DLVRP NSCI# ANTUE +JKNP OABRB INDGS UPASC ILHFO IEZNA ZJ#U+ O+IVR HFCO# H#CKX FIDPI YCJRH JGVLS UNJF+ PYJ#H FXJKS YVOFS TDSRU YIZRZ #POHS WXLJI LPER+ JYVHJ +WYFQ SHPBI #PMUQ ONTBX BHJKR HWA#I VRMBP CUBFK X+UFT DLXZI VJRDF AXBIC Q+VGZ HQOTY LVHB+ JWUFW BXTW+ SPFJT #O#AT LKPHY SPORU YFQXH WPIHX #JHXN ILPEB +NVIX D+IGO XDIZN PVGZH #PWPQ DLDTU JISFI S+FQG ZOLBP BOHZF VXKTO RGRDF OUYTG RZHUF CJFUT ZETWK PTNXS GIMD+ BPFTS OIZNV +B+JP MIDRB VLHMV HSCID URFBP WZGSF WKSQI G+QBV MOALN YJFTH ZUOLB HTSKC RDHWD L+BPO ENFON LPNAS KSIOR YFQEV TGCTO CPCUB VWXZS ACURX WJA#V +ZQG+ SMPOR BW#LW XLQBH KJZSA QNGIW MDLVW S+PRH LCTPZ EGNZB JWNAT CUAQN HDUOQ VQXTO FAXIS LXVRZ SXJRD FIXJS IGRHL C#QFY X+SZG SAGQG BOR#F AP#CU VSODY QLNFX ZQBHK ROVRA WQGWM NMIMO MVRB# QWIJA YVZOA QTHCJ +WPTU #NPRQ FMEOA PBXEB YJQTH MEMWN DRDVD RJ#TG W#NRJ FWSZX KXRNY GS+N diff --git a/2020/plaintext.7a.txt b/2020/plaintext.7a.txt new file mode 100644 index 0000000..95c5849 --- /dev/null +++ b/2020/plaintext.7a.txt @@ -0,0 +1,30 @@ +the attached document was intercepted by harry steam who have managed to plant a bug on the +communication lines out of tirpitz ufer our crypt analysts have examined the ciphertext and the case +files and believe that it maybe related to the wheatstone clock cipher deputy head of the division +has written a boss guide to these cipher machines and we have added that to the case files harry +steam also recovered a scrap of burnt paper from the abwehr hq waste which carries the following +message which we think might be part of the plaintext tential stop the tripwire option is also +deprecated since it is more likely that the expl the navy reported that a dutch fishing vessel was +impounded by the nazi authorities in bremerhaven the crew were detained and negotiations are +underway between the dutch and german authorities to try to get the fishermen and their vessel back +but in the meantime rn patrols will watch out for the boat in case it is involved in the operation +the air ministry have been briefed on our findings so far and have emphasised the importance of +protecting the rdf system which i am told they call chain home vk is sympathetic but the three of us +are still worried about the new agents embedded in london and we are not sure how much of a threat +they pose it is crucial that we break the attached ciphertext as fast as possible so we can put +effective countermeasures in place it is tempting to arrest all twenty three spy c lists and ask +them directly but without revealing the extent of our surveillance and code breaking ability it will +not be possible to prove that they have broken the law so we would not be able to detain or deport +them it would usually be better to watch and wait but the air ministry feels that the risk to our +air defence is too great so we need to act fast if we knew exactly when and where they intended to +attack chain home then we might be able to increase security to prevent it but again we risk +revealing our counterintelligence capabilities harry suggested that we could obscure our tracks by +faking a visit by dignitaries to the target sites as a coverstory for increased security but we cant +maintain the increase for long without raising suspicion so it is crucial to determine their plans +whatever the abwehr are intending they wont want their agents to fall into our hands especially +after a demolition since that would give us the excuse we need to arrest them it would be good to +know what they have in mind for their exfiltration things are very finely balanced if we act too +soon we giveaway our crucial advantage in the intercept war if we act too late our enemies could +seriously damage our air defence capability it is clear that things are coming to ahead and it is +crucial that we crack the clock cipher as soon as possible the fate of the country lies in your +hands pearl \ No newline at end of file diff --git a/2020/plaintext.7b.txt b/2020/plaintext.7b.txt new file mode 100644 index 0000000..9feae4e --- /dev/null +++ b/2020/plaintext.7b.txt @@ -0,0 +1,75 @@ +karl operation cathedral tower has been approved and our agents are arranging to provide you with +the tnt you requested in your last messages top this will be shipped on a dutch fishing vessel which +will land at the marshes of fold leigh at two am on friday december tenth stop they will signal +their arrival by flashing their navigation lights in morsecode to spell out the word flat and you +will reply tyres top if you believe that you are being watched then abandon the rendezvous and try +again at intervals of two days three days five days and seven days stop do not attempt to make +contact with the boat or it screw in any other ways top the explosive is stable but should be +treated with care stop the fuses are the most recent product of our research and technology division +and carry triple triggers stop they have a timer circuit which maybe set for any period from three +minutes to seventeen hours stop they can also be triggered by a tripwire assembly or the fuse +mechanism can be replaced with a hand grenade mechanisms top since these charges have been shaped +for demolition use we do not recommend using these devices in combat since you have no certainty +that the charge will land in an orientation that will maximise its destructive potential stop the +tripwire option is also deprecated since it is more likely that the explosives will be discovered if +they are attached to such a trigger and moreover it would be difficult to coordinate the charges +using such a devices top the charges themselves are small but the geometry of the package will focus +the blast so it is imperative that you install these charges in accordance with the manufacturers +instructions stop in order to maximise the damage to the towers the engineers recommend that you set +charges on three of the legs of each tower with charges two and three set to explode in sequence +after charge one stop set an additional delay of thirty seconds for charge two and one minute twenty +five seconds for charge three stop as the first leg buckles it will stress the frame so that the +shockwave of the second charge will distort the supporting members stop with the third explosion the +frame should buckle resulting in the total destruction of the towers but this sequence will make +site clearance and reconstruction harder to accomplish stop the delay with charge three also +increases the likelihood that soldiers will have arrived on site in time to be caught in the third +blast increasing confusion and loss of morales top if it is possible to climb the tower in advance +of the demolition to get more detailed images of the aerial and amplifier circuitry then this should +be attempted however if there is any guard presence then no risks should be taken in this regards +top we must leave it to you to determine the most effective targets for the operation but the +demolition must happen simultaneously at all sites for two reasons stop first in order to prevent +our enemy from disrupting the operation once they realise what is happenings top second we must +leave no doubt that this was an act of wars top there is a risk that the british government may try +to reach an accommodation with the fuhrer dividing the world between their dying empire and ours +just as it is born stop the only way to ensure that we can truly supplant them is to draw them into +a war they can not win and this project will be the provocation that ensures that this will happens +top the planning division has determined that january first will be the optimal night for the attack +as it coincides with a new moon stop they suggest that you split into two teams to attack the +edmunds t caistor and ca new don sites opening a corridor along the thames for our forthcoming air +raids stop the support teams should setup lookout posts at the targets in advance of the attack so +that you can monitor guard movements and make a final assessment of the security stop following the +operation the sabotage teams should rendezvous together with the support teams at the home of the +local orts gruppe chief in south maldon stop au boat will standby to pick you all up at three forty +seven january second with a fallback rendezvous of one thirteen on the thirteenth when the search +should have died down stop you will need to gain access to a boat capable of carrying you all out to +meet its top there are very many fishing vessels in this neighbourhood and we recommend stealing one +after the operations top it might feel less secure that obtaining one in advance however we must do +everything we can to prevent suspicion in advance of the operations top if this mission succeeds +then it will be only a matter of days before the war begins and your three comrades in london will +playa crucial role in coordinating our intelligence efforts behind enemy lines stop we have been +watching and listening carefully for signs that the operation could have been compromised and as a +result of those enquiries we have discovered a new top secret agency known only by the acronym boss +stop we have been unable to infiltrate this group but it is known that the leader is someone with +the initial hand that they are taking the lead on signals intelligence stop the head of the +counterintelligence branch uses the codename pearl and we will be making every effort to discover +her identity stop while the declaration of war and the destruction of the rdf system are the central +goals of this operation the london triangle will be key to ensuring a flow of high quality +intelligence to inform our battle plans stop without their communications we will be unable to +monitor british plans placing german lives at unnecessary risks top if there is any chance that +members of your group could be captured and interrogated then you should abandon the sabotage +operation and return to tirpitz ufer stop protecting the identity of the triangle is of far greater +longterm importance to us stop we can find other ways to provoke the war but we would find it more +difficult to ensure that we can win it without a network of agents in the capital stop the mission +will be regarded as a success only if we can guarantee their safety stop to increase the security of +the london triangle it is crucial that the clock cipher device and the associated code books reach +our london agents stop the device can not be allowed to fall into enemy hands and this must be the +top priority stop if you are captured then the codebook containing the keys to the cipher must be +destroyed stop it is printed on special paper that should easily dissolve but it can also be +ingested if necessary stop when using the machine take care to erase the cipher alphabet after use +and to delete the key from the codebook to ensure that no one uses the same key twice stop this will +also reduce the risk of the keyed cipher falling into enemy hands stop if capture appears imminent +then use one of the shaped charges to destroy the device preferably burying it together with the +charge to increase the destructive power and make it harder to reconstruct stop everyone in the +movement will be praying for your success and your courage and commitment to the fatherland will be +praised forever stop you are an inspiration to us all stop wishing you luck in the final phase of +the operations top yours uncle wilhelm \ No newline at end of file -- 2.34.1 From 836627202b29b8fb000481bc68bb8089f590c895 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 14 Oct 2021 11:31:07 +0100 Subject: [PATCH 08/16] 2021 challenge 1 --- 2021/2021-challenge1.ipynb | 194 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge1.md | 58 +++++++++++ 2021/ciphertext.1a.txt | 5 + 2021/ciphertext.1b.txt | 7 ++ 2021/plaintext.1a.txt | 5 + 2021/plaintext.1b.txt | 7 ++ 6 files changed, 276 insertions(+) create mode 100644 2021/2021-challenge1.ipynb create mode 100644 2021/2021-challenge1.md create mode 100644 2021/ciphertext.1a.txt create mode 100644 2021/ciphertext.1b.txt create mode 100644 2021/plaintext.1a.txt create mode 100644 2021/plaintext.1b.txt diff --git a/2021/2021-challenge1.ipynb b/2021/2021-challenge1.ipynb new file mode 100644 index 0000000..181561a --- /dev/null +++ b/2021/2021-challenge1.ipynb @@ -0,0 +1,194 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "0039d39a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "e23051fb", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 1\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": 4, + "id": "d1d1a7bc", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "45504249", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25 \n", + "\n", + "HARRY, I AM BORED, AND I AM REALLY NOT SURE WHY I HAVE BEEN EXILED TO THE ARCHAEOLOGISTS. DID I DO SOMETHING TO UPSET SOMEONE? I AM REALLY, REALLY HOPING THAT OUR OVERLORDS WILL FIND SOMETHING A BIT MORE RELEVANT FOR ME TO TACKLE SOON.\n", + "THE GROUP HERE IS GREAT, BUT IT FEELS LIKE THERE IS A DIMINISHING RETURN ON BREAKING WWII CIPHERS SEVENTY-SIX YEARS ON, AND EVEN THE COLD WAR FIALKA INTERCEPT PILE DOESN'T SEEM TO BE GIVING MUCH BACK. IF YOU DON'T HAVE ANYTHING FOR ME TO WORK ON, THEN MAYBE YOU COULD SEND OVER SOME NEWBIES FOR ME TO TRAIN UP? WE RECEIVED A STACK OF MATERIAL FROM LONDON A COUPLE OF WEEKS AGO THAT MIGHT MAKE A GOOD EXERCISE FOR THEM, AND WHILE THE FIRST FEW TEXTS ARE RELATIVELY SIMPLE, IT WOULD BE A GOOD EXERCISE FOR YOUNG ANALYSTS TO TRY TO WORK OUT WHAT THEY ARE TELLING US.\n", + "I HAVE ATTACHED THE FIRST ITEM FROM THE BATCH SO YOU CAN SEE WHAT I MEAN. I WOULD VERY DEARLY LIKE TO KNOW WHAT \"THE GREAT MATTER\" REFERS TO, AND I SUSPECT YOU WILL WANT TO KNOW TOO.\n", + "THE RECRUITS DON'T NEED TO KNOW MUCH TO BREAK THIS ONE; IF THEY HAVE DONE OUR INDUCTION TRAINING ON BASIC CIPHERS, THEY SHOULD BE FINE. MY COLLEAGUES HERE HAVE NICKNAMED THIS FILE THE LIGHTHOUSE CONSPIRACY, BECAUSE OF WHERE THE PAPERS WERE FOUND. THAT MAKES IT SOUND A LOT MORE IMPRESSIVE THAN IT FIRST LOOKS, BUT YOU NEVER KNOW WHERE SOMETHING LIKE THIS MIGHT LEAD. I HAVE SET UP A SECURE ONLINE SYSTEM SO THE TRAINEES CAN GET ACCESS TO CASE FILES AND SEND ME THEIR ATTEMPTS AT DECIPHERING. IF YOU POINT THEM THERE, THEN I WILL CHECK HOW THEY ARE GETTING ON. MAYBE THEY COULD LOOK AT THE BOSS CODEBREAKING GUIDE AS WELL IF THEY NEED TO BRUSH UP THEIR SKILLS.\n", + "ALL THE BEST, JODIE\n", + "\n" + ] + } + ], + "source": [ + "k_a, score_a = caesar_break(ca)\n", + "print(k_a, '\\n')\n", + "pa = caesar_decipher(ca, k_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "969933ef", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1663" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "90c206f4", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3 \n", + "\n", + "MY DEAR M, THANK YOU FOR LETTING ME KNOW ABOUT T'S OFFER TO JOIN WITH US IN THE GREAT MATTER. WHILE I STILL HAVE MANY IDEAS FOR HOW TO PROSECUTE OUR PLAN, MY DAYS ARE GROWING SHORT, AS ARE YOURS, AND WE WILL NEED TO FIND OTHERS OF A SIMILAR MIND WHO HAVE THE WIT AND IMAGINATION TO CARRY IT FORWARD. OUR ABILITY TO INFLUENCE MATTERS DIRECTLY WILL CONTINUE TO DEPEND ON THE POWER OF THE DEVICES WE CAN FASHION, AND IT WILL BE CLEAR TO YOU THAT THIS WILL REQUIRE NEW WAYS OF THINKING ABOUT THE WORLD AS WELL AS NEW TECHNOLOGIES TO MANIPULATE IT. T, TOGETHER WITH L AND THE YOUNG E WILL, I HOPE, BRING A NEW PERSPECTIVE, AND HELP TO KEEP OUR LITTLE CONSPIRACY ALIVE FOR ANOTHER GENERATION.\n", + "OUR ADVENTURES SO FAR HAVE, OF NECESSITY, BEEN LIMITED IN SCOPE, THOUGH OUR ACQUISITION OF BABBAGE'S PLANS AND THE SUPPRESSION OF HIS ANALYTIC ENGINE MUST COUNT AS A HIGHLIGHT. IF WE ARE TO SUCCEED ON THE GRAND SCALE THAT WE BOTH THINK IS NECESSARY, THEN IT IS TIME FOR US TO FORMALISE OUR ARRANGEMENTS AND TO ESTABLISH A HEADQUARTERS FOR OUR OPERATIONS.\n", + "I HAVE GIVEN THIS SOME THOUGHT AND HAVE AN IDEA THAT I HOPE WILL PLEASE YOU. WE SHOULD BUILD A LIGHTHOUSE IN LONDON! I CAN IMMEDIATELY SEE YOUR OBJECTION. LONDON HAS NO ROCKY SHORES, AND SO NO NEED OF ONE, BUT YOUR EXPERIMENTS WITH LANTERNS GIVE US THE IDEAL EXCUSE TO BUILD ONE AS A PLACE TO TEST THEM.\n", + "THE OPPORTUNITIES THIS WILL AFFORD ARE MANY: THE DELIVERY OF LARGE CRATES OF EQUIPMENT WILL GO UNNOTICED, CONSIDERED AS PART OF THE NATURAL BUSINESS OF THE PLACE; ITS LOCATION ON A BUSY WHARF WOULD DISGUISE THE NECESSARY COMINGS AND GOINGS OF OUR CO-CONSPIRATORS; THE WATERWAY WILL PROVIDE US WITH READY TRANSPORTATION BOTH INLAND VIA THE CANALS AND TO THE DOCKS AT TILBURY FOR OUR INTERNATIONAL VENTURES. NOT LEAST, THE EXTRAORDINARY POWER NEEDED FOR OUR DEVICES WILL BE MISTAKEN FOR THE ENERGY REQUIRED TO RUN YOUR PUBLIC EXPERIMENTS.\n", + "I HAVE LITTLE EXPERTISE IN THE DESIGN OR ENGINEERING OF SUCH STRUCTURES, BUT I IMAGINE THAT THEY REQUIRE SUBSTANTIAL FOOTINGS. THE DEVELOPMENT OF THESE WILL PROVIDE THE COVER WE NEED TO CONSTRUCT OUR SECRET HEADQUARTERS UNDER THE MORE PUBLIC FACE OF THE LIGHTHOUSE ITSELF AND ITS ANCILLARY BUILDINGS.\n", + "IT MAY BE THAT I HAVE MISSED SOMETHING IMPORTANT IN MY CONSIDERATIONS, IN WHICH CASE PLEASE DO POINT THAT OUT, BUT IF WE ARE TO PASS ON OUR DISCOVERIES, AMBITIONS AND PLANS TO THE NEXT GENERATION WE WILL NEED TO GIVE THEM A MORE PERMANENT HOME, SO I HOPE WE CAN AGREE TOGETHER ON THE BEST WAY TO PROCEED.\n", + "YOURS, CH\n", + "\n" + ] + } + ], + "source": [ + "k_b, score_b = caesar_break(cb)\n", + "print(k_b, '\\n')\n", + "pb = caesar_decipher(cb, k_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "cda2f09b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2499" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c1be9f8", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md", + "text_representation": { + "extension": ".md", + "format_name": "markdown", + "format_version": "1.2", + "jupytext_version": "1.3.4" + } + }, + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge1.md b/2021/2021-challenge1.md new file mode 100644 index 0000000..0c1eee1 --- /dev/null +++ b/2021/2021-challenge1.md @@ -0,0 +1,58 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +``` + +```python Collapsed="false" +challenge_number = 1 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() +``` + +```python Collapsed="false" +k_a, score_a = caesar_break(ca) +print(k_a, '\n') +pa = caesar_decipher(ca, k_a) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python Collapsed="false" +k_b, score_b = caesar_break(cb) +print(k_b, '\n') +pb = caesar_decipher(cb, k_b) +print(pb) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.1a.txt b/2021/ciphertext.1a.txt new file mode 100644 index 0000000..5b52fa6 --- /dev/null +++ b/2021/ciphertext.1a.txt @@ -0,0 +1,5 @@ +GZQQX, H ZL ANQDC, ZMC H ZL QDZKKX MNS RTQD VGX H GZUD ADDM DWHKDC SN SGD ZQBGZDNKNFHRSR. CHC H CN RNLDSGHMF SN TORDS RNLDNMD? H ZL QDZKKX, QDZKKX GNOHMF SGZS NTQ NUDQKNQCR VHKK EHMC RNLDSGHMF Z AHS LNQD QDKDUZMS ENQ LD SN SZBJKD RNNM. +SGD FQNTO GDQD HR FQDZS, ATS HS EDDKR KHJD SGDQD HR Z CHLHMHRGHMF QDSTQM NM AQDZJHMF VVHH BHOGDQR RDUDMSX-RHW XDZQR NM, ZMC DUDM SGD BNKC VZQ EHZKJZ HMSDQBDOS OHKD CNDRM'S RDDL SN AD FHUHMF LTBG AZBJ. HE XNT CNM'S GZUD ZMXSGHMF ENQ LD SN VNQJ NM, SGDM LZXAD XNT BNTKC RDMC NUDQ RNLD MDVAHDR ENQ LD SN SQZHM TO? VD QDBDHUDC Z RSZBJ NE LZSDQHZK EQNL KNMCNM Z BNTOKD NE VDDJR ZFN SGZS LHFGS LZJD Z FNNC DWDQBHRD ENQ SGDL, ZMC VGHKD SGD EHQRS EDV SDWSR ZQD QDKZSHUDKX RHLOKD, HS VNTKC AD Z FNNC DWDQBHRD ENQ XNTMF ZMZKXRSR SN SQX SN VNQJ NTS VGZS SGDX ZQD SDKKHMF TR. +H GZUD ZSSZBGDC SGD EHQRS HSDL EQNL SGD AZSBG RN XNT BZM RDD VGZS H LDZM. H VNTKC UDQX CDZQKX KHJD SN JMNV VGZS "SGD FQDZS LZSSDQ" QDEDQR SN, ZMC H RTRODBS XNT VHKK VZMS SN JMNV SNN. +SGD QDBQTHSR CNM'S MDDC SN JMNV LTBG SN AQDZJ SGHR NMD; HE SGDX GZUD CNMD NTQ HMCTBSHNM SQZHMHMF NM AZRHB BHOGDQR, SGDX RGNTKC AD EHMD. LX BNKKDZFTDR GDQD GZUD MHBJMZLDC SGHR EHKD SGD KHFGSGNTRD BNMROHQZBX, ADBZTRD NE VGDQD SGD OZODQR VDQD ENTMC. SGZS LZJDR HS RNTMC Z KNS LNQD HLOQDRRHUD SGZM HS EHQRS KNNJR, ATS XNT MDUDQ JMNV VGDQD RNLDSGHMF KHJD SGHR LHFGS KDZC. H GZUD RDS TO Z RDBTQD NMKHMD RXRSDL RN SGD SQZHMDDR BZM FDS ZBBDRR SN BZRD EHKDR ZMC RDMC LD SGDHQ ZSSDLOSR ZS CDBHOGDQHMF. HE XNT ONHMS SGDL SGDQD, SGDM H VHKK BGDBJ GNV SGDX ZQD FDSSHMF NM. LZXAD SGDX BNTKC KNNJ ZS SGD ANRR BNCDAQDZJHMF FTHCD ZR VDKK HE SGDX MDDC SN AQTRG TO SGDHQ RJHKKR. +ZKK SGD ADRS, INCHD diff --git a/2021/ciphertext.1b.txt b/2021/ciphertext.1b.txt new file mode 100644 index 0000000..22bb155 --- /dev/null +++ b/2021/ciphertext.1b.txt @@ -0,0 +1,7 @@ +PB GHDU P, WKDQN BRX IRU OHWWLQJ PH NQRZ DERXW W'V RIIHU WR MRLQ ZLWK XV LQ WKH JUHDW PDWWHU. ZKLOH L VWLOO KDYH PDQB LGHDV IRU KRZ WR SURVHFXWH RXU SODQ, PB GDBV DUH JURZLQJ VKRUW, DV DUH BRXUV, DQG ZH ZLOO QHHG WR ILQG RWKHUV RI D VLPLODU PLQG ZKR KDYH WKH ZLW DQG LPDJLQDWLRQ WR FDUUB LW IRUZDUG. RXU DELOLWB WR LQIOXHQFH PDWWHUV GLUHFWOB ZLOO FRQWLQXH WR GHSHQG RQ WKH SRZHU RI WKH GHYLFHV ZH FDQ IDVKLRQ, DQG LW ZLOO EH FOHDU WR BRX WKDW WKLV ZLOO UHTXLUH QHZ ZDBV RI WKLQNLQJ DERXW WKH ZRUOG DV ZHOO DV QHZ WHFKQRORJLHV WR PDQLSXODWH LW. W, WRJHWKHU ZLWK O DQG WKH BRXQJ H ZLOO, L KRSH, EULQJ D QHZ SHUVSHFWLYH, DQG KHOS WR NHHS RXU OLWWOH FRQVSLUDFB DOLYH IRU DQRWKHU JHQHUDWLRQ. +RXU DGYHQWXUHV VR IDU KDYH, RI QHFHVVLWB, EHHQ OLPLWHG LQ VFRSH, WKRXJK RXU DFTXLVLWLRQ RI EDEEDJH'V SODQV DQG WKH VXSSUHVVLRQ RI KLV DQDOBWLF HQJLQH PXVW FRXQW DV D KLJKOLJKW. LI ZH DUH WR VXFFHHG RQ WKH JUDQG VFDOH WKDW ZH ERWK WKLQN LV QHFHVVDUB, WKHQ LW LV WLPH IRU XV WR IRUPDOLVH RXU DUUDQJHPHQWV DQG WR HVWDEOLVK D KHDGTXDUWHUV IRU RXU RSHUDWLRQV. +L KDYH JLYHQ WKLV VRPH WKRXJKW DQG KDYH DQ LGHD WKDW L KRSH ZLOO SOHDVH BRX. ZH VKRXOG EXLOG D OLJKWKRXVH LQ ORQGRQ! L FDQ LPPHGLDWHOB VHH BRXU REMHFWLRQ. ORQGRQ KDV QR URFNB VKRUHV, DQG VR QR QHHG RI RQH, EXW BRXU HASHULPHQWV ZLWK ODQWHUQV JLYH XV WKH LGHDO HAFXVH WR EXLOG RQH DV D SODFH WR WHVW WKHP. +WKH RSSRUWXQLWLHV WKLV ZLOO DIIRUG DUH PDQB: WKH GHOLYHUB RI ODUJH FUDWHV RI HTXLSPHQW ZLOO JR XQQRWLFHG, FRQVLGHUHG DV SDUW RI WKH QDWXUDO EXVLQHVV RI WKH SODFH; LWV ORFDWLRQ RQ D EXVB ZKDUI ZRXOG GLVJXLVH WKH QHFHVVDUB FRPLQJV DQG JRLQJV RI RXU FR-FRQVSLUDWRUV; WKH ZDWHUZDB ZLOO SURYLGH XV ZLWK UHDGB WUDQVSRUWDWLRQ ERWK LQODQG YLD WKH FDQDOV DQG WR WKH GRFNV DW WLOEXUB IRU RXU LQWHUQDWLRQDO YHQWXUHV. QRW OHDVW, WKH HAWUDRUGLQDUB SRZHU QHHGHG IRU RXU GHYLFHV ZLOO EH PLVWDNHQ IRU WKH HQHUJB UHTXLUHG WR UXQ BRXU SXEOLF HASHULPHQWV. +L KDYH OLWWOH HASHUWLVH LQ WKH GHVLJQ RU HQJLQHHULQJ RI VXFK VWUXFWXUHV, EXW L LPDJLQH WKDW WKHB UHTXLUH VXEVWDQWLDO IRRWLQJV. WKH GHYHORSPHQW RI WKHVH ZLOO SURYLGH WKH FRYHU ZH QHHG WR FRQVWUXFW RXU VHFUHW KHDGTXDUWHUV XQGHU WKH PRUH SXEOLF IDFH RI WKH OLJKWKRXVH LWVHOI DQG LWV DQFLOODUB EXLOGLQJV. +LW PDB EH WKDW L KDYH PLVVHG VRPHWKLQJ LPSRUWDQW LQ PB FRQVLGHUDWLRQV, LQ ZKLFK FDVH SOHDVH GR SRLQW WKDW RXW, EXW LI ZH DUH WR SDVV RQ RXU GLVFRYHULHV, DPELWLRQV DQG SODQV WR WKH QHAW JHQHUDWLRQ ZH ZLOO QHHG WR JLYH WKHP D PRUH SHUPDQHQW KRPH, VR L KRSH ZH FDQ DJUHH WRJHWKHU RQ WKH EHVW ZDB WR SURFHHG. +BRXUV, FK diff --git a/2021/plaintext.1a.txt b/2021/plaintext.1a.txt new file mode 100644 index 0000000..f2badc8 --- /dev/null +++ b/2021/plaintext.1a.txt @@ -0,0 +1,5 @@ +HARRY, I AM BORED, AND I AM REALLY NOT SURE WHY I HAVE BEEN EXILED TO THE ARCHAEOLOGISTS. DID I DO SOMETHING TO UPSET SOMEONE? I AM REALLY, REALLY HOPING THAT OUR OVERLORDS WILL FIND SOMETHING A BIT MORE RELEVANT FOR ME TO TACKLE SOON. +THE GROUP HERE IS GREAT, BUT IT FEELS LIKE THERE IS A DIMINISHING RETURN ON BREAKING WWII CIPHERS SEVENTY-SIX YEARS ON, AND EVEN THE COLD WAR FIALKA INTERCEPT PILE DOESN'T SEEM TO BE GIVING MUCH BACK. IF YOU DON'T HAVE ANYTHING FOR ME TO WORK ON, THEN MAYBE YOU COULD SEND OVER SOME NEWBIES FOR ME TO TRAIN UP? WE RECEIVED A STACK OF MATERIAL FROM LONDON A COUPLE OF WEEKS AGO THAT MIGHT MAKE A GOOD EXERCISE FOR THEM, AND WHILE THE FIRST FEW TEXTS ARE RELATIVELY SIMPLE, IT WOULD BE A GOOD EXERCISE FOR YOUNG ANALYSTS TO TRY TO WORK OUT WHAT THEY ARE TELLING US. +I HAVE ATTACHED THE FIRST ITEM FROM THE BATCH SO YOU CAN SEE WHAT I MEAN. I WOULD VERY DEARLY LIKE TO KNOW WHAT "THE GREAT MATTER" REFERS TO, AND I SUSPECT YOU WILL WANT TO KNOW TOO. +THE RECRUITS DON'T NEED TO KNOW MUCH TO BREAK THIS ONE; IF THEY HAVE DONE OUR INDUCTION TRAINING ON BASIC CIPHERS, THEY SHOULD BE FINE. MY COLLEAGUES HERE HAVE NICKNAMED THIS FILE THE LIGHTHOUSE CONSPIRACY, BECAUSE OF WHERE THE PAPERS WERE FOUND. THAT MAKES IT SOUND A LOT MORE IMPRESSIVE THAN IT FIRST LOOKS, BUT YOU NEVER KNOW WHERE SOMETHING LIKE THIS MIGHT LEAD. I HAVE SET UP A SECURE ONLINE SYSTEM SO THE TRAINEES CAN GET ACCESS TO CASE FILES AND SEND ME THEIR ATTEMPTS AT DECIPHERING. IF YOU POINT THEM THERE, THEN I WILL CHECK HOW THEY ARE GETTING ON. MAYBE THEY COULD LOOK AT THE BOSS CODEBREAKING GUIDE AS WELL IF THEY NEED TO BRUSH UP THEIR SKILLS. +ALL THE BEST, JODIE diff --git a/2021/plaintext.1b.txt b/2021/plaintext.1b.txt new file mode 100644 index 0000000..f1b82b8 --- /dev/null +++ b/2021/plaintext.1b.txt @@ -0,0 +1,7 @@ +MY DEAR M, THANK YOU FOR LETTING ME KNOW ABOUT T'S OFFER TO JOIN WITH US IN THE GREAT MATTER. WHILE I STILL HAVE MANY IDEAS FOR HOW TO PROSECUTE OUR PLAN, MY DAYS ARE GROWING SHORT, AS ARE YOURS, AND WE WILL NEED TO FIND OTHERS OF A SIMILAR MIND WHO HAVE THE WIT AND IMAGINATION TO CARRY IT FORWARD. OUR ABILITY TO INFLUENCE MATTERS DIRECTLY WILL CONTINUE TO DEPEND ON THE POWER OF THE DEVICES WE CAN FASHION, AND IT WILL BE CLEAR TO YOU THAT THIS WILL REQUIRE NEW WAYS OF THINKING ABOUT THE WORLD AS WELL AS NEW TECHNOLOGIES TO MANIPULATE IT. T, TOGETHER WITH L AND THE YOUNG E WILL, I HOPE, BRING A NEW PERSPECTIVE, AND HELP TO KEEP OUR LITTLE CONSPIRACY ALIVE FOR ANOTHER GENERATION. +OUR ADVENTURES SO FAR HAVE, OF NECESSITY, BEEN LIMITED IN SCOPE, THOUGH OUR ACQUISITION OF BABBAGE'S PLANS AND THE SUPPRESSION OF HIS ANALYTIC ENGINE MUST COUNT AS A HIGHLIGHT. IF WE ARE TO SUCCEED ON THE GRAND SCALE THAT WE BOTH THINK IS NECESSARY, THEN IT IS TIME FOR US TO FORMALISE OUR ARRANGEMENTS AND TO ESTABLISH A HEADQUARTERS FOR OUR OPERATIONS. +I HAVE GIVEN THIS SOME THOUGHT AND HAVE AN IDEA THAT I HOPE WILL PLEASE YOU. WE SHOULD BUILD A LIGHTHOUSE IN LONDON! I CAN IMMEDIATELY SEE YOUR OBJECTION. LONDON HAS NO ROCKY SHORES, AND SO NO NEED OF ONE, BUT YOUR EXPERIMENTS WITH LANTERNS GIVE US THE IDEAL EXCUSE TO BUILD ONE AS A PLACE TO TEST THEM. +THE OPPORTUNITIES THIS WILL AFFORD ARE MANY: THE DELIVERY OF LARGE CRATES OF EQUIPMENT WILL GO UNNOTICED, CONSIDERED AS PART OF THE NATURAL BUSINESS OF THE PLACE; ITS LOCATION ON A BUSY WHARF WOULD DISGUISE THE NECESSARY COMINGS AND GOINGS OF OUR CO-CONSPIRATORS; THE WATERWAY WILL PROVIDE US WITH READY TRANSPORTATION BOTH INLAND VIA THE CANALS AND TO THE DOCKS AT TILBURY FOR OUR INTERNATIONAL VENTURES. NOT LEAST, THE EXTRAORDINARY POWER NEEDED FOR OUR DEVICES WILL BE MISTAKEN FOR THE ENERGY REQUIRED TO RUN YOUR PUBLIC EXPERIMENTS. +I HAVE LITTLE EXPERTISE IN THE DESIGN OR ENGINEERING OF SUCH STRUCTURES, BUT I IMAGINE THAT THEY REQUIRE SUBSTANTIAL FOOTINGS. THE DEVELOPMENT OF THESE WILL PROVIDE THE COVER WE NEED TO CONSTRUCT OUR SECRET HEADQUARTERS UNDER THE MORE PUBLIC FACE OF THE LIGHTHOUSE ITSELF AND ITS ANCILLARY BUILDINGS. +IT MAY BE THAT I HAVE MISSED SOMETHING IMPORTANT IN MY CONSIDERATIONS, IN WHICH CASE PLEASE DO POINT THAT OUT, BUT IF WE ARE TO PASS ON OUR DISCOVERIES, AMBITIONS AND PLANS TO THE NEXT GENERATION WE WILL NEED TO GIVE THEM A MORE PERMANENT HOME, SO I HOPE WE CAN AGREE TOGETHER ON THE BEST WAY TO PROCEED. +YOURS, CH -- 2.34.1 From 7191a262ea3a83098da7cdf08c24bf45571c3b3d Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 14 Oct 2021 15:41:50 +0100 Subject: [PATCH 09/16] Done challenge 2 --- 2021/2021-challenge2.ipynb | 205 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge2.md | 62 +++++++++++ 2021/ciphertext.2a.txt | 1 + 2021/ciphertext.2b.txt | 9 ++ 2021/plaintext.2a.txt | 1 + 2021/plaintext.2b.txt | 9 ++ 6 files changed, 287 insertions(+) create mode 100644 2021/2021-challenge2.ipynb create mode 100644 2021/2021-challenge2.md create mode 100644 2021/ciphertext.2a.txt create mode 100644 2021/ciphertext.2b.txt create mode 100644 2021/plaintext.2a.txt create mode 100644 2021/plaintext.2b.txt diff --git a/2021/2021-challenge2.ipynb b/2021/2021-challenge2.ipynb new file mode 100644 index 0000000..ee6f28b --- /dev/null +++ b/2021/2021-challenge2.ipynb @@ -0,0 +1,205 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e89c0bd1", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "e328ffba", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 2\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": 3, + "id": "17cf9fb6", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0fd1afb3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((9, 23, True), -2276.8668346831637)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "affine_break(ca)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "7f378aab", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9 23 True \n", + "\n", + "Jodie, you were not placed with the Archaeologists as a punishment; everyone takes their turn on that shift because we never know what might turn up in old documents. When I ran the group, we found evidence of a Russian agent placed in the SDECE in the aftermath of the war who was acting as liaison with British and US intelligence. She had remained undiscovered for thirty-five years and leaked a whole load of information across the iron curtain. The team cracked a Fialka cipher from 1956, and that led to an arrest and confession. I admit that the case you are working on doesn’t seem likely to have the same impact, but you never know where it might lead. I took a look at the papers you sent, and I thought this one looked very interesting. The information it contains ties down the year it was written pretty conclusively, and I have to say I don’t like the sound of the phrase “profit from the Schleswig conflict”. I think it is clear who M must be, but I am still unsure about the others mentioned in these letters. I am also very unclear why M might have been involved in what looks like a conspiracy aimed at wartime profiteering. I checked, and there is nothing on file from the period to suggest that this was suspected. Indeed there was nothing on file at all, which, thinking about it is slightly strange. M was a public figure and of definite interest, so there should be something. If you have time it might be worth logging in to the records system to see if anyone else from around then has a suspiciously empty file. I would start with public figures who have the initials CH or FN, as the single letters A, T, E and W don’t give us much to go on. Of course, we do know a little more about W, so that might also be a good place to start. We know we are looking for an engineer with initial W, who knows something about codes and ciphers. Whoever FN is, they are right that they should talk to W. Using Caesar and affine shift ciphers to encode their secret communications is poor, and I would have expected better from an organisation containing M. Perhaps they will have taken the mysterious W’s advice and will have switched to something more secure in their future communications. That will make life a little more interesting for you and the team. Good luck, Harry\n", + "\n" + ] + } + ], + "source": [ + "(m_a, a_a, z_a), score_a = affine_break(ca)\n", + "print(m_a, a_a, z_a, '\\n')\n", + "pa = affine_decipher(ca, m_a, a_a, z_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "dda44618", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2290" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "0b9d3e6a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11 9 True \n", + "\n", + "My dearest M,\n", + "Can it really be sixteen years since Caroline first proposed this venture? I cannot believe it and wish with all my heart that she could have seen her vision taking shape.\n", + "Last Wednesday I took the opportunity you so kindly offered to see the progress with the foundation for myself. I was very encouraged by the industry on display, however I left with a concern that we may have miscalculated in our plans to hide the facility in the basement of the building. The ventilation there will, of necessity, be far more restricted than it would be on the upper floors, as I know from my own research. The evidence from your experiments suggests that our device will produce a very large amount of heat in operation. I cannot say for sure, but it seems likely that this will cause problems, both for the device itself and for its operators.\n", + "Looking at the plans, I wondered briefly if we could hide it instead on an upper floor of the lighthouse, but you are likely to have many visitors who are inclined to curiosity, and I suspect the secret would not stay safe for long. We cannot take any risk that might expose us, and even if we keep it behind a locked door, the noise it will generate in operation will propagate more easily across the wharf, leading to questions. In the basement we can at least suppress the noise, reducing that risk, but that leaves the issue of managing the heat.\n", + "I am at a loss. Any changes we want to make to the design of the laboratory and its facilities will need to be made very soon, as once the upper floors are built further heavy construction would attract unwanted attention. Perhaps W will be able to suggest something; he is, after all, an engineer. in any case, I was planning to ask him to join us as head of security. I understand that he has some rather interesting ideas about codes and ciphers.\n", + "\n", + "On a less pressing matter, our first experiments with the prototype are showing some success. If we had been able to run them earlier this year, we may even have been able to profit from the Schleswig conflict, and it may not be too late to do so if we can mobilise our agents. There is much to play for here. Others will be seeking to gain from the conflict, and I see no reason why we cannot do so too.\n", + "Ever yours,\n", + "FN\n", + "\n" + ] + } + ], + "source": [ + "(m_b, a_b, z_b), score_a = affine_break(cb)\n", + "print(m_b, a_b, z_b, '\\n')\n", + "pb = affine_decipher(cb, m_b, a_b, z_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "d7293627", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2272" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "404b70cf", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge2.md b/2021/2021-challenge2.md new file mode 100644 index 0000000..15a217f --- /dev/null +++ b/2021/2021-challenge2.md @@ -0,0 +1,62 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +``` + +```python Collapsed="false" +challenge_number = 2 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() +``` + +```python +affine_break(ca) +``` + +```python Collapsed="false" +(m_a, a_a, z_a), score_a = affine_break(ca) +print(m_a, a_a, z_a, '\n') +pa = affine_decipher(ca, m_a, a_a, z_a) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python +(m_b, a_b, z_b), score_a = affine_break(cb) +print(m_b, a_b, z_b, '\n') +pb = affine_decipher(cb, m_b, a_b, z_b) +print(pb) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(pb) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.2a.txt b/2021/ciphertext.2a.txt new file mode 100644 index 0000000..1023c79 --- /dev/null +++ b/2021/ciphertext.2a.txt @@ -0,0 +1 @@ +Ibgzp, nbd vpcp sbu kafxpg vzuq uqp Fcxqfpbabhzlul fl f kdszlqjpsu; pmpcnbsp ufrpl uqpzc udcs bs uqfu lqzyu opxfdlp vp spmpc rsbv vqfu jzhqu udcs dk zs bag gbxdjpsul. Vqps Z cfs uqp hcbdk, vp ybdsg pmzgpsxp by f Cdllzfs fhpsu kafxpg zs uqp LGPXP zs uqp fyupcjfuq by uqp vfc vqb vfl fxuzsh fl azfzlbs vzuq Oczuzlq fsg DL zsupaazhpsxp. Lqp qfg cpjfzspg dsgzlxbmpcpg ybc uqzcun-yzmp npfcl fsg apfrpg f vqbap abfg by zsybcjfuzbs fxcbll uqp zcbs xdcufzs. Uqp upfj xcfxrpg f Yzfarf xzkqpc ycbj 1956, fsg uqfu apg ub fs fccplu fsg xbsypllzbs. Z fgjzu uqfu uqp xflp nbd fcp vbcrzsh bs gbpls’u lppj azrpan ub qfmp uqp lfjp zjkfxu, odu nbd spmpc rsbv vqpcp zu jzhqu apfg. Z ubbr f abbr fu uqp kfkpcl nbd lpsu, fsg Z uqbdhqu uqzl bsp abbrpg mpcn zsupcpluzsh. Uqp zsybcjfuzbs zu xbsufzsl uzpl gbvs uqp npfc zu vfl vczuups kcpuun xbsxadlzmpan, fsg Z qfmp ub lfn Z gbs’u azrp uqp lbdsg by uqp kqcflp “kcbyzu ycbj uqp Lxqaplvzh xbsyazxu”. Z uqzsr zu zl xapfc vqb J jdlu op, odu Z fj luzaa dsldcp fobdu uqp buqpcl jpsuzbspg zs uqplp apuupcl. Z fj falb mpcn dsxapfc vqn J jzhqu qfmp opps zsmbampg zs vqfu abbrl azrp f xbslkzcfxn fzjpg fu vfcuzjp kcbyzuppczsh. Z xqpxrpg, fsg uqpcp zl sbuqzsh bs yzap ycbj uqp kpczbg ub ldhhplu uqfu uqzl vfl ldlkpxupg. Zsgppg uqpcp vfl sbuqzsh bs yzap fu faa, vqzxq, uqzsrzsh fobdu zu zl lazhquan lucfshp. J vfl f kdoazx yzhdcp fsg by gpyzszup zsupcplu, lb uqpcp lqbdag op lbjpuqzsh. Zy nbd qfmp uzjp zu jzhqu op vbcuq abhhzsh zs ub uqp cpxbcgl lnlupj ub lpp zy fsnbsp palp ycbj fcbdsg uqps qfl f ldlkzxzbdlan pjkun yzap. Z vbdag lufcu vzuq kdoazx yzhdcpl vqb qfmp uqp zszuzfal XQ bc YS, fl uqp lzshap apuupcl F, U, P fsg V gbs’u hzmp dl jdxq ub hb bs. By xbdclp, vp gb rsbv f azuuap jbcp fobdu V, lb uqfu jzhqu falb op f hbbg kafxp ub lufcu. Vp rsbv vp fcp abbrzsh ybc fs pshzsppc vzuq zszuzfa V, vqb rsbvl lbjpuqzsh fobdu xbgpl fsg xzkqpcl. Vqbpmpc YS zl, uqpn fcp czhqu uqfu uqpn lqbdag ufar ub V. Dlzsh Xfplfc fsg fyyzsp lqzyu xzkqpcl ub psxbgp uqpzc lpxcpu xbjjdszxfuzbsl zl kbbc, fsg Z vbdag qfmp pekpxupg opuupc ycbj fs bchfszlfuzbs xbsufzszsh J. Kpcqfkl uqpn vzaa qfmp ufrps uqp jnlupczbdl V’l fgmzxp fsg vzaa qfmp lvzuxqpg ub lbjpuqzsh jbcp lpxdcp zs uqpzc ydudcp xbjjdszxfuzbsl. Uqfu vzaa jfrp azyp f azuuap jbcp zsupcpluzsh ybc nbd fsg uqp upfj. Hbbg adxr, Qfccn diff --git a/2021/ciphertext.2b.txt b/2021/ciphertext.2b.txt new file mode 100644 index 0000000..130836f --- /dev/null +++ b/2021/ciphertext.2b.txt @@ -0,0 +1,9 @@ +Vx altylju V, +Ptg du yltkkx el jdmullg xltyj jdgpl Ptyrkdgl wdyju cyrcrjla usdj qlgufyl? D ptggru elkdlql du tga bdjs bdus tkk vx sltyu ustu jsl prfka stql jllg sly qdjdrg utzdgh jstcl. +Ktju Blagljatx D urrz usl rccryufgdux xrf jr zdgakx rwwlyla ur jll usl cyrhyljj bdus usl wrfgatudrg wry vxjlkw. D btj qlyx lgprfythla ex usl dgafjuyx rg adjcktx, srblqly D klwu bdus t prgplyg ustu bl vtx stql vdjptkpfktula dg rfy cktgj ur sdal usl wtpdkdux dg usl etjlvlgu rw usl efdkadgh. Usl qlgudktudrg uslyl bdkk, rw glpljjdux, el wty vryl yljuydpula ustg du brfka el rg usl fccly wkrryj, tj D zgrb wyrv vx rbg yljltyps. Usl lqdalgpl wyrv xrfy lmclydvlguj jfhhljuj ustu rfy alqdpl bdkk cyrafpl t qlyx ktyhl tvrfgu rw sltu dg rclytudrg. D ptggru jtx wry jfyl, efu du jllvj kdzlkx ustu usdj bdkk ptfjl cyreklvj, erus wry usl alqdpl dujlkw tga wry duj rclyturyj. +Krrzdgh tu usl cktgj, D brgalyla eydlwkx dw bl prfka sdal du dgjulta rg tg fccly wkrry rw usl kdhsusrfjl, efu xrf tyl kdzlkx ur stql vtgx qdjduryj bsr tyl dgpkdgla ur pfydrjdux, tga D jfjclpu usl jlpylu brfka gru jutx jtwl wry krgh. Bl ptggru utzl tgx ydjz ustu vdhsu lmcrjl fj, tga lqlg dw bl zllc du elsdga t krpzla arry, usl grdjl du bdkk hlglytul dg rclytudrg bdkk cyrcthtul vryl ltjdkx tpyrjj usl bstyw, kltadgh ur nfljudrgj. Dg usl etjlvlgu bl ptg tu kltju jfccyljj usl grdjl, ylafpdgh ustu ydjz, efu ustu kltqlj usl djjfl rw vtgthdgh usl sltu. +D tv tu t krjj. Tgx pstghlj bl btgu ur vtzl ur usl aljdhg rw usl kteryturyx tga duj wtpdkdudlj bdkk glla ur el vtal qlyx jrrg, tj rgpl usl fccly wkrryj tyl efdku wfyusly sltqx prgjuyfpudrg brfka tuuytpu fgbtgula tuulgudrg. Clystcj B bdkk el tekl ur jfhhlju jrvlusdgh; sl dj, twuly tkk, tg lghdglly. dg tgx ptjl, D btj cktggdgh ur tjz sdv ur ordg fj tj slta rw jlpfydux. D fgalyjutga ustu sl stj jrvl ytusly dgulyljudgh daltj terfu pralj tga pdcslyj. + +Rg t kljj cyljjdgh vtuuly, rfy wdyju lmclydvlguj bdus usl cyruruxcl tyl jsrbdgh jrvl jfppljj. Dw bl sta ellg tekl ur yfg uslv ltykdly usdj xlty, bl vtx lqlg stql ellg tekl ur cyrwdu wyrv usl Jpskljbdh prgwkdpu, tga du vtx gru el urr ktul ur ar jr dw bl ptg vredkdjl rfy thlguj. Uslyl dj vfps ur cktx wry slyl. Ruslyj bdkk el jllzdgh ur htdg wyrv usl prgwkdpu, tga D jll gr yltjrg bsx bl ptggru ar jr urr. +Lqly xrfyj, +WG diff --git a/2021/plaintext.2a.txt b/2021/plaintext.2a.txt new file mode 100644 index 0000000..9ab97ca --- /dev/null +++ b/2021/plaintext.2a.txt @@ -0,0 +1 @@ +Jodie, you were not placed with the Archaeologists as a punishment; everyone takes their turn on that shift because we never know what might turn up in old documents. When I ran the group, we found evidence of a Russian agent placed in the SDECE in the aftermath of the war who was acting as liaison with British and US intelligence. She had remained undiscovered for thirty-five years and leaked a whole load of information across the iron curtain. The team cracked a Fialka cipher from 1956, and that led to an arrest and confession. I admit that the case you are working on doesn’t seem likely to have the same impact, but you never know where it might lead. I took a look at the papers you sent, and I thought this one looked very interesting. The information it contains ties down the year it was written pretty conclusively, and I have to say I don’t like the sound of the phrase “profit from the Schleswig conflict”. I think it is clear who M must be, but I am still unsure about the others mentioned in these letters. I am also very unclear why M might have been involved in what looks like a conspiracy aimed at wartime profiteering. I checked, and there is nothing on file from the period to suggest that this was suspected. Indeed there was nothing on file at all, which, thinking about it is slightly strange. M was a public figure and of definite interest, so there should be something. If you have time it might be worth logging in to the records system to see if anyone else from around then has a suspiciously empty file. I would start with public figures who have the initials CH or FN, as the single letters A, T, E and W don’t give us much to go on. Of course, we do know a little more about W, so that might also be a good place to start. We know we are looking for an engineer with initial W, who knows something about codes and ciphers. Whoever FN is, they are right that they should talk to W. Using Caesar and affine shift ciphers to encode their secret communications is poor, and I would have expected better from an organisation containing M. Perhaps they will have taken the mysterious W’s advice and will have switched to something more secure in their future communications. That will make life a little more interesting for you and the team. Good luck, Harry diff --git a/2021/plaintext.2b.txt b/2021/plaintext.2b.txt new file mode 100644 index 0000000..04b753e --- /dev/null +++ b/2021/plaintext.2b.txt @@ -0,0 +1,9 @@ +My dearest M, +Can it really be sixteen years since Caroline first proposed this venture? I cannot believe it and wish with all my heart that she could have seen her vision taking shape. +Last Wednesday I took the opportunity you so kindly offered to see the progress with the foundation for myself. I was very encouraged by the industry on display, however I left with a concern that we may have miscalculated in our plans to hide the facility in the basement of the building. The ventilation there will, of necessity, be far more restricted than it would be on the upper floors, as I know from my own research. The evidence from your experiments suggests that our device will produce a very large amount of heat in operation. I cannot say for sure, but it seems likely that this will cause problems, both for the device itself and for its operators. +Looking at the plans, I wondered briefly if we could hide it instead on an upper floor of the lighthouse, but you are likely to have many visitors who are inclined to curiosity, and I suspect the secret would not stay safe for long. We cannot take any risk that might expose us, and even if we keep it behind a locked door, the noise it will generate in operation will propagate more easily across the wharf, leading to questions. In the basement we can at least suppress the noise, reducing that risk, but that leaves the issue of managing the heat. +I am at a loss. Any changes we want to make to the design of the laboratory and its facilities will need to be made very soon, as once the upper floors are built further heavy construction would attract unwanted attention. Perhaps W will be able to suggest something; he is, after all, an engineer. in any case, I was planning to ask him to join us as head of security. I understand that he has some rather interesting ideas about codes and ciphers. + +On a less pressing matter, our first experiments with the prototype are showing some success. If we had been able to run them earlier this year, we may even have been able to profit from the Schleswig conflict, and it may not be too late to do so if we can mobilise our agents. There is much to play for here. Others will be seeking to gain from the conflict, and I see no reason why we cannot do so too. +Ever yours, +FN -- 2.34.1 From 8bed9f3e50a9c7591742003fe01487b0a1a586c1 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 22 Oct 2021 09:53:03 +0100 Subject: [PATCH 10/16] Done challenge 3 --- 2021/2021-challenge2.ipynb | 37 ++----- 2021/2021-challenge2.md | 4 - 2021/2021-challenge3.ipynb | 208 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge3.md | 62 +++++++++++ 2021/ciphertext.3a.txt | 6 ++ 2021/ciphertext.3b.txt | 1 + 2021/plaintext.3a.txt | 6 ++ 2021/plaintext.3b.txt | 27 +++++ 8 files changed, 318 insertions(+), 33 deletions(-) create mode 100644 2021/2021-challenge3.ipynb create mode 100644 2021/2021-challenge3.md create mode 100644 2021/ciphertext.3a.txt create mode 100644 2021/ciphertext.3b.txt create mode 100644 2021/plaintext.3a.txt create mode 100644 2021/plaintext.3b.txt diff --git a/2021/2021-challenge2.ipynb b/2021/2021-challenge2.ipynb index ee6f28b..bf25803 100644 --- a/2021/2021-challenge2.ipynb +++ b/2021/2021-challenge2.ipynb @@ -3,7 +3,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "e89c0bd1", + "id": "5c19999b", "metadata": { "Collapsed": "false" }, @@ -16,7 +16,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "e328ffba", + "id": "d9dd1b5e", "metadata": { "Collapsed": "false" }, @@ -32,7 +32,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "17cf9fb6", + "id": "0f1f792a", "metadata": { "Collapsed": "false" }, @@ -42,31 +42,10 @@ "cb = open(ciphertext_b_filename).read()" ] }, - { - "cell_type": "code", - "execution_count": 5, - "id": "0fd1afb3", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "((9, 23, True), -2276.8668346831637)" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "affine_break(ca)" - ] - }, { "cell_type": "code", "execution_count": 8, - "id": "7f378aab", + "id": "b3da7c78", "metadata": { "Collapsed": "false" }, @@ -92,7 +71,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "dda44618", + "id": "6cecddd9", "metadata": { "Collapsed": "false" }, @@ -115,7 +94,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "0b9d3e6a", + "id": "83a50584", "metadata": {}, "outputs": [ { @@ -147,7 +126,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "d7293627", + "id": "d12a663c", "metadata": { "Collapsed": "false" }, @@ -170,7 +149,7 @@ { "cell_type": "code", "execution_count": null, - "id": "404b70cf", + "id": "504ec2e2", "metadata": { "Collapsed": "false" }, diff --git a/2021/2021-challenge2.md b/2021/2021-challenge2.md index 15a217f..8bbb569 100644 --- a/2021/2021-challenge2.md +++ b/2021/2021-challenge2.md @@ -31,10 +31,6 @@ ca = open(ciphertext_a_filename).read() cb = open(ciphertext_b_filename).read() ``` -```python -affine_break(ca) -``` - ```python Collapsed="false" (m_a, a_a, z_a), score_a = affine_break(ca) print(m_a, a_a, z_a, '\n') diff --git a/2021/2021-challenge3.ipynb b/2021/2021-challenge3.ipynb new file mode 100644 index 0000000..86470de --- /dev/null +++ b/2021/2021-challenge3.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.support.text_prettify import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 3\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": 14, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c3cccd86-5e40-4040-8f91-9ca53ac6e909", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lighthouse KeywordWrapAlphabet.from_last \n", + "\n", + "harry, thanks for your email, i forgot you had spent time here in the archaeologists and it was good to be reminded that it can lead somewhere. in this case i think the best we can hope for is that we will have a new bunch of recruits trained and ready to tackle more serious challenges, but i have to admit that i am getting more excited about this case, even if it is just a training exercise.\n", + "the attached memo from abc reinforces what we learned from the last one. the lighthouse conspiracy seems to be a group of influential victorians who are aiming to use their newfound technological prowess to profit from war, famine, pestilence, and any other disturbance in the force. i don’t like to jump to conclusions, but i can’t help noticing that the initials coincide with people of interest to boss. i checked faraday’s intelligence file and as you say, it was empty. it is hard to believe that a scientist of his eminence had escaped notice, so it seems more likely that the real file has either been deleted or stored somewhere more secure. perhaps you can make enquiries? b must surely be babbage. all the talk in the attached letter is about a device that sounds like a computer, and that would mean that al is ada lovelace, who died some years before this letter was written. i can’t be sure who w or n are, but my guess is that this n is the same person as fn in the previous letter. as for abc, i have a guess, but it all seems rather fantastical. al and b appear in some of the earliest boss files, and i always assumed they were on the side of the angels. could they have been double agents working for boss inside the conspiracy? given that it is their work that seems to be driving it on, it seems more likely that the reverse is true. but that means boss was riddled with domestic insurgents from the start. i don’t think this has the same urgency as your discovery of soviet agents at the heart of british intelligence, but it is still rather alarming.\n", + "as is the increasing sophistication of our protagonists’ communications. they are still only relying on substitution ciphers, but their head of security, w, is clearly smart enough to know that this is too weak for serious use, and i suspect that future letters will be protected by something more professional. i wonder if he will push them to think about using polyalphabetic ciphers, or if he will just introduce simple changes like blocking the ciphertext.\n", + "i think it might pay for me to make a trip to london to carry out some enquiries, so i may be off grid for a couple of weeks. let me know if you hear anything useful.\n", + "all the best,\n", + "jodie.\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break(ca)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2618" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "86085f32-1564-4f01-8d58-2786625a743f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "baker KeywordWrapAlphabet.from_last \n", + "\n", + "my dear miss n while the outbreak of the austro prussian war has dismayed many of the chattering\n", + "classes i have found utter delight in the fact that we were able to forecast this development the\n", + "fact that we were able to do so not days or weeks but months in advance is the proof that we have\n", + "been seeking that our methods combined with the power of professor bs new device can deliver the\n", + "knowledge we need to shape our destiny the new statistical tools that you have pioneered can i\n", + "believe assist us in modelling further outbreaks of violence and unrest if you will allow me to mix\n", + "metaphors while we will not always be able to predict the onset of disease we can hope to predict\n", + "its course and thereby profit the device at trinity wharf is now working at full capacity and our\n", + "colleagues tell me that it can compute anything we ask of it given enough time and space in which to\n", + "record the answers of course these practical men did not think to ask how much time any particular\n", + "question might take before we can receive its answer but i think this is a calculation that i can\n", + "leave to you before she was taken from us al wrote extensive notes on the potential of the device\n", + "and i suspect you will find the answers there in in the current context the machine provided with\n", + "diplomatic intelligence by our network of agents in europe took five weeks to calculate the\n", + "likelihood that bismarck would launch his offensive and to use the weather data gathered by ws\n", + "telegraphic network to suggest when the attack would be launched we had little agency in the\n", + "conflict itself but we were able to advise our sympathisers in government and thereby to expand our\n", + "influence our intelligence analysts are now working to determine the likely progression of the\n", + "conflict in the hope of finding new ways to profit from it in mentioning wi realise that i forgot to\n", + "pass on his advice concerning security he has convinced me that our current policy of communicating\n", + "via substitution ciphers really is not sufficient to conceal our intentions as our network expands\n", + "the risk of leaks increase she is working on a new and considerably more fiendish cipher to be used\n", + "for our most delicate secrets and i hope to hear more about his progress on that when i meet him\n", + "next month maxwell will be delivering the baker ian lecture and he is hoping to attend i did wonder\n", + "if m would be amenable to joining our conspiracy but perhaps i should discuss that with the rest of\n", + "the curia i look forward to hearing your deliberations on the efficiency of the device and any\n", + "thoughts you might have on its development best wishes abc\n" + ] + } + ], + "source": [ + "(word_b, wrap_b), score_a = keyword_break(scb, fitness=Ptrigrams)\n", + "print(word_b, wrap_b, '\\n')\n", + "pb = keyword_decipher(scb, word_b, wrap_b)\n", + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2600" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge3.md b/2021/2021-challenge3.md new file mode 100644 index 0000000..563dc81 --- /dev/null +++ b/2021/2021-challenge3.md @@ -0,0 +1,62 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.support.text_prettify import * +``` + +```python Collapsed="false" +challenge_number = 3 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +scb = sanitise(cb) +``` + +```python +(word_a, wrap_a), score_a = keyword_break(ca) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(pa) +``` + +```python +(word_b, wrap_b), score_a = keyword_break(scb, fitness=Ptrigrams) +print(word_b, wrap_b, '\n') +pb = keyword_decipher(scb, word_b, wrap_b) +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.3a.txt b/2021/ciphertext.3a.txt new file mode 100644 index 0000000..1ed8630 --- /dev/null +++ b/2021/ciphertext.3a.txt @@ -0,0 +1,6 @@ +SLVVC, XSLNJW OPV CPYV TMLEK, E OPVUPX CPY SLH WQTNX XEMT STVT EN XST LVGSLTPKPUEWXW LNH EX ALW UPPH XP IT VTMENHTH XSLX EX GLN KTLH WPMTASTVT. EN XSEW GLWT E XSENJ XST ITWX AT GLN SPQT OPV EW XSLX AT AEKK SLZT L NTA IYNGS PO VTGVYEXW XVLENTH LNH VTLHC XP XLGJKT MPVT WTVEPYW GSLKKTNUTW, IYX E SLZT XP LHMEX XSLX E LM UTXXENU MPVT TBGEXTH LIPYX XSEW GLWT, TZTN EO EX EW FYWX L XVLENENU TBTVGEWT. +XST LXXLGSTH MTMP OVPM LIG VTENOPVGTW ASLX AT KTLVNTH OVPM XST KLWX PNT. XST KEUSXSPYWT GPNWQEVLGC WTTMW XP IT L UVPYQ PO ENOKYTNXELK ZEGXPVELNW ASP LVT LEMENU XP YWT XSTEV NTAOPYNH XTGSNPKPUEGLK QVPATWW XP QVPOEX OVPM ALV, OLMENT, QTWXEKTNGT, LNH LNC PXSTV HEWXYVILNGT EN XST OPVGT. E HPN’X KEJT XP FYMQ XP GPNGKYWEPNW, IYX E GLN’X STKQ NPXEGENU XSLX XST ENEXELKW GPENGEHT AEXS QTPQKT PO ENXTVTWX XP IPWW. E GSTGJTH OLVLHLC’W ENXTKKEUTNGT OEKT LNH LW CPY WLC, EX ALW TMQXC. EX EW SLVH XP ITKETZT XSLX L WGETNXEWX PO SEW TMENTNGT SLH TWGLQTH NPXEGT, WP EX WTTMW MPVT KEJTKC XSLX XST VTLK OEKT SLW TEXSTV ITTN HTKTXTH PV WXPVTH WPMTASTVT MPVT WTGYVT. QTVSLQW CPY GLN MLJT TNRYEVETW? I MYWX WYVTKC IT ILIILUT. LKK XST XLKJ EN XST LXXLGSTH KTXXTV EW LIPYX L HTZEGT XSLX WPYNHW KEJT L GPMQYXTV, LNH XSLX APYKH MTLN XSLX LK EW LHL KPZTKLGT, ASP HETH WPMT CTLVW ITOPVT XSEW KTXXTV ALW AVEXXTN. E GLN’X IT WYVT ASP A PV N LVT, IYX MC UYTWW EW XSLX XSEW N EW XST WLMT QTVWPN LW ON EN XST QVTZEPYW KTXXTV. LW OPV LIG, E SLZT L UYTWW, IYX EX LKK WTTMW VLXSTV OLNXLWXEGLK. LK LNH I LQQTLV EN WPMT PO XST TLVKETWX IPWW OEKTW, LNH E LKALCW LWWYMTH XSTC ATVT PN XST WEHT PO XST LNUTKW. GPYKH XSTC SLZT ITTN HPYIKT LUTNXW APVJENU OPV IPWW ENWEHT XST GPNWQEVLGC? UEZTN XSLX EX EW XSTEV APVJ XSLX WTTMW XP IT HVEZENU EX PN, EX WTTMW MPVT KEJTKC XSLX XST VTZTVWT EW XVYT. IYX XSLX MTLNW IPWW ALW VEHHKTH AEXS HPMTWXEG ENWYVUTNXW OVPM XST WXLVX. E HPN’X XSENJ XSEW SLW XST WLMT YVUTNGC LW CPYV HEWGPZTVC PO WPZETX LUTNXW LX XST STLVX PO IVEXEWS ENXTKKEUTNGT, IYX EX EW WXEKK VLXSTV LKLVMENU. +LW EW XST ENGVTLWENU WPQSEWXEGLXEPN PO PYV QVPXLUPNEWXW’ GPMMYNEGLXEPNW. XSTC LVT WXEKK PNKC VTKCENU PN WYIWXEXYXEPN GEQSTVW, IYX XSTEV STLH PO WTGYVEXC, A, EW GKTLVKC WMLVX TNPYUS XP JNPA XSLX XSEW EW XPP ATLJ OPV WTVEPYW YWT, LNH E WYWQTGX XSLX OYXYVT KTXXTVW AEKK IT QVPXTGXTH IC WPMTXSENU MPVT QVPOTWWEPNLK. E APNHTV EO ST AEKK QYWS XSTM XP XSENJ LIPYX YWENU QPKCLKQSLITXEG GEQSTVW, PV EO ST AEKK FYWX ENXVPHYGT WEMQKT GSLNUTW KEJT IKPGJENU XST GEQSTVXTBX. +E XSENJ EX MEUSX QLC OPV MT XP MLJT L XVEQ XP KPNHPN XP GLVVC PYX WPMT TNRYEVETW, WP E MLC IT POO UVEH OPV L GPYQKT PO ATTJW. KTX MT JNPA EO CPY STLV LNCXSENU YWTOYK. +LKK XST ITWX, +FPHET. diff --git a/2021/ciphertext.3b.txt b/2021/ciphertext.3b.txt new file mode 100644 index 0000000..506e98d --- /dev/null +++ b/2021/ciphertext.3b.txt @@ -0,0 +1 @@ +ZPERB HZVII CNUVY RJURD LJAHR BXDSJ URBLI JHDFH LIIVB CNBHU BIEVI ZBPRE ZBCPD SJURK UBJJR HVCTK YBIIR IVUBM RSDLC ELJJR HERYV TUJVC JURSB KJJUB JNRNR HRBAY RJDSD HRKBI JJUVI ERMRY DFZRC JJURS BKJJU BJNRN RHRBA YRJDE DIDCD JEBPI DHNRR XIALJ ZDCJU IVCBE MBCKR VIJUR FHDDS JUBJN RUBMR ARRCI RRXVC TJUBJ DLHZR JUDEI KDZAV CRENV JUJUR FDNRH DSFHD SRIID HAICR NERMV KRKBC ERYVM RHJUR XCDNY RETRN RCRRE JDIUB FRDLH ERIJV CPJUR CRNIJ BJVIJ VKBYJ DDYIJ UBJPD LUBMR FVDCR RHREK BCVAR YVRMR BIIVI JLIVC ZDERY YVCTS LHJUR HDLJA HRBXI DSMVD YRCKR BCELC HRIJV SPDLN VYYBY YDNZR JDZVO ZRJBF UDHIN UVYRN RNVYY CDJBY NBPIA RBAYR JDFHR EVKJJ URDCI RJDSE VIRBI RNRKB CUDFR JDFHR EVKJV JIKDL HIRBC EJURH RAPFH DSVJJ URERM VKRBJ JHVCV JPNUB HSVIC DNNDH XVCTB JSLYY KBFBK VJPBC EDLHK DYYRB TLRIJ RYYZR JUBJV JKBCK DZFLJ RBCPJ UVCTN RBIXD SVJTV MRCRC DLTUJ VZRBC EIFBK RVCNU VKUJD HRKDH EJURB CINRH IDSKD LHIRJ URIRF HBKJV KBYZR CEVEC DJJUV CXJDB IXUDN ZLKUJ VZRBC PFBHJ VKLYB HGLRI JVDCZ VTUJJ BXRAR SDHRN RKBCH RKRVM RVJIB CINRH ALJVJ UVCXJ UVIVI BKBYK LYBJV DCJUB JVKBC YRBMR JDPDL ARSDH RIURN BIJBX RCSHD ZLIBY NHDJR ROJRC IVMRC DJRID CJURF DJRCJ VBYDS JURER MVKRB CEVIL IFRKJ PDLNV YYSVC EJURB CINRH IJURH RVCVC JURKL HHRCJ KDCJR OJJUR ZBKUV CRFHD MVERE NVJUE VFYDZ BJVKV CJRYY VTRCK RAPDL HCRJN DHXDS BTRCJ IVCRL HDFRJ DDXSV MRNRR XIJDK BYKLY BJRJU RYVXR YVUDD EJUBJ AVIZB HKXND LYEYB LCKUU VIDSS RCIVM RBCEJ DLIRJ URNRB JURHE BJBTB JURHR EAPNI JRYRT HBFUV KCRJN DHXJD ILTTR IJNUR CJURB JJBKX NDLYE ARYBL CKURE NRUBE YVJJY RBTRC KPVCJ URKDC SYVKJ VJIRY SALJN RNRHR BAYRJ DBEMV IRDLH IPZFB JUVIR HIVCT DMRHC ZRCJB CEJUR HRAPJ DROFB CEDLH VCSYL RCKRD LHVCJ RYYVT RCKRB CBYPI JIBHR CDNND HXVCT JDERJ RHZVC RJURY VXRYP FHDTH RIIVD CDSJU RKDCS YVKJV CJURU DFRDS SVCEV CTCRN NBPIJ DFHDS VJSHD ZVJVC ZRCJV DCVCT NVHRB YVIRJ UBJVS DHTDJ JDFBI IDCUV IBEMV KRKDC KRHCV CTIRK LHVJP URUBI KDCMV CKREZ RJUBJ DLHKL HHRCJ FDYVK PDSKD ZZLCV KBJVC TMVBI LAIJV JLJVD CKVFU RHIHR BYYPV ICDJI LSSVK VRCJJ DKDCK RBYDL HVCJR CJVDC IBIDL HCRJN DHXRO FBCEI JURHV IXDSY RBXIV CKHRB IRIUR VINDH XVCTD CBCRN BCEKD CIVER HBAYP ZDHRS VRCEV IUKVF URHJD ARLIR ESDHD LHZDI JERYV KBJRI RKHRJ IBCEV UDFRJ DURBH ZDHRB ADLJU VIFHD THRII DCJUB JNURC VZRRJ UVZCR OJZDC JUZBO NRYYN VYYAR ERYVM RHVCT JURAB XRHVB CYRKJ LHRBC EURVI UDFVC TJDBJ JRCEV EVEND CERHV SZNDL YEARB ZRCBA YRJDW DVCVC TDLHK DCIFV HBKPA LJFRH UBFIV IUDLY EEVIK LIIJU BJNVJ UJURH RIJDS JURKL HVBVY DDXSD HNBHE JDURB HVCTP DLHER YVARH BJVDC IDCJU RRSSV KVRCK PDSJU RERMV KRBCE BCPJU DLTUJ IPDLZ VTUJU BMRDC VJIER MRYDF ZRCJA RIJNV IURIB AK diff --git a/2021/plaintext.3a.txt b/2021/plaintext.3a.txt new file mode 100644 index 0000000..38a3f12 --- /dev/null +++ b/2021/plaintext.3a.txt @@ -0,0 +1,6 @@ +harry, thanks for your email, i forgot you had spent time here in the archaeologists and it was good to be reminded that it can lead somewhere. in this case i think the best we can hope for is that we will have a new bunch of recruits trained and ready to tackle more serious challenges, but i have to admit that i am getting more excited about this case, even if it is just a training exercise. +the attached memo from abc reinforces what we learned from the last one. the lighthouse conspiracy seems to be a group of influential victorians who are aiming to use their newfound technological prowess to profit from war, famine, pestilence, and any other disturbance in the force. i don’t like to jump to conclusions, but i can’t help noticing that the initials coincide with people of interest to boss. i checked faraday’s intelligence file and as you say, it was empty. it is hard to believe that a scientist of his eminence had escaped notice, so it seems more likely that the real file has either been deleted or stored somewhere more secure. perhaps you can make enquiries? b must surely be babbage. all the talk in the attached letter is about a device that sounds like a computer, and that would mean that al is ada lovelace, who died some years before this letter was written. i can’t be sure who w or n are, but my guess is that this n is the same person as fn in the previous letter. as for abc, i have a guess, but it all seems rather fantastical. al and b appear in some of the earliest boss files, and i always assumed they were on the side of the angels. could they have been double agents working for boss inside the conspiracy? given that it is their work that seems to be driving it on, it seems more likely that the reverse is true. but that means boss was riddled with domestic insurgents from the start. i don’t think this has the same urgency as your discovery of soviet agents at the heart of british intelligence, but it is still rather alarming. +as is the increasing sophistication of our protagonists’ communications. they are still only relying on substitution ciphers, but their head of security, w, is clearly smart enough to know that this is too weak for serious use, and i suspect that future letters will be protected by something more professional. i wonder if he will push them to think about using polyalphabetic ciphers, or if he will just introduce simple changes like blocking the ciphertext. +i think it might pay for me to make a trip to london to carry out some enquiries, so i may be off grid for a couple of weeks. let me know if you hear anything useful. +all the best, +jodie. diff --git a/2021/plaintext.3b.txt b/2021/plaintext.3b.txt new file mode 100644 index 0000000..ef8b84e --- /dev/null +++ b/2021/plaintext.3b.txt @@ -0,0 +1,27 @@ +my dear miss n while the outbreak of the austro prussian war has dismayed many of the chattering +classes i have found utter delight in the fact that we were able to forecast this development the +fact that we were able to do so not days or weeks but months in advance is the proof that we have +been seeking that our methods combined with the power of professor bs new device can deliver the +knowledge we need to shape our destiny the new statistical tools that you have pioneered can i +believe assist us in modelling further outbreaks of violence and unrest if you will allow me to mix +metaphors while we will not always be able to predict the onset of disease we can hope to predict +its course and thereby profit the device at trinity wharf is now working at full capacity and our +colleagues tell me that it can compute anything we ask of it given enough time and space in which to +record the answers of course these practical men did not think to ask how much time any particular +question might take before we can receive its answer but i think this is a calculation that i can +leave to you before she was taken from us al wrote extensive notes on the potential of the device +and i suspect you will find the answers there in in the current context the machine provided with +diplomatic intelligence by our network of agents in europe took five weeks to calculate the +likelihood that bismarck would launch his offensive and to use the weather data gathered by ws +telegraphic network to suggest when the attack would be launched we had little agency in the +conflict itself but we were able to advise our sympathisers in government and thereby to expand our +influence our intelligence analysts are now working to determine the likely progression of the +conflict in the hope of finding new ways to profit from it in mentioning wi realise that i forgot to +pass on his advice concerning security he has convinced me that our current policy of communicating +via substitution ciphers really is not sufficient to conceal our intentions as our network expands +the risk of leaks increase she is working on a new and considerably more fiendish cipher to be used +for our most delicate secrets and i hope to hear more about his progress on that when i meet him +next month maxwell will be delivering the baker ian lecture and he is hoping to attend i did wonder +if m would be amenable to joining our conspiracy but perhaps i should discuss that with the rest of +the curia i look forward to hearing your deliberations on the efficiency of the device and any +thoughts you might have on its development best wishes abc \ No newline at end of file -- 2.34.1 From 987f633b55c3f07a85a85f5ecc24c482691d87ac Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 4 Nov 2021 16:21:21 +0000 Subject: [PATCH 11/16] Done challenge 4 --- 2021/2021-challenge4.ipynb | 311 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge4.md | 91 +++++++++++ 2021/ciphertext.4a.txt | 1 + 2021/ciphertext.4b.txt | 1 + 2021/plaintext.4a.txt | 35 +++++ 2021/plaintext.4b.txt | 12 ++ 6 files changed, 451 insertions(+) create mode 100644 2021/2021-challenge4.ipynb create mode 100644 2021/2021-challenge4.md create mode 100644 2021/ciphertext.4a.txt create mode 100644 2021/ciphertext.4b.txt create mode 100644 2021/plaintext.4a.txt create mode 100644 2021/plaintext.4b.txt diff --git a/2021/2021-challenge4.ipynb b/2021/2021-challenge4.ipynb new file mode 100644 index 0000000..486fd0a --- /dev/null +++ b/2021/2021-challenge4.ipynb @@ -0,0 +1,311 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.support.text_prettify import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 4\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": 6, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "sca = sanitise(ca)\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "c3cccd86-5e40-4040-8f91-9ca53ac6e909", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "archive KeywordWrapAlphabet.from_last \n", + "\n", + "harry iamba ckisp entmo stoft helas ttwow eeksi nthev aultt rying tounp ackso meoft hemys terys urrou nding theli ghtho useco nspir acycr ewand ithin kimad esome progr esswh ileiw asawa ythet raine estac kledt helet terfr omabc andth eydid agrea tjobt heyar eshap ingup welli think wewil lbegl adoft heirh elpas thisc asepr ogres sesth elibr arian atthe vault wasve ryhel pfula ndwhe nitol dherw hatiw asloo kingf orshe point edmet oanar chive ofvic toria npape rscon cerni ngsci entis tseng ineer sands ocial refor merst hatha dreco rdede arlyb ackgr oundi nvest igati onsin topeo pleof inter estis aypeo plebu tidid notic ethat there wasah eavyb iasto inves tigat ingwo menba ckthe niwas surpr iseda tfirs tihad assum edtha tthey would haveb eenla rgely ignor edbut isupp oseth esere marka blewo menma dethe irpre sence known andpe rhaps thees tabli shmen tfelt threa tened inmos tcase sther earen ostan dards ecuri tyfil esfor these women butwh ereth erewe rethe ywere atbes tthin there allyi ntere sting mater ialwa sinth ehidd enarc hivew herei found repor tsand paper sabou tlove lacen ighti ngale andab cases tabli shmen tfigu resth emsel vesth eysee mtoha vebee nigno redby these crets ervic eandc learl ynotc onsid ereda secur ityth reatb utour bossf orebe arsdi dcarr youti nvest igati onsin tothe iract iviti esand there arecl earsi gnsth atthe ymayh avewo rkedt ogeth erobv iousl ythef actth atthe ywere makin gsuch animp acton socie tywas enoug htoma kesom epeop lener vousa ftera llitw asati meofg reatc hange andco ncern sabou trevo lutio nwere veryr ealon eofth enote sonfi lesug gests thatt hegro wingc ampai gnfor women ssuff ragea ndsoc ialac tivis mmigh thave beent hesta rtofa ninsu rrect ionan ditna medse veral ofour prota gonis tsbut itdid ntsay howth eymig hthav einte ndedt otrig gerth eupri singw hatwe haves eenso faris thatw hatev erthe light house consp iracy wereu ptoth eywen ttoex traor dinar yleng thsto keepi tsecr etand thefa cttha twear eonly nowun cover ingit sugge ststh atitw asmuc hsubt lerth anapl anned upris ingia mstil lstru gglin gwith theid eatha tpeop lewho werep artof thebi rthof bossc ouldh avebe enact ingse cretl yagai nstus butth atisc ertai nlyim plied bysom eofth efile sweha vecra ckeda ndthe attac heddo cumen thasa ddedt omywo rries itwas writt enint heaft ermat hofth ehind enbur gdisa sterb ysome oneit hinky oukne wwell sheha dafan tasti creco rdwor kingd eepun derco veran drepo rting backt owest ernin telli gence agenc iesbu tthet hingt hatca ughtm yeyew astha there sheus edthe coden ameau gusta idont knowi fyoua lread yspot tedit butth elett ering aroun dthee dgeof theli ghtho usest ampre adsad aaddd aaada aadad andsu bstit uting theaa nddfo rdota nddas hspel lsout herco denam eitho ughta tfirs tthat imigh tbere ading toomu chint oitth elett erinh erfil eseem sneve rtoha vebee nbrok ensom eonew roted ouble encry ptedo nthee nvelo peand igues sthat wasen ought odiss uadet heage ncies froms pendi ngmuc htime onitw ithhi ndsig htiti spret tyobv ioust hatac tuall yitha sjust beene ncryp tedon ceand thene ncode dasmo rseco deusi ngthe samec onven tiona equal sdotd equal sdash oncet hatha dbeen untan gledi found itpre ttyea sytob reaka ndiam veryw orrie dabou twhat ifoun dithi nkyou needt otake alook jodie\n", + "\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break(sca)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(ca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harry i am back i spent most of the last two weeks in the vault trying to unpack some of the mystery\n", + "surrounding the lighthouse conspiracy crew and i think i made some progress while i was away the\n", + "trainees tackled the letter from abc and they did a great job they are shaping up well i think we\n", + "will be glad of their help as this case progresses the librarian at the vault was very helpful and\n", + "when it old her what i was looking for she pointed me to an archive of victorian papers concerning\n", + "scientists engineers and social reformers that had recorded early background investigations into\n", + "people of interest i say people but i did notice that there was a heavy bias to investigating women\n", + "back then i was surprised at first i had assumed that they would have been largely ignored but i\n", + "suppose these remarkable women made their presence known and perhaps the establishment felt\n", + "threatened in most cases there are no standard security files for these women but where there were\n", + "they were at best thin the really interesting material was in the hidden archive where i found\n", + "reports and papers about lovelace nightingale and abc as establishment figures themselves they seem\n", + "to have been ignored by the secret service and clearly not considered a security threat but our boss\n", + "forebears did carryout investigations into their activities and there are clear signs that they may\n", + "have worked together obviously the fact that they were making such an impact on society was enough\n", + "to make some people nervous after all it was a time of great change and concerns about revolution\n", + "were very real one of the notes on file suggests that the growing campaign for womens suffrage and\n", + "social activism might have been the start of an insurrection and it named several of our\n", + "protagonists but it didnt say how they might have intended to trigger the uprising what we have seen\n", + "so far is that whatever the lighthouse conspiracy were up to they went to extraordinary lengths to\n", + "keep it secret and the fact that we are only now uncovering it suggests that it was much subtler\n", + "than a planned uprising i am still struggling with the idea that people who were part of the birth\n", + "of boss could have been acting secretly against us but that is certainly implied by some of the\n", + "files we have cracked and the attached document has added to my worries it was written in the\n", + "aftermath of the hindenburg disaster by someone i think you knew well she had a fantastic record\n", + "working deep undercover and reporting back to western intelligence agencies but the thing that\n", + "caught my eye was that here she used the codename augusta i dont know if you already spotted it but\n", + "the lettering around the edge of the lighthouse stamp reads ada add da a ada a a dad and\n", + "substituting the a and d for dot and dash spells out her codename i thought at first that i might be\n", + "reading too much into it the letter in her file seems never to have been broken someone wrote double\n", + "encrypted on the envelope and i guess that was enough to dissuade the agencies from spending much\n", + "time on it with hindsight it is pretty obvious that actually it has just been encrypted once and\n", + "then encoded as morsecode using the same convention a equals dotd equals dash once that had been\n", + "untangled i found it pretty easy to break and i am very worried about what i found i think you need\n", + "to take a look jodie\n" + ] + } + ], + "source": [ + "pa = keyword_decipher(sca, word_a, wrap_a)\n", + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3341" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "77e0eb5c-226d-4197-a687-4a5d725c6af0", + "metadata": {}, + "outputs": [], + "source": [ + "morse_chars = 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'.split()\n", + "# morse_chars" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "0c7912fb-f552-4933-9730-3784197fc729", + "metadata": {}, + "outputs": [], + "source": [ + "morse_codes = '.- / -... / -.-. / -.. / . / ..-. / --. / .... / .. / .--- / -.- / .-.. / -- / -. / --- / .--. / --.- / .-. / ... / - / ..- / ...- / .-- / -..- / -.-- / --.. / ----- / .---- / ..--- / ...-- / ....- / ..... / -.... / --... / ---.. / ----.'.split(' / ')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "ae62967b-0c5d-4e14-adf2-8cad03ed6970", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['.-', '-...', '-.-.']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "char_to_morse = {l: c for l, c in zip(morse_chars, morse_codes)}\n", + "morse_to_char = {c: l for l, c in zip(morse_chars, morse_codes)}\n", + "[char_to_morse[l] for l in 'abc']" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "d5c24bcb-fda8-40f0-89ba-166380046fc9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'otjsjseifzotyijsfeajzmoafzkfacjtntjtegsaneyeceggaftwqifzoytygcaweayhczxbweptjqayhotjsjsajjsefetgaifzotyiftgvjsajzkfxtggtzyotwwlekycznefehlqzyezmjsebafjtegjzjseczymwtcjtsaneleeyalwejzhftbmeehtyjewwtieycejzjseoegjefyawwtegntajsetfaieyjsaffqayhagmafagtcayjewwsefexatygtiyzfayjzmzkfjfkebkfbzgeyzyejseweggjseftgvfexatygstiszmzyezflzjsgthegacdktftyijsegecfejjzajzxtcoeabzygeafwqayhoeotwwyeehjzacjmagjtmoeafejzbfeneyjjstgjsewzggzmjsestyheylkfibfegeyjehamalkwzkgzbbzfjkytjqayhtkgehtjjzxavegkfejsajjseawwtegkyhefgjzzhosajjseyartgcteyjtgjgoefeozfvtyizytsanejftehyzjjzbfznthesaffqotjsjzzxkcstymzfxajtzyajjstggjaiegtycetjtgcfkctawjzzkfxtggtzyjsajoexatyjatyjselawaycezmkycefjatyjqtjtgyzjajawwcweafoszxtisjotyjseykcweafafxgfacelkjzkfepbefteycezmjsexzyjsgayhqeafgweahtyikbjzjseifeajoafgkiiegjgjsajjsefaceotwwsanetjgzoyxzxeyjkxayhtjotwwjaveczygthefalweemmzfjlqawwzmkgtmoeszbejzhtfecjtjjzzkfahnayjaieakikgja'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "morse_table = ''.maketrans('AD', '.-')\n", + "cb_dd = cb.translate(morse_table)\n", + "cb_words = cb_dd.split(' / ')\n", + "cb_letters = cat(cat(morse_to_char[l] for l in w.split()) for w in cb_words)\n", + "cb_letters" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "86085f32-1564-4f01-8d58-2786625a743f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "alchemist KeywordWrapAlphabet.from_last \n", + "\n", + "with the growing threat of war our activities have necessarily grown in scale and complexity and\n", + "with that there is a growing risk that our mission will be uncovered by one of the parties to the\n", + "conflict i have be enable to drip feed intelligence to the western allies via their agent harry and\n", + "as far as i can tell he remains ignorant of our true purpose nonetheless the risk remains high of\n", + "one or both sides acquiring the secret to atomic weapons early and we will need to act fast if we\n", + "are to prevent this the loss of the hindenburg presented a fabulous opportunity and i used it to\n", + "make sure that the allies understood what the nazi scientists were working on i have tried not to\n", + "provide harry with too much information at this stage since it is crucial to our mission that we\n", + "maintain the balance of uncertainty it is not at all clear who might win the nuclear arms race but\n", + "our experience of the months and years leading up to the great war suggests that the race will have\n", + "its own momentum and it will take considerable effort by all of us if we hope to direct it to our\n", + "advantage augusta\n" + ] + } + ], + "source": [ + "(word_b, wrap_b), score_a = keyword_break(cb_letters, fitness=Ptrigrams)\n", + "print(word_b, wrap_b, '\\n')\n", + "pb = keyword_decipher(cb_letters, word_b, wrap_b)\n", + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1097" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge4.md b/2021/2021-challenge4.md new file mode 100644 index 0000000..c455b6c --- /dev/null +++ b/2021/2021-challenge4.md @@ -0,0 +1,91 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.support.text_prettify import * +``` + +```python Collapsed="false" +challenge_number = 4 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +scb = sanitise(cb) +``` + +```python +(word_a, wrap_a), score_a = keyword_break(sca) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(ca, word_a, wrap_a) +print(pa) +``` + +```python +pa = keyword_decipher(sca, word_a, wrap_a) +print(prettify(pa)) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +morse_chars = 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'.split() +# morse_chars +``` + +```python +morse_codes = '.- / -... / -.-. / -.. / . / ..-. / --. / .... / .. / .--- / -.- / .-.. / -- / -. / --- / .--. / --.- / .-. / ... / - / ..- / ...- / .-- / -..- / -.-- / --.. / ----- / .---- / ..--- / ...-- / ....- / ..... / -.... / --... / ---.. / ----.'.split(' / ') +``` + +```python +char_to_morse = {l: c for l, c in zip(morse_chars, morse_codes)} +morse_to_char = {c: l for l, c in zip(morse_chars, morse_codes)} +[char_to_morse[l] for l in 'abc'] +``` + +```python +morse_table = ''.maketrans('AD', '.-') +cb_dd = cb.translate(morse_table) +cb_words = cb_dd.split(' / ') +cb_letters = cat(cat(morse_to_char[l] for l in w.split()) for w in cb_words) +cb_letters +``` + +```python +(word_b, wrap_b), score_a = keyword_break(cb_letters, fitness=Ptrigrams) +print(word_b, wrap_b, '\n') +pb = keyword_decipher(cb_letters, word_b, wrap_b) +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.4a.txt b/2021/ciphertext.4a.txt new file mode 100644 index 0000000..0e10b4e --- /dev/null +++ b/2021/ciphertext.4a.txt @@ -0,0 +1 @@ +FASSB GAMRA CKGTP INUMO TUOVU FILAT UUYOY IIKTG NUFIX AWLUU SBGNE UOWNP ACKTO MIOVU FIMBT UISBT WSSOW NHGNE UFILG EFUFO WTICO NTPGS ACBCS IYANH GUFGN KGMAH ITOMI PSOES ITTYF GLIGY ATAYA BUFIU SAGNI ITUAC KLIHU FILIU UISVS OMARC ANHUF IBHGH AESIA UJORU FIBAS ITFAP GNEWP YILLG UFGNK YIYGL LRIEL AHOVU FIGSF ILPAT UFGTC ATIPS OESIT TITUF ILGRS ASGAN AUUFI XAWLU YATXI SBFIL PVWLA NHYFI NGUOL HFISY FAUGY ATLOO KGNEV OSTFI POGNU IHMIU OANAS CFGXI OVXGC UOSGA NPAPI STCON CISNG NETCG INUGT UTINE GNIIS TANHT OCGAL SIVOS MISTU FAUFA HSICO SHIHI ASLBR ACKES OWNHG NXITU GEAUG ONTGN UOPIO PLIOV GNUIS ITUGT ABPIO PLIRW UGHGH NOUGC IUFAU UFISI YATAF IAXBR GATUO GNXIT UGEAU GNEYO MINRA CKUFI NGYAT TWSPS GTIHA UVGST UGFAH ATTWM IHUFA UUFIB YOWLH FAXIR IINLA SEILB GENOS IHRWU GTWPP OTIUF ITISI MASKA RLIYO MINMA HIUFI GSPSI TINCI KNOYN ANHPI SFAPT UFIIT UARLG TFMIN UVILU UFSIA UINIH GNMOT UCATI TUFIS IASIN OTUAN HASHT ICWSG UBVGL ITVOS UFITI YOMIN RWUYF ISIUF ISIYI SIUFI BYISI AURIT UUFGN UFISI ALLBG NUISI TUGNE MAUIS GALYA TGNUF IFGHH INASC FGXIY FISIG VOWNH SIPOS UTANH PAPIS TAROW ULOXI LACIN GEFUG NEALI ANHAR CATIT UARLG TFMIN UVGEW SITUF IMTIL XITUF IBTII MUOFA XIRII NGENO SIHRB UFITI CSIUT ISXGC IANHC LIASL BNOUC ONTGH ISIHA TICWS GUBUF SIAUR WUOWS ROTTV OSIRI ASTHG HCASS BOWUG NXITU GEAUG ONTGN UOUFI GSACU GXGUG ITANH UFISI ASICL IASTG ENTUF AUUFI BMABF AXIYO SKIHU OEIUF ISORX GOWTL BUFIV ACUUF AUUFI BYISI MAKGN ETWCF ANGMP ACUON TOCGI UBYAT INOWE FUOMA KITOM IPIOP LINIS XOWTA VUISA LLGUY ATAUG MIOVE SIAUC FANEI ANHCO NCISN TAROW USIXO LWUGO NYISI XISBS IALON IOVUF INOUI TONVG LITWE EITUT UFAUU FIESO YGNEC AMPAG ENVOS YOMIN TTWVV SAEIA NHTOC GALAC UGXGT MMGEF UFAXI RIINU FITUA SUOVA NGNTW SSICU GONAN HGUNA MIHTI XISAL OVOWS PSOUA EONGT UTRWU GUHGH NUTAB FOYUF IBMGE FUFAX IGNUI NHIHU OUSGE EISUF IWPSG TGNEY FAUYI FAXIT IINTO VASGT UFAUY FAUIX ISUFI LGEFU FOWTI CONTP GSACB YISIW PUOUF IBYIN UUOIZ USAOS HGNAS BLINE UFTUO KIIPG UTICS IUANH UFIVA CUUFA UYIAS IONLB NOYWN COXIS GNEGU TWEEI TUTUF AUGUY ATMWC FTWRU LISUF ANAPL ANNIH WPSGT GNEGA MTUGL LTUSW EELGN EYGUF UFIGH IAUFA UPIOP LIYFO YISIP ASUOV UFIRG SUFOV ROTTC OWLHF AXIRI INACU GNETI CSIUL BAEAG NTUWT RWUUF AUGTC ISUAG NLBGM PLGIH RBTOM IOVUF IVGLI TYIFA XICSA CKIHA NHUFI AUUAC FIHHO CWMIN UFATA HHIHU OMBYO SSGIT GUYAT YSGUU INGNU FIAVU ISMAU FOVUF IFGNH INRWS EHGTA TUISR BTOMI ONIGU FGNKB OWKNI YYILL TFIFA HAVAN UATUG CSICO SHYOS KGNEH IIPWN HISCO XISAN HSIPO SUGNE RACKU OYITU ISNGN UILLG EINCI AEINC GITRW UUFIU FGNEU FAUCA WEFUM BIBIY ATUFA UFISI TFIWT IHUFI COHIN AMIAW EWTUA GHONU KNOYG VBOWA LSIAH BTPOU UIHGU RWUUF ILIUU ISGNE ASOWN HUFII HEIOV UFILG EFUFO WTITU AMPSI AHTAH AAHHH AAAHA AAHAH ANHTW RTUGU WUGNE UFIAA NHHVO SHOUA NHHAT FTPIL LTOWU FISCO HINAM IGUFO WEFUA UVGST UUFAU GMGEF URISI AHGNE UOOMW CFGNU OGUUF ILIUU ISGNF ISVGL ITIIM TNIXI SUOFA XIRII NRSOK INTOM IONIY SOUIH OWRLI INCSB PUIHO NUFII NXILO PIANH GEWIT TUFAU YATIN OWEFU OHGTT WAHIU FIAEI NCGIT VSOMT PINHG NEMWC FUGMI ONGUY GUFFG NHTGE FUGUG TPSIU UBORX GOWTU FAUAC UWALL BGUFA TJWTU RIINI NCSBP UIHON CIANH UFINI NCOHI HATMO STICO HIWTG NEUFI TAMIC ONXIN UGONA IQWAL THOUH IQWAL THATF ONCIU FAUFA HRIIN WNUAN ELIHG VOWNH GUPSI UUBIA TBUOR SIAKA NHGAM XISBY OSSGI HAROW UYFAU GVOWN HGUFG NKBOW NIIHU OUAKI ALOOK JOHGI diff --git a/2021/ciphertext.4b.txt b/2021/ciphertext.4b.txt new file mode 100644 index 0000000..524fa94 --- /dev/null +++ b/2021/ciphertext.4b.txt @@ -0,0 +1 @@ +DDD D ADDD AAA ADDD / AAA A AA AADA DDAA / DDD D DADD AA ADDD / AAA AADA A AD ADDD / DDAA DD DDD AD AADA / DDAA DAD AADA AD DADA / ADDD D DA D ADDD / D A DDA AAA AD / DA A DADD A DADA / A DDA DDA AD AADA / D ADD DDAD AA AADA / DDAA DDD DADD D DADD / DDA DADA AD ADD A / AD DADD AAAA DADA DDAA / DAAD DAAA ADD A ADDA / D ADDD DDAD AD DADD / AAAA DDD D ADDD AAA / ADDD AAA AD ADDD ADDD / AAA A AADA A D / DDA AD AA AADA DDAA / DDD D DADD AA AADA / D DDA AAAD ADDD AAA / AD ADDD DDAA DAD AADA / DAAD D DDA DDA D / DDAA DADD DDD D ADD / ADD ADAA A DAD DADD / DADA DDAA DA A AADA / A AAAA ADAA DDAD DDAA / DADD A DDAA DD ADDD / AAA A DAAA AD AADA / ADDD D A DDA ADDD / DDAA ADDD AAA A DADA / DDAA DADD DD ADD D / DADA ADDD D AAA AD / DA A ADAA A A / DADD AD ADAA ADD A / ADDD DDAA AAAA AADA D / DAAA DD A A AAAA / D DADD ADDD A ADD / ADD D AA A DADD / DADA A ADDD DDAA ADDD / AAA A DDD A DDA / ADDD A AADA DADD AD / ADD ADD D A DDA / DA D AD ADDD AAA / A D AADA AD AA / A DADD ADDD AAA AD / AADA AADA DDAD AD DADD / AAAA AD DDA DD AD / AADA AD DDA D DADA / AD DADD ADDD A ADD / ADD AAA A AADA A / DAAD AD D DADD DDA / D AA DADD DDAA AADA / AD DADD ADDD DDAA DD / DDAA DAD AADA ADDD AADA / DAD A DAAA DAD AADA / DAAA DDAA DDA A DADD / DDAA DADD A ADDD AAA / A ADD A DDA DDA / ADDD AAA A AADA D / DDA AAAD AADA A DAAD / AD D DADD DDA AAA / D AA AAA DDAA DD / DDAA DADD A DDAA AADA / ADAA DDAA ADDD AAA DDA / D AAAA A DDA AD / DADA DAA DAD D AADA / D DADD AA ADDD AAA / A DDA A DADA AADA / A ADDD ADDD DDAA AD / ADDD DDAA DAAD D DADA / DDD A AD DAAA DDAA / DADD DDA A AD AADA / ADD DDAD AD DADD AAAA / DDD A DDD D ADD / ADD DADD A A AAAA / ADDD DDAA AD DADA ADDD / DD AD DDA ADDD D / DD DDD A AD AADA / A ADDD DDAA DAAA AADA / A DA A DADD ADDD / ADDD AAA D DDA ADDD / AAA A ADD DDAA DDA / DDA DDAA DD ADDD AAA / A AAA D DADD AAAA / A DADD ADAA DAD AADA / AA DAAA AADA A DDA / A DADD ADDD A AAAA / AD DD AD ADAA DAD / ADD DDAA DAD DDA DDAA / DAAA DAAA DDAA AADA ADDD / DAD DADD D ADDD DDAD / AD DADD AAAA D DAD / DDA A AAAA D ADDD / ADDD DDAA DAAD AD AAAD / A DDA DAD AADA A / ADDD AAA AD ADDD ADDD / AAA A AD ADD ADD / D A DDA DAD DADD / AAAA A AADA DDA ADDD / DDAA DDAA AAAA DDD AAA / AD ADDD ADDD AAA A / DADD AD ADA D DDA / DADA D A DADD ADDD / D DDA ADDD DDA DDD / A AADA A DDD DDAA / AADA AAAD D DADD AA / DDAA DADD D AAA AD / DA A ADDD AADA D / A AAAA DADD DDAA ADDD / ADDD DDAA DAAA AADA DDAA / DA D AAAA A AAA / AD AADA AADA DDAD DDD / D ADDD AAA ADDD DDAA / DDAA DAAD DAD DADA AAA / D DADD DD DDAA AADA / DAAD AD ADDD D DDAA / DADD AD ADDD ADDD AAA / D DDA DDA ADDD AD / AA A DDA D DADD / DADA A D ADDD D / DDA DADA AADA DAD DADA / D AD ADD ADDD DDAA / DDAA DAD AADA DAAD D / DDA DDA D DDAA DADD / ADDD AAA AD ADDD DDD / A DAAD AD D DADD / ADDD AD D DADD ADDD / AAA A ADAA AD ADD / AD DADD DADA A DDAA / DD DAD DADD DADA A / AADA ADDD AD D DADD / ADDD DDAD D ADDD D / DDA DADD DDAA ADDD AD / ADDD AD ADD ADD DADA / ADD A AD AADA DDD / AAA DDAA DAAD D AA / AAA ADDD DDD D DADD / ADDD AAA A DADD DAD / DADA ADD A AD AADA / AD AADA DAAD DDA AADA / AD DADA A ADAA DAD / ADDD DDAA DAD AADA A / ADDA DAAA A AADA D / A DADD DADA A DDAA / DD ADDD AAA A DAAD / DDAA DADD ADDD AAA DDA / AD DADD AAAA DDAD A / AD AADA DDA ADD A / AD AAAA D DADD AA / DAD DAAA ADDD DDAA ADDD / AAA A AA AADA A / AD ADDD DDD AD AADA / DDA DAD AA AA A / DDA ADDD DDA ADDD AAA / AD ADDD ADDD AAA A / AADA AD DADA A DDD / D ADD ADD AAA AD / DA A D ADDD DDA / DDAA DDD DADD DAAD DDAA / DAAD A DADD ADDD DAD / DAAD AD DADD AAAA D / ADDD DDD D ADD ADD / ADDD AD AAAD A DADA / DDAA DADD DDA D AAAA / A AADA AD ADAA ADD / A A DD DD DDAA / AADA ADDD ADAA DDAD AD / ADD ADD DDAA DD DAD / DDA D DD DDD A / AAA DDAA DAAA A ADDD / DDAA AAAA D AADA A / DADA ADDD D ADDD ADDD / DDAA DDAA DAD AADA AD / AAAA DA AD DADD ADDD / AD AA A AD DAD / AA DAD DDA ADDD AD diff --git a/2021/plaintext.4a.txt b/2021/plaintext.4a.txt new file mode 100644 index 0000000..39abee1 --- /dev/null +++ b/2021/plaintext.4a.txt @@ -0,0 +1,35 @@ +harry i am back i spent most of the last two weeks in the vault trying to unpack some of the mystery +surrounding the lighthouse conspiracy crew and i think i made some progress while i was away the +trainees tackled the letter from abc and they did a great job they are shaping up well i think we +will be glad of their help as this case progresses the librarian at the vault was very helpful and +when it old her what i was looking for she pointed me to an archive of victorian papers concerning +scientists engineers and social reformers that had recorded early background investigations into +people of interest i say people but i did notice that there was a heavy bias to investigating women +back then i was surprised at first i had assumed that they would have been largely ignored but i +suppose these remarkable women made their presence known and perhaps the establishment felt +threatened in most cases there are no standard security files for these women but where there were +they were at best thin the really interesting material was in the hidden archive where i found +reports and papers about lovelace nightingale and abc as establishment figures themselves they seem +to have been ignored by the secret service and clearly not considered a security threat but our boss +forebears did carryout investigations into their activities and there are clear signs that they may +have worked together obviously the fact that they were making such an impact on society was enough +to make some people nervous after all it was a time of great change and concerns about revolution +were very real one of the notes on file suggests that the growing campaign for womens suffrage and +social activism might have been the start of an insurrection and it named several of our +protagonists but it didnt say how they might have intended to trigger the uprising what we have seen +so far is that whatever the lighthouse conspiracy were up to they went to extraordinary lengths to +keep it secret and the fact that we are only now uncovering it suggests that it was much subtler +than a planned uprising i am still struggling with the idea that people who were part of the birth +of boss could have been acting secretly against us but that is certainly implied by some of the +files we have cracked and the attached document has added to my worries it was written in the +aftermath of the hindenburg disaster by someone i think you knew well she had a fantastic record +working deep undercover and reporting back to western intelligence agencies but the thing that +caught my eye was that here she used the codename augusta i dont know if you already spotted it but +the lettering around the edge of the lighthouse stamp reads ada add da a ada a a dad and +substituting the a and d for dot and dash spells out her codename i thought at first that i might be +reading too much into it the letter in her file seems never to have been broken someone wrote double +encrypted on the envelope and i guess that was enough to dissuade the agencies from spending much +time on it with hindsight it is pretty obvious that actually it has just been encrypted once and +then encoded as morsecode using the same convention a equals dotd equals dash once that had been +untangled i found it pretty easy to break and i am very worried about what i found i think you need +to take a look jodie \ No newline at end of file diff --git a/2021/plaintext.4b.txt b/2021/plaintext.4b.txt new file mode 100644 index 0000000..5cd0a9c --- /dev/null +++ b/2021/plaintext.4b.txt @@ -0,0 +1,12 @@ +with the growing threat of war our activities have necessarily grown in scale and complexity and +with that there is a growing risk that our mission will be uncovered by one of the parties to the +conflict i have be enable to drip feed intelligence to the western allies via their agent harry and +as far as i can tell he remains ignorant of our true purpose nonetheless the risk remains high of +one or both sides acquiring the secret to atomic weapons early and we will need to act fast if we +are to prevent this the loss of the hindenburg presented a fabulous opportunity and i used it to +make sure that the allies understood what the nazi scientists were working on i have tried not to +provide harry with too much information at this stage since it is crucial to our mission that we +maintain the balance of uncertainty it is not at all clear who might win the nuclear arms race but +our experience of the months and years leading up to the great war suggests that the race will have +its own momentum and it will take considerable effort by all of us if we hope to direct it to our +advantage augusta \ No newline at end of file -- 2.34.1 From 72331e8675e2ba8e51c112287730bc43955613c4 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 12 Nov 2021 15:07:12 +0000 Subject: [PATCH 12/16] Done challenge 5 --- 2021/2021-challenge5.ipynb | 503 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge5.md | 143 +++++++++++ 2021/ciphertext.5a.txt | 1 + 2021/ciphertext.5b.txt | 1 + 2021/plaintext.5a.txt | 24 ++ 2021/plaintext.5b.txt | 16 ++ 6 files changed, 688 insertions(+) create mode 100644 2021/2021-challenge5.ipynb create mode 100644 2021/2021-challenge5.md create mode 100644 2021/ciphertext.5a.txt create mode 100644 2021/ciphertext.5b.txt create mode 100644 2021/plaintext.5a.txt create mode 100644 2021/plaintext.5b.txt diff --git a/2021/2021-challenge5.ipynb b/2021/2021-challenge5.ipynb new file mode 100644 index 0000000..d6bf264 --- /dev/null +++ b/2021/2021-challenge5.ipynb @@ -0,0 +1,503 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 27, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.railfence import *\n", + "from szyfrow.support.text_prettify import *\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import collections\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 5\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": 5, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "sca = sanitise(ca)\n", + "rsca = cat(reversed(sca))\n", + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'j': 2,\n", + " 'n': 145,\n", + " 'o': 133,\n", + " 'c': 61,\n", + " 't': 202,\n", + " 'h': 106,\n", + " 'l': 74,\n", + " 'b': 25,\n", + " 'i': 152,\n", + " 'w': 44,\n", + " 'e': 241,\n", + " 'v': 20,\n", + " 's': 101,\n", + " 'r': 94,\n", + " 'a': 162,\n", + " 'm': 36,\n", + " 'u': 60,\n", + " 'g': 48,\n", + " 'y': 35,\n", + " 'd': 67,\n", + " 'f': 35,\n", + " 'k': 17,\n", + " 'p': 18,\n", + " 'x': 4,\n", + " 'z': 1})" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sca_counts = collections.Counter(sca)\n", + "sca_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD5CAYAAADcDXXiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAASZUlEQVR4nO3df7DldV3H8ecLMDQgW2KhDYhLzmZiFskVbaSJsoRyCp3ElhpCM1cNin4DTYU5beGUNmpBoaDkL9xUgkaTcNMBCsQFkV8L48bPlRXWstgaRXZ998f57nC6nHvOuefeu3vvZ5+PmTPnfD/n+/l+3/d7z32dz/n+ODdVhSSpLfvs6QIkSQvPcJekBhnuktQgw12SGmS4S1KDDHdJatDIcE9yZJJPJ9mU5M4kZ3ftb0rypSS3dref7utzXpLNSe5JctJi/gCSpKfKqPPck6wCVlXVLUkOAm4GXg68CvifqvqLGfMfA3wIOB74LuBTwPdW1c7Z1nHIIYfU1NTUPH4MSdr73HzzzV+pqpWDnttvVOeq2gps7R5vT7IJOHxIl1OAy6vqceC+JJvpBf0Ns3WYmppi48aNo0qRJPVJ8sBsz81pn3uSKeCHgM92TWcluS3JpUlWdG2HAw/1ddvCgDeDJGuTbEyycdu2bXMpQ5I0wtjhnuRA4KPAb1TVY8BFwLOAY+mN7N+6a9YB3Z+y76eqLq6q6aqaXrly4KcKSdKExgr3JE+jF+wfqKqPAVTVI1W1s6q+CbyL3q4X6I3Uj+zrfgTw8MKVLEkaZZyzZQJcAmyqqrf1ta/qm+0VwB3d46uANUn2T3I0sBq4aeFKliSNMvKAKvBi4HTg9iS3dm2/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+eUifgXWO8Rp8Pk/+rsZ9LS3p39kkZvxMO4BHutHrsD4XAJfXkBMFRvQ/EHgN8Dv0TnDYf8i80zP/jpKcXlWzHutI8mbgkkG/jyTPWdQMWOrhLu0JSW6vqueNnlPLUXcWy4/QG70/wJNnzvzLHi1sAS3V3TLSnnbjoFPf1IxnAG+jd3rw0E8Hy5Ujd2mAJJuAZ9E702PJHH+QxmW4SwNMuv9cWioMd0lq0JK8QlWSND+GuyQ1yHCXpAYZ7pLUoP8DQ2uGuOCXRZEAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(sca_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "61ce2102-294e-4b1a-842c-1607aa7a4b05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 \n", + "\n", + "jodieicanseewhyyouareconcernedbutifindithardtobelievethatagathacouldhavebeenpartofaconspiracyshewasafaithfulcolleagueinallthetimeiworkedwithherandnooneeversuggestedotherwiseofcoursewerantheusualspotchecksfromtimetotimebutnothingunusualwasfoundhavingsaidthatthemessageyoufoundinthearchiveisreallyworryingmyfirstthoughtwasthatshemighthavebeenactingasadoubleagenttryingtodestabilisenaziintelligencebutthatdoesntfitwiththetextitiscrucialtoourmissionthatwemaintainthebalanceofuncertaintyanddirectittoouradvantagemakeitlooklikeshehaddefinitelyhadanotheragendaitrawledthroughmyownrecordstoseeifanyoneelseagathaandiworkedwithmighthavebeeninvolvedihatetosayitbuttheonlypersonofinterestatthemomentischarlieweworkedtogetheronthekohinoortwinscaseandagathawashergreatauntnotthattreacheryisagenetictraitbutinvettingcirclesitcanbetreatedlikeitisinheritedsoisupposeweoughttotakethatseriouslyespeciallysinceshebecameprettyseniorinamericanintelligenceicheckedourcurrentcasefilesandalthoughsheisretiredshestillactsasgovernmentliaisonsheisinlondonatthemomentinthenewembassybuildingwhichwillmakeitdifficulttogetholdofherifshewantstostayhiddenwecantaffordtoupsetouruscousinsandifwearewrongaboutherwemightalsopoisonthewellwhenitcomestointelligenceexchangetheyhaventforgivenusforphilbyandmacleanyetsoicanimaginehowtheywouldreactifitturnsoutthatoneofourownisadoubleagentandhasinfiltratedtheirinnersanctumisentoneoftheelvestotakealookatherapartmentinnewjerseyitwasprettycleanasyoucanimaginebuttheywereabletoliftthefollowingextractitwashardtoreadandevenhardertodeciphersincesheusedavigenereencryptionbutoneincriminatingfeaturestandsoutevenwithoutadecryptsheusedtheadmorseencodingontopofthevigenerecipheriamnotsurewhatweshoulddonextcouldyougettheteamtotakealookatthefilemaybethisisallabigcoincidenceoramisunderstandingifnotthenwemayhavetotelllondonandwashingtonandiamreallynotlookingforwardtothatallthebestharry\n" + ] + } + ], + "source": [ + "key_a, score_a = railfence_break(sca, fitness=Ptrigrams)\n", + "print(key_a, '\\n')\n", + "pa = railfence_decipher(sca, key_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "605792ee-8bbf-44da-b33f-6bd2321f449e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0, 1, 2, 3) False True \n", + "\n", + "sichacnerlliitniyicaiemanorianesletthpemhbecnhseesinrllacpecaeylhioulestkethtatohghtdoewnpossusiredsiirersinhtieodlietaeebethactdleswricstinuevntbutniarnticnnegiyishehcetretahtetnoeuatsgrerehsohawtagabeanhacsgtwiooonckohahtnehernegorkedlowesliefahcsntismometthttsehnteafonsersfylntthetubtesayetetidihivloeninyebefthargimhwitaekrediwiaahtagaesleiyonhafihoseosdrfrecswoyoughdrhtawleirtisendfarelnottdahdtellnifgaddyehseliknooltkeinmegoantedarstooiitcrdirhnaylainireceofudcnaeebaetnirintimewrthaeoisyrmisootrciakrcsutitpetetthtiwtiesntnodtctthtbectigeeletrziitnesnbilrtsetgtosiyrrenteaeltdoursagrctieneeaaveithgphemttahowasehguetthhrifdngmnyrrelywnaertveinhcrotheaidngufoayegiesshehtkthaaiasvvinthdndsfotwlaenushgnianotnubeuotiuemixromiskcetchupsllusuahtnawernsrugofcasiwathehdetsggetsresneeiondleraihtinkedoowimtimdhtlainaaugauolltluftaitfasaosheecarenspecafoartuneeoavehdlurhaceagaethacveifobeydraoditpifihdbutnreecontraunhyyeeeseicawidoeyrrthahebetlltotahldtoeawrnngfakoonnottllaeamrndnaagtosihsnndwcnodslloyetohaveayamaenwgttocgiflidnarstodnupamigoecpidednioobigellayisiotebeematifefattmooloakepotmeeteettenyoucluorextnodddhouiewtgewhfustoamnerehbecinenenevietfoyntongnirncoaesraadmehtdoeuststpnecreatunithtnevuoutodnaoresstaeiinguaniocriiienebutmoithcryeeerngentvadeeuslsecersihhpitodesredenhabvedradaarotsharpawtfactntxetwinwllohtheefililetkaerceywlttubinetamimucadysaeleaiyttesprcwtihrserjweutinaemtaapacehteookgaekntotnevlytheaoencentiimusancarentiriehtdorathlifkasirdnaigengelbiadotinwaouraoenthatatuoaurndtifnactirdloywothtwwnehsgamecanrostoanyolcaiandablivorpvsunhgivoofttaveeyehengeohcxmncedgilantehotsycomeineellwtwehasonuopoetaltgimnerwltuoangatrweswealidniinshuocfuruatesntounrofintadcewtddebhyantosbtnaishetireodofyohtotogslucaiffutiealmatiwhgwhiunidubuihssamwemtnehetinaemoatheoanorlonsisivnshnsiawntlemnrlgoveasthllawtseiedsoitebeisoshgttholadnhlestfescntcorrunourjekc \n" + ] + } + ], + "source": [ + "(word_a, fill_a, empty_a), score_a = column_transposition_break(rsca, fitness=Ptrigrams)\n", + "print(word_a, fill_a, empty_a, '\\n')\n", + "pa = column_transposition_decipher(rsca, word_a, fillcolumnwise=fill_a, emptycolumnwise=empty_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "c3cccd86-5e40-4040-8f91-9ca53ac6e909", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a KeywordWrapAlphabet.from_a \n", + "\n", + "jnocthltoboiwhelewnvsroaaetmhuugtauasoyotibnbtdinnafhilstalnteuateeyhadmoeetohvvaiooreswtoindaataatigirkhoetasicaynngecaaurhceiedmtblckiehwtnfpsarbestheletnehmeiouisooutnentoeaarnyennbeofgidnrcneepomfteoyeodpgpoalcgaahyscnsanetnanelothroasyuneuitaeiaacueetfpreatflaalmidiadeeetewcurnulhcmiietisaonnsatsgonerirwrmfhushmgeeigultroelsitechttitetsatisawtiaaucnyrcortgilksdflhtediethycreineahwrtmaenohtytensneehmiceedornhnisnawsetotecsgcrtnncstteienesiswtohtulcanecmtsiaaiiehcrucssnogseseatvrlahinoeonhmaidihaefcgtfeeasaewafusucsnaeaowmlonhwemselexehetvnpidaytnmhwoltfnotnrwobnaiftdincutneltkktatneeirtaaaieuwrtleonettrtadadeiicsdnryttniigesatvhurpsdmroiooieihnthtudtoueemelteabiagoeciutnfowmeoodwsoaratofrohteardceyaorbfirbehgalverasahsiulgntiwetrnergehifretssckomtbonulfdiahhsefdhceeyrgitgaaehvetaoenytsieiegetdnthticiomihennbnfeiaitoaneeoihdieaorntlhgoedsfolgaikiihbilieabhlrotstothiwegetoowcagahranhrhieiauviiecealiirdsoehttsoyeliseetermcnlnckurteedhhitdslsontissonhmieesuihwmifuohorhnoydetooerondewguriapoelnotticcgevfiurlncnsaaetwdciruaeundlensiatrenmnehvoeohpmiwstptescmntyeeihlixcwaodehedpseuaeeriuernnaenuettctutdscntfvncemswwodxuotttkotfmesliidemnsditnavtlodhtnmloogwtalbhyiiehrcndiddovtahdanacncsaalouihtokheonsgdtsoswhuptsreoungnwshviteeyuithvalynrthwthtancsdaeigtbnzlibtoswtetrcorotmitecoranditdamkoleantdnaerwruwrsoaysaadewgtenvdtsutyefnttmnalokehhkotaeahegutateyntibetrlabtdtsieupogaeeieplshbpenoeitlcieornflatseietlagmnsnilatetnwsbnwiltiltodistthdcnrttuuiiwrntegtoswlicongnhnyaogsobalaocgnhyratuthooiaegdalrhiraieotetaoeaetjrwsylyuaitealftlwtaahravnrohrsevgecobicaitrdoniaesehaengnteeeraueehoelyteoaoaietilbnioadrigteyaelnnigdalnknadtleteweentethpoyfceerhouoeeeofttuaadmonilistshaagnaalueixuunahetdtvakhiagaontnendheeotpiaerrterstrntrettcneitpukrsyerireedeilhriseontneygldtlfsiadosfohhietieahrfyeiieettfsahtessfslrneacoghbtorseetehinnntuswdheeohrirsndhtklhacrenhhlaniyiras\n" + ] + } + ], + "source": [ + "(word_a, wrap_a), score_a = keyword_break(sca, fitness=Pletters)\n", + "print(word_a, wrap_a, '\\n')\n", + "pa = keyword_decipher(sca, word_a, wrap_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "47bfce9d-9932-457f-a175-715660ac9d01", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "okhltfwynjvdgsiuqraecbpxmz \n", + "\n", + "jiauecdeavaogctdtgiknrassteycppmespsnahaeoviveloiisfcodnesdietpsetthcslyatteackksoaartngeaoilssesseomorbcatesnoushiimtussprcutotlyevdubotcgeifwnsrvtnectdteitcytoaponaapeitieatssrihtiivtafmoliruittwayfetahtalwmwasdumsschnuinsiteisitdaecrasnhpitpoestossupttefwrtsefdssdyolosltttetgupripdcuyooteonsaiinsenmaitrorgryfcpncymttompderatdnoetuceeoetenseonsgeosspuihruaremodbnlfdcetlotechurtoitscgreystiacehetinittcyouttlaricionisgnteaetunmureiiuneetotitnongeacepdusituyenossootcurpunniamntntsekrdscoiataicysolocstfumefttsnstgsfpnpunistsagydaicgtyntdtxtctekiwolsheiycgadefiaeirgavisofeloiupeitdebbeseittoresssotpgredtaiteereslsltoounlirheeioomtnsekcprwnlyraoaaotociecepleapttytdetsvosmatuopeifagytaalgnasrseafracetsrluthsarvforvtcmsdktrsnscnopdmieogteritrmtcofrtennubayevaipdflosccntflcutthrmoemsstcktesatihenototmtelieceouoayoctiiviftosoeasittaoclotsariedcmatlnfadmsoboocvodotsvcdraeneaecogtmteaagusmscrsicrcotospkootutsdoorlnatceenahtdonttetryuidiubprettlccoelndnaieonnaicyottnpocgyofpacarciahlteaatrailtgmproswatdiaeeouumtkfoprdiuinsstegluorpstpildtinosertiyitckatacwyognewetnuyiehttocdoxugsaltctlwntpsttroptriistipteeuepelnuiefkiutynggalxpaeeebaefytndooltyinloeiskedalceiydaamgesdvchootcruilollakesclsisuiunssdapoceabctainmlenangcpwenrtapimignckoetthpoecksdhirecgecesiunlstomevizdoveangeteruaraeyoetuarsiloelsybadtsielistrgrpgrnashnssltgmetiklenpehtfieeyisdabtccbaestsctmpesethieovterdsvelenotpwamsttotwdncvwtiatoeduotarifdsentotedsmyiniodseteignvigodeodealoneecluireeppoogrietmeangdouaimicihsamnavsdsaumichrsepecaaostmlsdrcorsotaetesatstejrgnhdhpsoetsdfedgesscrskiracrntkmtuavousoerlaiostntcstimietttrspttcatdhetasasoteodvioaslromethstdiiomlsdibisledtetgttietecwahfuttrcapatttafeepsslyaiodonencssmissdptoxppiscteleksbcosmsaieitilcttaewostrretrnerierteeuitoewpbrnhtrorttltodcrontaieithmdledfnoslanfaccoteotscrfhtootteefnscetnnfndritsuamcvearnttetcoiiiepnglcttacrornilcebdcsurticcdsiohorsn\n" + ] + } + ], + "source": [ + "word_a, score_a = monoalphabetic_sa_break(sca)\n", + "print(word_a, '\\n')\n", + "pa = keyword_decipher(sca, word_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "d925f1d9-f70b-4858-85ba-8eb1ae919080", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a \n", + "\n", + "jnocthltoboiwhelewnvsroaaetmhuugtauasoyotibnbtdinnafhilstalnteuateeyhadmoeetohvvaiooreswtoindaataatigirkhoetasicaynngecaaurhceiedmtblckiehwtnfpsarbestheletnehmeiouisooutnentoeaarnyennbeofgidnrcneepomfteoyeodpgpoalcgaahyscnsanetnanelothroasyuneuitaeiaacueetfpreatflaalmidiadeeetewcurnulhcmiietisaonnsatsgonerirwrmfhushmgeeigultroelsitechttitetsatisawtiaaucnyrcortgilksdflhtediethycreineahwrtmaenohtytensneehmiceedornhnisnawsetotecsgcrtnncstteienesiswtohtulcanecmtsiaaiiehcrucssnogseseatvrlahinoeonhmaidihaefcgtfeeasaewafusucsnaeaowmlonhwemselexehetvnpidaytnmhwoltfnotnrwobnaiftdincutneltkktatneeirtaaaieuwrtleonettrtadadeiicsdnryttniigesatvhurpsdmroiooieihnthtudtoueemelteabiagoeciutnfowmeoodwsoaratofrohteardceyaorbfirbehgalverasahsiulgntiwetrnergehifretssckomtbonulfdiahhsefdhceeyrgitgaaehvetaoenytsieiegetdnthticiomihennbnfeiaitoaneeoihdieaorntlhgoedsfolgaikiihbilieabhlrotstothiwegetoowcagahranhrhieiauviiecealiirdsoehttsoyeliseetermcnlnckurteedhhitdslsontissonhmieesuihwmifuohorhnoydetooerondewguriapoelnotticcgevfiurlncnsaaetwdciruaeundlensiatrenmnehvoeohpmiwstptescmntyeeihlixcwaodehedpseuaeeriuernnaenuettctutdscntfvncemswwodxuotttkotfmesliidemnsditnavtlodhtnmloogwtalbhyiiehrcndiddovtahdanacncsaalouihtokheonsgdtsoswhuptsreoungnwshviteeyuithvalynrthwthtancsdaeigtbnzlibtoswtetrcorotmitecoranditdamkoleantdnaerwruwrsoaysaadewgtenvdtsutyefnttmnalokehhkotaeahegutateyntibetrlabtdtsieupogaeeieplshbpenoeitlcieornflatseietlagmnsnilatetnwsbnwiltiltodistthdcnrttuuiiwrntegtoswlicongnhnyaogsobalaocgnhyratuthooiaegdalrhiraieotetaoeaetjrwsylyuaitealftlwtaahravnrohrsevgecobicaitrdoniaesehaengnteeeraueehoelyteoaoaietilbnioadrigteyaelnnigdalnknadtleteweentethpoyfceerhouoeeeofttuaadmonilistshaagnaalueixuunahetdtvakhiagaontnendheeotpiaerrterstrntrettcneitpukrsyerireedeilhriseontneygldtlfsiadosfohhietieahrfyeiieettfsahtessfslrneacoghbtorseetehinnntuswdheeohrirsndhtklhacrenhhlaniyiras\n" + ] + } + ], + "source": [ + "word_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams)\n", + "print(word_a, '\\n')\n", + "pa = vigenere_decipher(sca, word_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "jodie i can see why you are concerned but i find it hard to believe that agatha could have been part\n", + "of a conspiracy she was a faithful colleague in all the time i worked with her and no one ever\n", + "suggested otherwise of course we ran the usual spot checks from time to time but nothing unusual was\n", + "found having said that the message you found in the archive is really worrying my first thought was\n", + "that she might have been acting as a double agent trying to destabilise nazi intelligence but that\n", + "doesnt fit with the text it is crucial to our mission that we maintain the balance of uncertainty\n", + "and direct it to our advantage make it look like she had definitely had another agenda i trawled\n", + "through my own records to see if anyone else agatha and i worked with might have been involved i\n", + "hate to say it but the only person of interest at the moment is charlie we worked together on the\n", + "kohinoor twins case and agatha washer great aunt not that treachery is a genetic trait but in\n", + "vetting circles it can be treated like it is inherited so i suppose we ought to take that seriously\n", + "especially since she became pretty senior in american intelligence i checked our current case files\n", + "and although she is retired she still acts as government liaison she is in london at the moment in\n", + "the new embassy building which will make it difficult to get hold of her if she wants to stay hidden\n", + "we cant afford to upset our us cousins and if we are wrong about her we might also poison the well\n", + "when it comes to intelligence exchange they havent for given us for phil by and maclean yet so i can\n", + "imagine how they would react if it turns out that one of our own is a double agent and has\n", + "infiltrated their inner sanctum i sent one of the elves to take a look at her apartment in new\n", + "jersey it was pretty clean as you can imagine but they were able to lift the following extract it\n", + "was hard to read and even harder to decipher since she used avi genere encryption but one\n", + "incriminating feature stands out even without a decrypt she used the ad morse encoding on top of the\n", + "vi genere cipher i am not sure what we should do next could you get the team to take a look at the\n", + "file maybe this is all a big coincidence or a misunderstanding if not then we may have to tell\n", + "london and washington and i am really not looking forward to that all the best harry\n" + ] + } + ], + "source": [ + "pa = railfence_decipher(sca, key_a)\n", + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2333" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "77e0eb5c-226d-4197-a687-4a5d725c6af0", + "metadata": {}, + "outputs": [], + "source": [ + "morse_chars = 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'.split()\n", + "# morse_chars" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "0c7912fb-f552-4933-9730-3784197fc729", + "metadata": {}, + "outputs": [], + "source": [ + "morse_codes = '.- / -... / -.-. / -.. / . / ..-. / --. / .... / .. / .--- / -.- / .-.. / -- / -. / --- / .--. / --.- / .-. / ... / - / ..- / ...- / .-- / -..- / -.-- / --.. / ----- / .---- / ..--- / ...-- / ....- / ..... / -.... / --... / ---.. / ----.'.split(' / ')" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "ae62967b-0c5d-4e14-adf2-8cad03ed6970", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['.-', '-...', '-.-.']" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "char_to_morse = {l: c for l, c in zip(morse_chars, morse_codes)}\n", + "morse_to_char = {c: l for l, c in zip(morse_chars, morse_codes)}\n", + "[char_to_morse[l] for l in 'abc']" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "d5c24bcb-fda8-40f0-89ba-166380046fc9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cdbaneliksgsaztmemhewdmgmydbanadbwyxbuxtynnzelojgrnyhlhyvcyhnrimsynckcifyjyifyjagyhlhuqisnxrunemdcdlhynxolgujdynukugwujynyokhybyannrymscmuftlsmcmuucfgyxkmilsyktbbimgbdbwumeudcbkhfefcvmtcdbanegyfeynngihfyktcquleckgvimkjhocxnwdnrultbonjihsnqtykgdezdzalyccftbovssywyftqryftboskhczjwdientundbwyxsxfonruneuvilozgujncxasnxkndeucnlhyixgnncywmnybsvyvyxtuxslhcxauulbyftzylzalbslozshvizdbwybkxzeqyoddhdbsvyzuksynnzecxpwsnsastcyhlonrysrwruwofyaasncclwiefvhufyyohomlrusaztozmlacbmxolkwliixcsmcxnoogshvsulimtcdcxahiifeyvmwwuccfvycnagudcfgcgimlxcuqwycbgufncynibyatnryqalooflcuydynygskywouhipuzimdijiwkfuulsikinivmtcpufyixyuoovxlrumylhyvcfknyoknignzehrujrskhvjincwalonzeixyktiniatdyxaecculelbcwrqrioohdfwtuxslhcxayoixwwsbobssbolleydbannyclahnbsrlibssvoyfalyofdfyhyehyoyhnyefoqgbwnmygwtbshytlspaafsmscneudlssgholduftixvsluxwwinrcfkcgcdlhoyvtilygnnryyriehvwbolwiwkhzojongihpfmehmylhyncjewdcgnipnzecbyfqoslaempijtboagoxyzwvybsgnygyfeynngkyojsvybsdoqzlgfcvystfouktqrcdenrytomccfvycnagudcgnccbgtmyoflycmlhycsktywzdaacujeuvwjimsmoeqsfdhufyloxsuddighgulkwlipsnaempijaqrcdeqoqalfmujrsyhoinrzgrymuktmlolwcvffonkwlohdbwmoxfwsmdbwtbbystfopwllsmwsnynwnyfyftbohlhymojiugcdlhoyvtiwywtnyxwccnyohydbwrcdckwccylonkewawdcgncgcdlbouvtivifdixngtuuyuhubawozwckdcbyutcyhqoomufcixnscnwystnrywmvkmkywrujlco'" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "morse_table = ''.maketrans('AD', '.-')\n", + "cb_dd = cb.translate(morse_table)\n", + "cb_words = cb_dd.split(' / ')\n", + "cb_letters = cat(cat(morse_to_char[l] for l in w.split()) for w in cb_words)\n", + "cb_letters" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "16210c33-3bcb-43c8-9189-d82eea7cf53b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ukusa \n", + "\n", + "ithinkbossmightsuspectsomethingtheydraftedthereportonthelighthousediscoveryoveramonthagoandhavestillnotforwardedasummarytoushereintheusicantriskmakingenquiriesthroughtheusualchannelsbutithinkweneedtoinvestigateiamdisappointedthatthetrinityteamleftfilesinthebasementwhentheyshippedoutbuttheydidnothavealotofwarningandatleasttheydontseemtohaveleftanythingcurrentforharrytofindiftheyhadhewouldnthavepassedtheinvestigationtothearchaeologistsitwouldhavegonestraightupstairsforactioniamintwomindsaboutitifanyoneelsewasinvestigatingiwouldsayweshouldignoreittheyareunlikelytomakemuchofahistoricalcuriositybutifanyonecouldtracethelinktousnowthenharryandjodiearetheonestodoitjodieisaterrierwhowontletanythinggoonceshehasherteethintoitandharryhasbeenaroundlongenoughtoknowwhensomethingtrivialisactuallyimportantonbalanceithinkiwillneedtobeonthegroundwhereicanhopetoinfluencethedirectionoftheirenquiriesforthegoodofeveryoneweneedtokeepaverylowprofileatleastwhilethebossinvestigationishotsounlessthesystemflagsarealcrisiswewillhavetodialdownouractivitiesforawhilewewillcarryonwithforecastsbutwillnotactonthemunlessthethreatlevelrisestoteneventhenthecuriawillneedtomeettodecidewhetheritiswisetotakeactioniwillheadtolondontotakechargeofmisdirectionyoucancontactmeattheembassycharlie\n" + ] + } + ], + "source": [ + "word_b, score_b = vigenere_frequency_break(cb_letters, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = vigenere_decipher(cb_letters, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "fe094361-7c85-40d9-952e-0c84abbcf903", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i think boss might suspect something they drafted the report on the lighthouse discovery over a\n", + "month ago and have still not forwarded a summary to us herein the us icant risk making enquiries\n", + "through the usual channels but i think we need to investigate i am disappointed that the trinity\n", + "team left files in the basement when they shipped out but they did not have alot of warning and\n", + "atleast they dont seem to have left anything current for harry to find if they had he wouldnt have\n", + "passed the investigation to the archaeologists it would have gone straight upstairs for action i am\n", + "in two minds about it if anyone else was investigating i would say we should ignore it they are\n", + "unlikely to make much of a historical curiosity but if anyone could trace the link to us now then\n", + "harry and jodie are the ones to do it jodie is a terrier who wont let anything go once she has her\n", + "teeth into it and harry has been around long enough to know when something trivial is actually\n", + "important on balance i think i will need to be on the ground where i can hope to influence the\n", + "direction of their enquiries for the good of everyone we need to keep a very low profile atleast\n", + "while the boss investigation is hot so unless the system flags a real crisis we will have to dial\n", + "down our activities for a while we will carry on with forecasts but will not acton them unless the\n", + "threat level rises to ten even then the curia will need to meet to decide whether it is wise to take\n", + "action i will head to london to take charge of misdirection you can contact meat the embassy charlie\n" + ] + } + ], + "source": [ + "pb = vigenere_decipher(cb_letters, word_b)\n", + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1563" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge5.md b/2021/2021-challenge5.md new file mode 100644 index 0000000..c0a093f --- /dev/null +++ b/2021/2021-challenge5.md @@ -0,0 +1,143 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.railfence import * +from szyfrow.support.text_prettify import * + +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +import collections +%matplotlib inline +``` + +```python Collapsed="false" +challenge_number = 5 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +rsca = cat(reversed(sca)) +scb = sanitise(cb) +``` + +```python +sca_counts = collections.Counter(sca) +sca_counts +``` + +```python +pd.Series(sca_counts).sort_index().plot.bar() +``` + +```python +key_a, score_a = railfence_break(sca, fitness=Ptrigrams) +print(key_a, '\n') +pa = railfence_decipher(sca, key_a) +print(pa) +``` + +```python +(word_a, fill_a, empty_a), score_a = column_transposition_break(rsca, fitness=Ptrigrams) +print(word_a, fill_a, empty_a, '\n') +pa = column_transposition_decipher(rsca, word_a, fillcolumnwise=fill_a, emptycolumnwise=empty_a) +print(pa) +``` + +```python +(word_a, wrap_a), score_a = keyword_break(sca, fitness=Pletters) +print(word_a, wrap_a, '\n') +pa = keyword_decipher(sca, word_a, wrap_a) +print(pa) +``` + +```python +word_a, score_a = monoalphabetic_sa_break(sca) +print(word_a, '\n') +pa = keyword_decipher(sca, word_a) +print(pa) +``` + +```python +word_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams) +print(word_a, '\n') +pa = vigenere_decipher(sca, word_a) +print(pa) +``` + +```python +pa = railfence_decipher(sca, key_a) +print(prettify(pa)) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +morse_chars = 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'.split() +# morse_chars +``` + +```python +morse_codes = '.- / -... / -.-. / -.. / . / ..-. / --. / .... / .. / .--- / -.- / .-.. / -- / -. / --- / .--. / --.- / .-. / ... / - / ..- / ...- / .-- / -..- / -.-- / --.. / ----- / .---- / ..--- / ...-- / ....- / ..... / -.... / --... / ---.. / ----.'.split(' / ') +``` + +```python +char_to_morse = {l: c for l, c in zip(morse_chars, morse_codes)} +morse_to_char = {c: l for l, c in zip(morse_chars, morse_codes)} +[char_to_morse[l] for l in 'abc'] +``` + +```python +morse_table = ''.maketrans('AD', '.-') +cb_dd = cb.translate(morse_table) +cb_words = cb_dd.split(' / ') +cb_letters = cat(cat(morse_to_char[l] for l in w.split()) for w in cb_words) +cb_letters +``` + +```python +word_b, score_b = vigenere_frequency_break(cb_letters, fitness=Ptrigrams) +print(word_b, '\n') +pb = vigenere_decipher(cb_letters, word_b) +print(pb) +``` + +```python +pb = vigenere_decipher(cb_letters, word_b) +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.5a.txt b/2021/ciphertext.5a.txt new file mode 100644 index 0000000..987a8d8 --- /dev/null +++ b/2021/ciphertext.5a.txt @@ -0,0 +1 @@ +JNOCT HLTOB OIWHE LEWNV SROAA ETMHU UGTAU ASOYO TIBNB TDINN AFHIL STALN TEUAT EEYHA DMOEE TOHVV AIOOR ESWTO INDAA TAATI GIRKH OETAS ICAYN NGECA AURHC EIEDM TBLCK IEHWT NFPSA RBEST HELET NEHME IOUIS OOUTN ENTOE AARNY ENNBE OFGID NRCNE EPOMF TEOYE ODPGP OALCG AAHYS CNSAN ETNAN ELOTH ROASY UNEUI TAEIA ACUEE TFPRE ATFLA ALMID IADEE ETEWC URNUL HCMII ETISA ONNSA TSGON ERIRW RMFHU SHMGE EIGUL TROEL SITEC HTTIT ETSAT ISAWT IAAUC NYRCO RTGIL KSDFL HTEDI ETHYC REINE AHWRT MAENO HTYTE NSNEE HMICE EDORN HNISN AWSET OTECS GCRTN NCSTT EIENE SISWT OHTUL CANEC MTSIA AIIEH CRUCS SNOGS ESEAT VRLAH INOEO NHMAI DIHAE FCGTF EEASA EWAFU SUCSN AEAOW MLONH WEMSE LEXEH ETVNP IDAYT NMHWO LTFNO TNRWO BNAIF TDINC UTNEL TKKTA TNEEI RTAAA IEUWR TLEON ETTRT ADADE IICSD NRYTT NIIGE SATVH URPSD MROIO OIEIH NTHTU DTOUE EMELT EABIA GOECI UTNFO WMEOO DWSOA RATOF ROHTE ARDCE YAORB FIRBE HGALV ERASA HSIUL GNTIW ETRNE RGEHI FRETS SCKOM TBONU LFDIA HHSEF DHCEE YRGIT GAAEH VETAO ENYTS IEIEG ETDNT HTICI OMIHE NNBNF EIAIT OANEE OIHDI EAORN TLHGO EDSFO LGAIK IIHBI LIEAB HLROT STOTH IWEGE TOOWC AGAHR ANHRH IEIAU VIIEC EALII RDSOE HTTSO YELIS EETER MCNLN CKURT EEDHH ITDSL SONTI SSONH MIEES UIHWM IFUOH ORHNO YDETO OERON DEWGU RIAPO ELNOT TICCG EVFIU RLNCN SAAET WDCIR UAEUN DLENS IATRE NMNEH VOEOH PMIWS TPTES CMNTY EEIHL IXCWA ODEHE DPSEU AEERI UERNN AENUE TTCTU TDSCN TFVNC EMSWW ODXUO TTTKO TFMES LIIDE MNSDI TNAVT LODHT NMLOO GWTAL BHYII EHRCN DIDDO VTAHD ANACN CSAAL OUIHT OKHEO NSGDT SOSWH UPTSR EOUNG NWSHV ITEEY UITHV ALYNR THWTH TANCS DAEIG TBNZL IBTOS WTETR COROT MITEC ORAND ITDAM KOLEA NTDNA ERWRU WRSOA YSAAD EWGTE NVDTS UTYEF NTTMN ALOKE HHKOT AEAHE GUTAT EYNTI BETRL ABTDT SIEUP OGAEE IEPLS HBPEN OEITL CIEOR NFLAT SEIET LAGMN SNILA TETNW SBNWI LTILT ODIST THDCN RTTUU IIWRN TEGTO SWLIC ONGNH NYAOG SOBAL AOCGN HYRAT UTHOO IAEGD ALRHI RAIEO TETAO EAETJ RWSYL YUAIT EALFT LWTAA HRAVN ROHRS EVGEC OBICA ITRDO NIAES EHAEN GNTEE ERAUE EHOEL YTEOA OAIET ILBNI OADRI GTEYA ELNNI GDALN KNADT LETEW EENTE THPOY FCEER HOUOE EEOFT TUAAD MONIL ISTSH AAGNA ALUEI XUUNA HETDT VAKHI AGAON TNEND HEEOT PIAER RTERS TRNTR ETTCN EITPU KRSYE RIREE DEILH RISEO NTNEY GLDTL FSIAD OSFOH HIETI EAHRF YEIIE ETTFS AHTES SFSLR NEACO GHBTO RSEET EHINN NTUSW DHEEO HRIRS NDHTK LHACR ENHHL ANIYI RAS diff --git a/2021/ciphertext.5b.txt b/2021/ciphertext.5b.txt new file mode 100644 index 0000000..d53e46a --- /dev/null +++ b/2021/ciphertext.5b.txt @@ -0,0 +1 @@ +DADA DAA DAAA AD DA A ADAA AA DAD AAA DDA AAA AD DDAA D DD A DD AAAA A ADD DAA DD DDA DD DADD DAA DAAA AD DA AD DAA DAAA ADD DADD DAAD DAAA AAD DAAD D DADD DA DA DDAA A ADAA DDD ADDD DDA ADA DA DADD AAAA ADAA AAAA DADD AAAD DADA DADD AAAA DA ADA AA DD AAA DADD DA DADA DAD DADA AA AADA DADD ADDD DADD AA AADA DADD ADDD AD DDA DADD AAAA ADAA AAAA AAD DDAD AA AAA DA DAAD ADA AAD DA A DD DAA DADA DAA ADAA AAAA DADD DA DAAD DDD ADAA DDA AAD ADDD DAA DADD DA AAD DAD AAD DDA ADD AAD ADDD DADD DA DADD DDD DAD AAAA DADD DAAA DADD AD DA DA ADA DADD DD AAA DADA DD AAD AADA D ADAA AAA DD DADA DD AAD AAD DADA AADA DDA DADD DAAD DAD DD AA ADAA AAA DADD DAD D DAAA DAAA AA DD DDA DAAA DAA DAAA ADD AAD DD A AAD DAA DADA DAAA DAD AAAA AADA A AADA DADA AAAD DD D DADA DAA DAAA AD DA A DDA DADD AADA A DADD DA DA DDA AA AAAA AADA DADD DAD D DADA DDAD AAD ADAA A DADA DAD DDA AAAD AA DD DAD ADDD AAAA DDD DADA DAAD DA ADD DAA DA ADA AAD ADAA D DAAA DDD DA ADDD AA AAAA AAA DA DDAD D DADD DAD DDA DAA A DDAA DAA DDAA AD ADAA DADD DADA DADA AADA D DAAA DDD AAAD AAA AAA DADD ADD DADD AADA D DDAD ADA DADD AADA D DAAA DDD AAA DAD AAAA DADA DDAA ADDD ADD DAA AA A DA D AAD DA DAA DAAA ADD DADD DAAD AAA DAAD AADA DDD DA ADA AAD DA A AAD AAAD AA ADAA DDD DDAA DDA AAD ADDD DA DADA DAAD AD AAA DA DAAD DAD DA DAA A AAD DADA DA ADAA AAAA DADD AA DAAD DDA DA DA DADA DADD ADD DD DA DADD DAAA AAA AAAD DADD AAAD DADD DAAD D AAD DAAD AAA ADAA AAAA DADA DAAD AD AAD AAD ADAA DAAA DADD AADA D DDAA DADD ADAA DDAA AD ADAA DAAA AAA ADAA DDD DDAA AAA AAAA AAAD AA DDAA DAA DAAA ADD DADD DAAA DAD DAAD DDAA A DDAD DADD DDD DAA DAA AAAA DAA DAAA AAA AAAD DADD DDAA AAD DAD AAA DADD DA DA DDAA A DADA DAAD ADDA ADD AAA DA AAA AD AAA D DADA DADD AAAA ADAA DDD DA ADA DADD AAA ADA ADD ADA AAD ADD DDD AADA DADD AD AD AAA DA DADA DADA ADAA ADD AA A AADA AAAD AAAA AAD AADA DADD DADD DDD AAAA DDD DD ADAA ADA AAD AAA AD DDAA D DDD DDAA DD ADAA AD DADA DAAA DD DAAD DDD ADAA DAD ADD ADAA AA AA DAAD DADA AAA DD DADA DAAD DA DDD DDD DDA AAA AAAA AAAD AAA AAD ADAA AA DD D DADA DAA DADA DAAD AD AAAA AA AA AADA A DADD AAAD DD ADD ADD AAD DADA DADA AADA AAAD DADD DADA DA AD DDA AAD DAA DADA AADA DDA DADA DDA AA DD ADAA DAAD DADA AAD DDAD ADD DADD DADA DAAA DDA AAD AADA DA DADA DADD DA AA DAAA DADD AD D DA ADA DADD DDAD AD ADAA DDD DDD AADA ADAA DADA AAD DADD DAA DADD DA DADD DDA AAA DAD DADD ADD DDD AAD AAAA AA ADDA AAD DDAA AA DD DAA AA ADDD AA ADD DAD AADA AAD AAD ADAA AAA AA DAD AA DA AA AAAD DD D DADA ADDA AAD AADA DADD AA DAAD DADD AAD DDD DDD AAAD DAAD ADAA ADA AAD DD DADD ADAA AAAA DADD AAAD DADA AADA DAD DA DADD DDD DAD DA AA DDA DA DDAA A AAAA ADA AAD ADDD ADA AAA DAD AAAA AAAD ADDD AA DA DADA ADD AD ADAA DDD DA DDAA A AA DAAD DADD DAD D AA DA AA AD D DAA DADD DAAD AD A DADA DADA AAD ADAA A ADAA DAAA DADA ADD ADA DDAD ADA AA DDD DDD AAAA DAA AADA ADD D AAD DAAD AAA ADAA AAAA DADA DAAD AD DADD DDD AA DAAD ADD ADD AAA DAAA DDD DAAA AAA AAA DAAA DDD ADAA ADAA A DADD DAA DAAA AD DA DA DADD DADA ADAA AD AAAA DA DAAA AAA ADA ADAA AA DAAA AAA AAA AAAD DDD DADD AADA AD ADAA DADD DDD AADA DAA AADA DADD AAAA DADD A AAAA DADD DDD DADD AAAA DA DADD A AADA DDD DDAD DDA DAAA ADD DA DD DADD DDA ADD D DAAA AAA AAAA DADD D ADAA AAA ADDA AD AD AADA AAA DD AAA DADA DA A AAD DAA ADAA AAA AAA DDA AAAA DDD ADAA DAA AAD AADA D AA DAAD AAAD AAA ADAA AAD DAAD ADD ADD AA DA ADA DADA AADA DAD DADA DDA DADA DAA ADAA AAAA DDD DADD AAAD D AA ADAA DADD DDA DA DA ADA DADD DADD ADA AA A AAAA AAAD ADD DAAA DDD ADAA ADD AA ADD DAD AAAA DDAA DDD ADDD DDD DA DDA AA AAAA ADDA AADA DD A AAAA DD DADD ADAA AAAA DADD DA DADA ADDD A ADD DAA DADA DDA DA AA ADDA DA DDAA A DADA DAAA DADD AADA DDAD DDD AAA ADAA AD A DD ADDA AA ADDD D DAAA DDD AD DDA DDD DAAD DADD DDAA ADD AAAD DADD DAAA AAA DDA DA DADD DDA DADD AADA A DADD DA DA DDA DAD DADD DDD ADDD AAA AAAD DADD DAAA AAA DAA DDD DDAD DDAA ADAA DDA AADA DADA AAAD DADD AAA D AADA DDD AAD DAD D DDAD ADA DADA DAA A DA ADA DADD D DDD DD DADA DADA AADA AAAD DADD DADA DA AD DDA AAD DAA DADA DDA DA DADA DADA DAAA DDA D DD DADD DDD AADA ADAA DADD DADA DD ADAA AAAA DADD DADA AAA DAD D DADD ADD DDAA DAA AD AD DADA AAD ADDD A AAD AAAD ADD ADDD AA DD AAA DD DDD A DDAD AAA AADA DAA AAAA AAD AADA DADD ADAA DDD DAAD AAA AAD DAA DAA AA DDA AAAA DDA AAD ADAA DAD ADD ADAA AA ADDA AAA DA AD A DD ADDA AA ADDD AD DDAD ADA DADA DAA A DDAD DDD DDAD AD ADAA AADA DD AAD ADDD ADA AAA DADD AAAA DDD AA DA ADA DDAA DDA ADA DADD DD AAD DAD D DD ADAA DDD ADAA ADD DADA AAAD AADA AADA DDD DA DAD ADD ADAA DDD AAAA DAA DAAA ADD DD DDD DAAD AADA ADD AAA DD DAA DAAA ADD D DAAA DAAA DADD AAA D AADA DDD ADDA ADD ADAA ADAA AAA DD ADD AAA DA DADD DA ADD DA DADD AADA DADD AADA D DAAA DDD AAAA ADAA AAAA DADD DD DDD ADDD AA AAD DDA DADA DAA ADAA AAAA DDD DADD AAAD D AA ADD DADD ADD D DA DADD DAAD ADD DADA DADA DA DADD DDD AAAA DADD DAA DAAA ADD ADA DADA DAA DADA DAD ADD DADA DADA DADD ADAA DDD DA DAD A ADD AD ADD DAA DADA DDA DA DADA DDA DADA DAA ADAA DAAA DDD AAD AAAD D AA AAAD AA AADA DAA AA DAAD DA DDA D AAD AAD DADD AAD AAAA AAD DAAA AD ADD DDD DDAA ADD DADA DAD DAA DADA DAAA DADD AAD D DADA DADD AAAA DDAD DDD DDD DD AAD AADA DADA AA DAAD DA AAA DADA DA ADD DADD AAA D DA ADA DADD ADD DD AAAD DAD DD DAD DADD ADD ADA AAD ADDD ADAA DADA DDD diff --git a/2021/plaintext.5a.txt b/2021/plaintext.5a.txt new file mode 100644 index 0000000..382498c --- /dev/null +++ b/2021/plaintext.5a.txt @@ -0,0 +1,24 @@ +jodie i can see why you are concerned but i find it hard to believe that agatha could have been part +of a conspiracy she was a faithful colleague in all the time i worked with her and no one ever +suggested otherwise of course we ran the usual spot checks from time to time but nothing unusual was +found having said that the message you found in the archive is really worrying my first thought was +that she might have been acting as a double agent trying to destabilise nazi intelligence but that +doesnt fit with the text it is crucial to our mission that we maintain the balance of uncertainty +and direct it to our advantage make it look like she had definitely had another agenda i trawled +through my own records to see if anyone else agatha and i worked with might have been involved i +hate to say it but the only person of interest at the moment is charlie we worked together on the +kohinoor twins case and agatha washer great aunt not that treachery is a genetic trait but in +vetting circles it can be treated like it is inherited so i suppose we ought to take that seriously +especially since she became pretty senior in american intelligence i checked our current case files +and although she is retired she still acts as government liaison she is in london at the moment in +the new embassy building which will make it difficult to get hold of her if she wants to stay hidden +we cant afford to upset our us cousins and if we are wrong about her we might also poison the well +when it comes to intelligence exchange they havent for given us for phil by and maclean yet so i can +imagine how they would react if it turns out that one of our own is a double agent and has +infiltrated their inner sanctum i sent one of the elves to take a look at her apartment in new +jersey it was pretty clean as you can imagine but they were able to lift the following extract it +was hard to read and even harder to decipher since she used avi genere encryption but one +incriminating feature stands out even without a decrypt she used the ad morse encoding on top of the +vi genere cipher i am not sure what we should do next could you get the team to take a look at the +file maybe this is all a big coincidence or a misunderstanding if not then we may have to tell +london and washington and i am really not looking forward to that all the best harry \ No newline at end of file diff --git a/2021/plaintext.5b.txt b/2021/plaintext.5b.txt new file mode 100644 index 0000000..b7acd34 --- /dev/null +++ b/2021/plaintext.5b.txt @@ -0,0 +1,16 @@ +i think boss might suspect something they drafted the report on the lighthouse discovery over a +month ago and have still not forwarded a summary to us herein the us icant risk making enquiries +through the usual channels but i think we need to investigate i am disappointed that the trinity +team left files in the basement when they shipped out but they did not have alot of warning and +atleast they dont seem to have left anything current for harry to find if they had he wouldnt have +passed the investigation to the archaeologists it would have gone straight upstairs for action i am +in two minds about it if anyone else was investigating i would say we should ignore it they are +unlikely to make much of a historical curiosity but if anyone could trace the link to us now then +harry and jodie are the ones to do it jodie is a terrier who wont let anything go once she has her +teeth into it and harry has been around long enough to know when something trivial is actually +important on balance i think i will need to be on the ground where i can hope to influence the +direction of their enquiries for the good of everyone we need to keep a very low profile atleast +while the boss investigation is hot so unless the system flags a real crisis we will have to dial +down our activities for a while we will carry on with forecasts but will not acton them unless the +threat level rises to ten even then the curia will need to meet to decide whether it is wise to take +action i will head to london to take charge of misdirection you can contact meat the embassy charlie \ No newline at end of file -- 2.34.1 From a2adf18bfed90449940ae7d06fd76fbbb83bf2a4 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 18 Nov 2021 17:38:48 +0000 Subject: [PATCH 13/16] Done 2021 challenge 6 --- 2021/2021-challenge6.ipynb | 583 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge6.md | 114 ++++++++ 2021/ciphertext.6a.txt | 1 + 2021/ciphertext.6b.txt | 1 + 2021/plaintext.6a.txt | 26 ++ 2021/plaintext.6b.txt | 21 ++ 6 files changed, 746 insertions(+) create mode 100644 2021/2021-challenge6.ipynb create mode 100644 2021/2021-challenge6.md create mode 100644 2021/ciphertext.6a.txt create mode 100644 2021/ciphertext.6b.txt create mode 100644 2021/plaintext.6a.txt create mode 100644 2021/plaintext.6b.txt diff --git a/2021/2021-challenge6.ipynb b/2021/2021-challenge6.ipynb new file mode 100644 index 0000000..781e8ec --- /dev/null +++ b/2021/2021-challenge6.ipynb @@ -0,0 +1,583 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 18, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.vigenere import *\n", + "from szyfrow.support.text_prettify import *\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import collections\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 6\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": 20, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "sca = sanitise(ca)\n", + "rsca = cat(reversed(sca))\n", + "scb = sanitise(cb)\n", + "rscb = cat(reversed(scb))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'r': 124,\n", + " 'm': 42,\n", + " 't': 227,\n", + " 'u': 65,\n", + " 'v': 24,\n", + " 'a': 163,\n", + " 's': 138,\n", + " 'w': 41,\n", + " 'c': 59,\n", + " 'i': 158,\n", + " 'f': 35,\n", + " 'd': 66,\n", + " 'e': 279,\n", + " 'l': 44,\n", + " 'j': 2,\n", + " 'h': 142,\n", + " 'o': 130,\n", + " 'n': 144,\n", + " 'b': 36,\n", + " 'g': 63,\n", + " 'y': 37,\n", + " 'p': 29,\n", + " 'k': 12,\n", + " 'q': 3,\n", + " 'x': 2})" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sca_counts = collections.Counter(sca)\n", + "sca_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAASH0lEQVR4nO3dfbBcdX3H8fdHtGgBLZSAKaBBJz5AVdSIdsQprVXwadBWbGiHUqtGLbTaWitYW63TtDj1Yaa2UFHUqCimKoUZrYipHaQ+YILIU2CMghpBiM8ZR9HEb//YE9le9unuvTf35pf3a2Zn9/z2/M753nPP/ezZ39k9N1WFJKkt91jsAiRJ889wl6QGGe6S1CDDXZIaZLhLUoMMd0lq0D0XuwCAgw8+uFasWLHYZUjSHmXTpk3frqplg55bEuG+YsUKNm7cuNhlSNIeJcnXhj3nsIwkNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQUviS0x7gxVnfnToc7ec/YzdWImkvYFH7pLUIMNdkhpkuEtSgwx3SWqQ4S5JDTLcJalBhrskNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBhnuktSgseGe5Igkn0qyOcn1SV7Wtb8uyTeTXN3dnt7X56wkW5LclOSEhfwBJEl3N8m/2dsBvKKqrkpyALApyWXdc2+pqjf2z5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vqdTbPfLnUztsUO4Paq2jGmz9nAhTXiAwYj+u5P78X/r+h9KGLfEfOumvm3l+TUqhp5fiTJ64HzB/0ekzx8kuxY8uEuLYYkbwfeMuE7Oe0Fuk+wPIne0fvXuOuTM/+9qIUNYbhLAyTZDDyY3km9pTREpUWS5JX0An3TuHcGS4HhLg0w7RCLtFQY7pLUoCX5JSZJ0twY7pLUIMNdkhpkuEtSgwx3SWrQ/wGJhqR+GErYRAAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(sca_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "61ce2102-294e-4b1a-842c-1607aa7a4b05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6 \n", + "\n", + "rnhsheesramriuewtasdtitnaceiglucseeeocervciainrorfaerbtlishirbsaenshatsasituehetwetsqniofncastwohaswiigndhfthraeraettotefrhthmithgdsrtayuackerwdhrahetlnitmsofmoasuoaurgeeugeeoovesrjulithtetrmattrehearihsinonecmhepuaownietserwysrcafntghhhecseiytuefesllcahonrsbeebgaatesethshtecaabbogweboantimdcurseoitiafsderinmoamndnaemhsiscasbveeosatrinhitwnlfsrucennhdedeeloebetnpbohethfefdarcenggnieeedintscutecsoshmrardyoloertoeaeoubnhsitmierhutetlhrdinstohaautahywsenetnsrgecnciethnpieneetntesetnhrugiysnhwviahwcataerfbttuedfihlfenrhegncbithehmgiiihembsehtomacoascdiiteetccuhghapharoimapsrdiastoonomhicaotindfthreaekeeourocanitoeisseudlhisthyttehatvtitirpentohateenesydblubnrceeyedteignudageihrweniiashsodneevysrrpelittstieetniviitnicuabmshatohertfwofedoarfiwleiouggieethtltehanyflettnoeawtmamhbtiseinoaniggevthnrwaeasrowneynitbgavondarowingiisipsacnbonhueytsdtnclgihnhouhicnosesraiuristitnkitsohwnuchdogoeaguwnomootpdcsslrhvaoeeitwneudcipatohnpsriotiiicpionhisregseuetudoshseocaneettmixreouhfyuogecldunyosttmhitneslnoekeifoylaobssueaerqejiedhyrhaeaisuyihreemssthrebenhyrdioyfosauikhhtnottahaswerlrsagooirodnnebutactwntnetictthnoldohduuroegenhevtgetneceneonsotheettrlereasiketwgewavisaetuusesmishetvnlvimoedohewarrondsokthosaatfsiavkasinrdihatratceildogatesotcaltyalyanathehtinttarothtveetaheiemisgbmrorleftrgithnceoubnopinoyraocfuruehseesinetirxppneedstnagsoshaghgtmvbtdevrelietabundetsteorebotfechttreytinergupttianmpsssmteibwahthoreeamcinsnaeweorladievyietsgaitgtieehonfarsptycnduahermctdeteenafevyttighihtneeitlmaskasonilnashglytefditertmeniearigwetiwvicttatuubwahttatyesragtseqrituegnofwnehhyodydnlratseteeinllnttgincthtewesuntraehertnmereiitttdtrrabacikchrtahousaghaeocsrudrosgtfeeieheiatysatihgtnggosasetheehateimhtebehateeadtelouegantnihnopgnenaentioidthrelefharsetaldaebgtiacinoldewowgnthnisthaatearhcdvgnietrsgmmtfaaroethettiriiairuaiwnishthekamgehtneahhesutnuerekessanithrybebsolstnhsonnwentdehoneurantepdpgsrepddeoryhttswsahetpassdreenmnohepnatitcisyconoutswenibrevhaodetuddaoesthparatregyahyasaeotisnaeapgarcoagnrdlotherrorepstedvtoidierppuofeauorerntrfooeemohwsnt\n" + ] + } + ], + "source": [ + "key_a, score_a = railfence_break(sca, fitness=Ptrigrams)\n", + "print(key_a, '\\n')\n", + "pa = railfence_decipher(sca, key_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "605792ee-8bbf-44da-b33f-6bd2321f449e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 4, 3, 0, 1) False True \n", + "\n", + "harryiamsurethismustbeveryhardforyouasiknowthatcharliewasagoodfriendbutwecantletthatcloudourjudgementgiventhecontentofherletterlastweekwehavetoassumesheisinvolvedsomehowandworkonthatbasishavingsaidthatcharliedoesntactuallysayanythingthatprovesthatsheisamemberofthelighthouseconspiracyofcoursesheisanexperiencedagentsothatmightbedeliberatebutshedoesrefertothetrinitygroupanditspossiblethattheamericanswerealreadyinvestigatingtheconspiracyunderthatcodenameeverythingintheemailtakesonaslightlydifferentmeaningifweviewitthatwaybutthatraisesthequestionofwhytheydidntsharetheintelligencewithusinthemeantimeitriedtotrackbackthroughagathasrecordtoseeifthereisanythingtosuggestthatshemighthavebeenadoubleagentnothingmentionedinthefileraisedaflagbutinoticedtwothingsintheattachedvettingsummaryafterherinitialruninwiththegermantreasurehuntersseekingthebabylonstoneshewentontherunandpapersreportedthatshewasapassengeronthetitanicasyouknowsheneverboardedandusedthattragedyasawaytodisappearaccordingtothereportshedidnotreappearforoverfourteenmonthswhenshewasrecruitedasanintelligencesourceincairoforthebritishembassythatraisesthequestionofwhatshewasdoingfortheyeartheotherthingthatstruckachordwasthementionofmassouriegeorgeeverestbuiltaretreatthereandhisnamecameupwheniwasresearchingthesecurityfilesofcharlesbabbageitseemsthatbabbagewasintroducedtoideasfromindianmathematicsbyeverestandthisinfluencedthedevelopmentofthedifferenceengineanditssuccessorsmaryboolewroteaboutthisinherletterindianthoughtandwesternscienceinthenineteenthcenturygivenwhatchwroteaboutthedifferenceenginethismightbemorethanacoincidencethoughperhapsiamreadingtoomuchintoitforthesakeofourtraineesishouldsaythatthevettingreporthasbeendoubleencryptedusingavigenerewithasecondverysimpletwistimentionitbecausethatthrewmeoffforawhileisuggestthattheyreflectonwhatmightbegoingongiventhatwearenowtryingtoavoidraisingsuspicionbytheusandthelighthouseconspiratorsithinkweshouldchangeourownprotocolssoihaveswitcheduptoatranspositioncipherisuggestyoudothesamenexttimethoughyoucouldtrysomethingelselikeapolybiussquarejodie\n" + ] + } + ], + "source": [ + "(word_a, fill_a, empty_a), score_a = column_transposition_break(sca, fitness=Ptrigrams)\n", + "print(word_a, fill_a, empty_a, '\\n')\n", + "pa = column_transposition_decipher(sca, word_a, fillcolumnwise=fill_a, emptycolumnwise=empty_a)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "b66bf02f-9e8b-421d-8549-ab00774465ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 4, 3, 0, 1)" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transpositions_of('deacb')" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "b9fa44e0-fd0c-4ff3-b62b-81db5c4b6109", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['gibed',\n", + " 'gybed',\n", + " 'hodge',\n", + " 'image',\n", + " 'imbed',\n", + " 'jodie',\n", + " 'judge',\n", + " 'lobed',\n", + " 'locke',\n", + " 'lodge',\n", + " 'lubed',\n", + " 'lucid',\n", + " 'noble',\n", + " 'noemi',\n", + " 'nudge',\n", + " 'osage',\n", + " 'prank',\n", + " 'pubic',\n", + " 'pylon',\n", + " 'quake',\n", + " 'ruble',\n", + " 'stage',\n", + " 'staid',\n", + " 'stake',\n", + " 'stale',\n", + " 'stalk',\n", + " 'stand',\n", + " 'stank',\n", + " 'staph',\n", + " 'stare',\n", + " 'stark',\n", + " 'stern',\n", + " 'stink',\n", + " 'sucre',\n", + " 'swage',\n", + " 'swami',\n", + " 'swank',\n", + " 'sward',\n", + " 'swarm',\n", + " 'swirl',\n", + " 'tubed',\n", + " 'twang',\n", + " 'twerp',\n", + " 'twirl',\n", + " 'wyeth',\n", + " 'fibbed',\n", + " 'fobbed',\n", + " 'gobbed',\n", + " 'jobbed',\n", + " 'judged',\n", + " 'lobbed',\n", + " 'lodged',\n", + " 'lucile',\n", + " 'lychee',\n", + " 'mobbed',\n", + " 'muddle',\n", + " 'mumble',\n", + " 'noodle',\n", + " 'nudged',\n", + " 'osages',\n", + " 'puddle',\n", + " 'ruanda',\n", + " 'rubbed',\n", + " 'rubble',\n", + " 'rubier',\n", + " 'rubric',\n", + " 'rwanda',\n", + " 'stages',\n", + " 'stakes',\n", + " 'stales',\n", + " 'stalks',\n", + " 'stands',\n", + " 'staphs',\n", + " 'starer',\n", + " 'stares',\n", + " 'stated',\n", + " 'static',\n", + " 'stereo',\n", + " 'sterne',\n", + " 'sterns',\n", + " 'stinks',\n", + " 'subbed',\n", + " 'sudoku',\n", + " 'summon',\n", + " 'swamis',\n", + " 'swanee',\n", + " 'swanks',\n", + " 'swards',\n", + " 'swarms',\n", + " 'swirls',\n", + " 'sydney',\n", + " 'tubule',\n", + " 'tycoon',\n", + " 'imbibed',\n", + " 'inching',\n", + " 'kneeing',\n", + " 'lucille',\n", + " 'muddied',\n", + " 'muddled',\n", + " 'nodding',\n", + " 'noodled',\n", + " 'prairie',\n", + " 'premier',\n", + " 'puddled',\n", + " 'quahaug',\n", + " 'ruddier',\n", + " 'rwandan',\n", + " 'stalest',\n", + " 'starter',\n", + " 'stashes',\n", + " 'statics',\n", + " 'steepen',\n", + " 'steeple',\n", + " 'stereos',\n", + " 'sterner',\n", + " 'sternes',\n", + " 'stetson',\n", + " 'subsume',\n", + " 'succeed',\n", + " 'sudokus',\n", + " 'summons',\n", + " 'susanne',\n", + " 'swansea',\n", + " 'swashes',\n", + " 'sydneys',\n", + " 'tuition',\n", + " 'imbedded',\n", + " 'indigene',\n", + " 'premiere',\n", + " 'starters',\n", + " 'steeples',\n", + " 'sternest',\n", + " 'stetsons',\n", + " 'subsumes',\n", + " 'succeeds',\n", + " 'summonss',\n", + " 'susannes',\n", + " 'swanseas',\n", + " 'statistic',\n", + " 'steeliest',\n", + " 'steepness',\n", + " 'sternness',\n", + " 'succeeded',\n", + " 'statistics',\n", + " 'steepnesss',\n", + " 'sternnesss',\n", + " 'ouagadougou']" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transpositions[word_a]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harry i am sure this must be very hard for you as i know that charlie was a good friend but we cant\n", + "let that cloud our judgement given the content of her letter last week we have to assumes he is\n", + "involved somehow and work on that basis having said that charlie doesnt actually say anything that\n", + "proves that she is a member of the lighthouse conspiracy of course she is an experienced agent so\n", + "that might be deliberate but she does refer to the trinity group and its possible that the americans\n", + "were already investigating the conspiracy under that codename everything in the email takes on a\n", + "slightly different meaning if we view it that way but that raises the question of why they didnt\n", + "share the intelligence with us in the meantime i tried to trackback through agatha s record to see\n", + "if there is anything to suggest that she might have been a double agent nothing mentioned in the\n", + "file raised a flag but i noticed two things in the attached vetting summary after her initial run in\n", + "with the german treasure hunters seeking the babylon stone she went on the run and papers reported\n", + "that she was a passenger on the titanic as you know she never boarded and used that tragedy as away\n", + "to disappear according to the report she did not reappear for over fourteen months when she was\n", + "recruited as an intelligence source in cairo for the british embassy that raises the question of\n", + "what she was doing for the year the other thing that struck a chord was the mention of mass our ie\n", + "george everest built a retreat there and his name came up when i was researching the security files\n", + "of charles babbage it seems that babbage was introduced to ideas from indian mathematics by everest\n", + "and this influenced the development of the difference engine and its successors mary boole wrote\n", + "about this in her letter indian thought and western science in the nineteenth century given what ch\n", + "wrote about the difference engine this might be more than a coincidence though perhaps i am reading\n", + "too much into it for the sake of our trainees i should say that the vetting report has been double\n", + "encrypted using avi genere with a second very simple twist i mention it because that threw me off\n", + "for a while i suggest that they reflect on what might be going on given that we are now trying to\n", + "avoid raising suspicion by the us and the lighthouse conspirators i think we should change our own\n", + "protocols so i have switched up to a transposition cipher i suggest you do the same next time though\n", + "you could try something else like a polybius square jodie\n" + ] + } + ], + "source": [ + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2525" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "16210c33-3bcb-43c8-9189-d82eea7cf53b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "nittevg \n", + "\n", + "yllaunnaibdesiverebdluohsharofecnaraelcehttessarojamasatubnrecnocrofsdnuorgtnerruconeraerehtmsicafybdesoptaerhtetaidemmieromehtmorftcartsidotylekilyrevdnasmiadetatsstinideeccusotylekilnusatidedragerohwyratercesngierofehtybdetcejersawlasoporpehtmehtllatserofotredronistaerhterutufgniniltuostroperegnargnoleraperpotsawmiadetatsehtsrethgilpmalehtpuorgsihtdemankcinehsgninnalpdrawrofotdetacidedycnegaehtfohcnarbwenafohcnualehtgnidnemmocerrepapadetfardhahcinumrofgnivaelerofebevitaitininworehtadehcnualsawhcihwnetsimehclaeidnoitagitsevnitsetalrehotdeltahwsisihtylbamuserpdralizstsitneicsnairagnuhehtdnatforkcockciwdahcgnidulcnidoirepsihtgnirudsrotisivforebmunllamsadahehsnagebynamregninoissimtnerrucrehlitnudevilehserehwhciwneergnitnemtrapanakoothakuehtotnrutertnecerrehnosnoitareponeewtebdnanohtobsecruosernwonkrehhtiwtnetsisnocelytsefiladnasdneirfwefsahehseiruossamnigniyatsaidniniyadilohgniklawakootehsnoissimtnecertsomrehfodneehttaaisadnaacirfanisdoireptnacifingisdnepsotnwonksidnakuehtniesabtnenamreponsahhacilbuperramiewehtnignisilaicepseciffoeporueruonievitarepodaelaneebsahehsselliasrevecnisadnagaporpdnaegatobasgnitanidroocelihwsnoitisopsidpoortnostroperelbaulavdnaralugerdedivorpehserehwecnarfniseitudotdengissaersawehstcilfnocehtfokaerbtuoehtnotnavelehtniesitrepxerehfoesuaceboriacotdengissayllaitinisawdnarawtaergehtfokaerbtuoehterofebhtnomenonoitasinagroehtdeniojhaecnaraelcrehfoweivercidoirepdradnatsasisihtevobadnatercespottasseccallufsahdnasesacrojamnohhtiwylevisnetxedekrowsahehsasuehtdnakuehtnisnoitcennocgnortshtiwytinummocecnegilletniehtforebmemdedragerllewasihatnegaiiixxxmcmenujyrammusdleifhgihahtagaetadpugnittev\n" + ] + } + ], + "source": [ + "word_b, score_b = vigenere_frequency_break(scb, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = vigenere_decipher(scb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "595593e0-9b09-4ef8-974f-9969ff327941", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "vetting \n", + "\n", + "vettingupdateagathahighfieldsummaryjunemcmxxxiiiagentahisawellregardedmemberoftheintelligencecommunitywithstrongconnectionsintheukandtheusashehasworkedextensivelywithhonmajorcasesandhasfullaccessattopsecretandabovethisisastandardperiodicreviewofherclearanceahjoinedtheorganisationonemonthbeforetheoutbreakofthegreatwarandwasinitiallyassignedtocairobecauseofherexpertiseinthelevantontheoutbreakoftheconflictshewasreassignedtodutiesinfrancewheresheprovidedregularandvaluablereportsontroopdispositionswhilecoordinatingsabotageandpropagandasinceversaillesshehasbeenaleadoperativeinoureuropeofficespecialisingintheweimarrepublicahhasnopermanentbaseintheukandisknowntospendsignificantperiodsinafricaandasiaattheendofhermostrecentmissionshetookawalkingholidayinindiastayinginmassourieshehasfewfriendsandalifestyleconsistentwithherknownresourcesbothonandbetweenoperationsonherrecentreturntotheukahtookanapartmentingreenwichwheresheliveduntilhercurrentmissioningermanybeganshehadasmallnumberofvisitorsduringthisperiodincludingchadwickcockroftandthehungarianscientistszilardpresumablythisiswhatledtoherlatestinvestigationdiealchemistenwhichwaslaunchedatherowninitiativebeforeleavingformunichahdraftedapaperrecommendingthelaunchofanewbranchoftheagencydedicatedtoforwardplanningshenicknamedthisgroupthelamplightersthestatedaimwastopreparelongrangereportsoutliningfuturethreatsinordertoforestallthemtheproposalwasrejectedbytheforeignsecretarywhoregardeditasunlikelytosucceedinitsstatedaimsandverylikelytodistractfromthemoreimmediatethreatposedbyfacismtherearenocurrentgroundsforconcernbutasamajorassettheclearanceforahshouldberevisedbiannually\n" + ] + } + ], + "source": [ + "word_b, score_b = vigenere_frequency_break(rscb, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = vigenere_decipher(rscb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "fe094361-7c85-40d9-952e-0c84abbcf903", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "vetting update agatha highfield summary june mcm xxxiii agent a his a well regarded member of the\n", + "intelligence community with strong connections in the uk and the usa she has worked extensively with\n", + "hon major cases and has full access at top secret and above this is a standard periodic review of\n", + "her clearance ah joined the organisation one month before the outbreak of the great war and was\n", + "initially assigned to cairo because of her expertise in the levant on the outbreak of the conflict\n", + "she was reassigned to duties in france where she provided regular and valuable reports on troop\n", + "dispositions while coordinating sabotage and propaganda since versailles she has been a lead\n", + "operative in our europe office specialising in the weimar republic ah has no permanent base in the\n", + "uk and is known to spend significant periods in africa and asia at the end of her most recent\n", + "mission she took a walking holiday in india staying in mass our ie she has few friends and a\n", + "lifestyle consistent with her known resources both on and between operations on her recent return to\n", + "the uk ah took an apartment in greenwich where she lived until her current mission in germany began\n", + "she had a small number of visitors during this period including chadwick cockroft and the hungarian\n", + "scientist szilard presumably this is what led to her latest investigation die alchemist en which was\n", + "launched at her own initiative before leaving for munich ah drafted a paper recommending the launch\n", + "of a new branch of the agency dedicated to forward planning she nicknamed this group the\n", + "lamplighters the stated aim was to prepare long range reports outlining future threats in order to\n", + "forestall them the proposal was rejected by the foreign secretary who regarded it as unlikely to\n", + "succeed in its stated aims and very likely to distract from the more immediate threat posed by\n", + "facism there are no current grounds for concern but as a major asset the clearance for ah should be\n", + "revised biannually\n" + ] + } + ], + "source": [ + "pb = vigenere_decipher(rscb, word_b)\n", + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1967" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge6.md b/2021/2021-challenge6.md new file mode 100644 index 0000000..34a691c --- /dev/null +++ b/2021/2021-challenge6.md @@ -0,0 +1,114 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.support.text_prettify import * + +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +import collections +%matplotlib inline +``` + +```python Collapsed="false" +challenge_number = 6 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +rsca = cat(reversed(sca)) +scb = sanitise(cb) +rscb = cat(reversed(scb)) +``` + +```python +sca_counts = collections.Counter(sca) +sca_counts +``` + +```python +pd.Series(sca_counts).sort_index().plot.bar() +``` + +```python +key_a, score_a = railfence_break(sca, fitness=Ptrigrams) +print(key_a, '\n') +pa = railfence_decipher(sca, key_a) +print(pa) +``` + +```python +(word_a, fill_a, empty_a), score_a = column_transposition_break(sca, fitness=Ptrigrams) +print(word_a, fill_a, empty_a, '\n') +pa = column_transposition_decipher(sca, word_a, fillcolumnwise=fill_a, emptycolumnwise=empty_a) +print(pa) +``` + +```python +transpositions_of('deacb') +``` + +```python +transpositions[word_a] +``` + +```python +print(prettify(pa)) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +word_b, score_b = vigenere_frequency_break(scb, fitness=Ptrigrams) +print(word_b, '\n') +pb = vigenere_decipher(scb, word_b) +print(pb) +``` + +```python +word_b, score_b = vigenere_frequency_break(rscb, fitness=Ptrigrams) +print(word_b, '\n') +pb = vigenere_decipher(rscb, word_b) +print(pb) +``` + +```python +pb = vigenere_decipher(rscb, word_b) +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.6a.txt b/2021/ciphertext.6a.txt new file mode 100644 index 0000000..7208ade --- /dev/null +++ b/2021/ciphertext.6a.txt @@ -0,0 +1 @@ +RMTUV ARSWC IAFDE LAUJM IHTFE LEHOM IOSOW NBHGT HENUS YGPSS AEHHS SCOSA ECETI EBEHS REIOD OLTMA RENIN CIUTO MRNHI ESTFN NFEHY HIHSO TIHHE EIIMI ROKTG TETIR NNUTS GVNBE TMONI IFUTT INTET UYRNL NTRRR TEGAN EETNA RTAWA GTTAK HERND TDWDP CITPH NARVU NHNAR DILCR CFEIB TATEN AWIRE ERGSK RTNOS EGRUR ARHME ESANS ILCEB TSBGI DTAMA HIEST NNHEE TFNGN SSMOR BHHTN THWRE NIEEY NCTUD REEMB EACCU RIATC ORAOA SUYTT RTEUN TIIRH ORPIE NCTHE OIUTT ETAHO NNWNY ODISO HNLHC IRISD GOOLH WEONI CRGOH ETHYU YTEIO UADYU ITRDO KHAWO IUATC ODNEC NETSK VSSIV MARHS VAARO ALYHH OHEEO LHCIO REEID TAHER UDEOR YPTST HRSAD EATNA DAEET IETOI YEMNE ITUTE QIWEN RILCH TAEER ARAAO STITT GHETB DETIN EHEEA ICOGH AVNMF ETUIE AAHRK HYTHT ENEPD SSSRE NYONB EUHAA YSAOG ERDTP ORTOW HRIST GSEIR RHSAS ETFSS GHRTH HRCWE IMUEE SLTTA SCPIE CTCYS ABGEH BWTCI FNMMS EAILE DOTEE ENICO RLTUS REIOA SSCHE TTIHW ATFNG HGMHO DTHAM IOITH ERNSD HEIPA NLRDG EWSDS ETTTU AEFAE GHELN MBNIH AWNVA GIBUT GUNAI KOHON OSVTU TPIPS SDSEM UUDOI SEYSE ERSHS ERYIT HEGRB CETDU EVEEH TAEAA ESLOW OTAAS HADTA ATTRT HMRET EPYUH NRENH GDEBE RTTTU ISETE NEAVG GORNH DEYGE LSLLF TIWWA BASET FHDAE LNTNE MITBH HHCOF EYGGT HHEAL NHENT LSLTI WNTTD IMAHI RWHME EEETB SSNHA PEETA SEHAS NERDD TRYAI ECNHO EOPFE RMSSS UANIE CAOBS AHIHS OTANT AOTTT ADHTF OGEEI ETEIE UNRRG ETEHS ASTAE NUOSI NECVT HFCEL NHFCI DUSAO OOIET DHTEN NTNNN GWHET IENTI ETCIE GHADO HITKU IILTH TEHEB CENGE ANYLS NIAHR ORLGT HFOTT IGTEO IARNP NEDIO ORSNH CEWTS AIDAS TIIEU ENIOO LSHLK LSRIH IRSBY FUNAR AOETN TLUGT NOTRE TWESH NEENK AIIIT LECLA IAVAI MFIOO RFSIX EASTT LATOF TIGAS IHEIW LYSTH SCETN VHNMA NGDRE GVTWT RSUOH YTENI EUHNI DACOG SREHS HOEAM HEOAN NTDER DGNET SECEG ATRIN TGNSU SIELO EORDR OTHAE OTIOW EODSA GSTAR RTRTI RERFE NHEET AEEOI RTIES TEQIW HDFET HIAUH AMOAR OVTTR HNNAW WSHHU FORAE EABAR EDRDA ABRNS UDEPO DREET CRYEE TILRA UNTCE ETHUV ARBHF CIIHO AIEHP PRNMN FEOTE HSAVN OSDEY UANIE VITII BSTWF WIEAY EWIEG VARTG OISCY SHHSS TTWUA UPCOE CPROO HUTOA XEGCT MNEAB QJAAE MEHOA OTLSD NWTHO REGTN OLRWE TUEVD HDOTS NDCIS TYNNT ETSBT GUNAC ESPNG OMBIT SEEHN RNPBA ACERI TIEPY RCAEI TAKAH IEAII TATAT ENYDS TTGWS ETTTC KUARD EEAIS STIAE UGOGI IFAAB ODHIA HTSRE IAIHE TUNSN BONWN UPSRH EPNNI CUSVA AETEA OPADO ESDEA OOETE WCENL NUNOH TMYRS UOHEO OYHEN TCOSE NSIRE BAEED AMHAE IERIF LBIMT ASODE OITTY EDIET VMFIE NASES BWATN EINGD EIINE CRETO OEEEN STRNN NOESE GUTOS FREOA TEGRB OEPSV ETCEM WMOEE TMFHS STRCH GGOET ERTIS UITAE TEPOH ELNRR OISHT ASNEG YTMTT HOREG LPIUO diff --git a/2021/ciphertext.6b.txt b/2021/ciphertext.6b.txt new file mode 100644 index 0000000..f836274 --- /dev/null +++ b/2021/ciphertext.6b.txt @@ -0,0 +1 @@ +LTETY ITNQU WINOI MKXFY RHWAL LVXBN XVRVX NMEVI CZGML LEMUW IFTWV ZHJGK IXTBK KHJNJ ACHKK OTRZK NGJTR ZTXVZ NGULB GVLLJ WXWJV GIXKL OKGIB WIHSV MKHQZ NGUHK JOINZ MLMYU GGEXO DRLZX OHIGF UBTHZ ZNBLL XDTVL XXGXA FWMRP ZQVTG NWVZV LXWVV MRZHA ATXNB XKGZY AOBXV JLRPM RFYKG KXCIM YNEET WJVBZ IXLOS RPMEP VZFMK HJJZE MWKSI OFBTX VCZRZ NMYAM AQGBP OABAM KSKKE MZGEM MAWEX VVVRZ IHXNG JUBTH ZZNBL XLOYE MMAKD RCUTE ICZCC HKKNO UBWXQ VTXKB GICYT VBGRV RCLKT AMUSW MWIOG PQWXH TIAMZ TICZS WAVRV XOEXG EAUUK GNEGK UBZGM YTRUF HGZXE MITTV JRBYT VYNNP VBRPS EWYZR DBNME XVJLR JXOMO GVBBG MICBZ XAXVJ RPVGY VRFIP AGDNJ VXMWD SRPVE EZOQV HBXVM VBLXZ IOGAX MEGXR PHMHZ RGIAP WDYVP MRPWG ZCLXV KJEIE BDNZF QMGID IFVTB VVMAC AXLOJ AIMYS MQPWV DGDCQ IAVKI OQCEV RDJBQ KXTNO UBZGM MAQAK HXDYV DYHVZ HZCGE PVSFI WTLZN FVTZI WEAIF KIBTV VHBWN OZBGX VMAPZ XAPDZ ACWXZ DRRPL XVZNJ PVBAI KRZZG MOTRU MKEKG AIDHS ONNSN XLOUG VKNXZ XGVXV IMXRP GHWIU VBTKI KUAMX PXZHQ VTGSC ZBJLX GMABA XKRRU ASKXL CZVEM GIOYV AGHGZ RLBLX JDRNL GTWYT RQKYA ZLFIA XLNKV ZNHWN GZVBZ RDENB LTMYT VVBRE YOYWA ZRDQY IPTOJ UGMAL RJOFA BFXIK PMKMW JSEMA YSYTR MAMXV GVATW RVGPQ KYEIO FLHBV ZVGVT VMAOA OBLHI KCAHM RRUAS LBHIG XCXAX IORAT UXIKA IFKIK UAATA LVIVT UNTZX EIFBI RKUBG BKIOF QETMX KCAXV MALBM IHVPK ECHGM ZBVBT KIKUQ IXEEI KRJLT LZNFA XEPDG FZXOI XTVAT WRVMN XHKTY TNMZT XJHNA ZGMOG AQWKS JIRTB AANTB QMBWJ VFQWI SJXGV HLXMU CMKXP WGHTT OHIGE IENKZ XQMWB ZJXCM ALIMK UEXVR VXSVB LIDZH LHMHZ TTQLL EZXFI PXLNZ PQEYR JIRPM YSFGR ZUMYJ KUBGH XIGIM EXLOT VMLBX MKCFX KICLB MLNEX KOWKB EXUGL XGKDY FIREP VOGQG BWVCQ VTKER ZNMKZ ICZSW DTIMH GCHXL OKEWY XFCZA WFXRJ TBQMT WDTNO KHICZ QMGBS ENNMV GEMGR TVKIC LBEXB ZZXPQ WHMMK CLKTH IGGAT LMNOU BXOSW GQVTM IMIRA IHXOG FAXVG VRYCY LECJA ILXWV IEWCT QIUUP MBATR RDBLR ZZKMW XOMUJ ATAIC YNANX LOJAI DNICZ AQLGS DZPMG GSXMA WKMWC ZVERM MIAZU HVIXT ROBEP ZZAQX AXAUE MUFIH JRLKT KZXYT XPENO UIMGI BGVQB QBSSP UXGYE EEIFF YNJYM BYLBO UIAME BGRBT WTPMA QMMIQ diff --git a/2021/plaintext.6a.txt b/2021/plaintext.6a.txt new file mode 100644 index 0000000..4ee8ace --- /dev/null +++ b/2021/plaintext.6a.txt @@ -0,0 +1,26 @@ +harry i am sure this must be very hard for you as i know that charlie was a good friend but we cant +let that cloud our judgement given the content of her letter last week we have to assumes he is +involved somehow and work on that basis having said that charlie doesnt actually say anything that +proves that she is a member of the lighthouse conspiracy of course she is an experienced agent so +that might be deliberate but she does refer to the trinity group and its possible that the americans +were already investigating the conspiracy under that codename everything in the email takes on a +slightly different meaning if we view it that way but that raises the question of why they didnt +share the intelligence with us in the meantime i tried to trackback through agatha s record to see +if there is anything to suggest that she might have been a double agent nothing mentioned in the +file raised a flag but i noticed two things in the attached vetting summary after her initial run in +with the german treasure hunters seeking the babylon stone she went on the run and papers reported +that she was a passenger on the titanic as you know she never boarded and used that tragedy as away +to disappear according to the report she did not reappear for over fourteen months when she was +recruited as an intelligence source in cairo for the british embassy that raises the question of +what she was doing for the year the other thing that struck a chord was the mention of mass our ie +george everest built a retreat there and his name came up when i was researching the security files +of charles babbage it seems that babbage was introduced to ideas from indian mathematics by everest +and this influenced the development of the difference engine and its successors mary boole wrote +about this in her letter indian thought and western science in the nineteenth century given what ch +wrote about the difference engine this might be more than a coincidence though perhaps i am reading +too much into it for the sake of our trainees i should say that the vetting report has been double +encrypted using avi genere with a second very simple twist i mention it because that threw me off +for a while i suggest that they reflect on what might be going on given that we are now trying to +avoid raising suspicion by the us and the lighthouse conspirators i think we should change our own +protocols so i have switched up to a transposition cipher i suggest you do the same next time though +you could try something else like a polybius square jodie \ No newline at end of file diff --git a/2021/plaintext.6b.txt b/2021/plaintext.6b.txt new file mode 100644 index 0000000..2a7c883 --- /dev/null +++ b/2021/plaintext.6b.txt @@ -0,0 +1,21 @@ +vetting update agatha highfield summary june mcm xxxiii agent a his a well regarded member of the +intelligence community with strong connections in the uk and the usa she has worked extensively with +hon major cases and has full access at top secret and above this is a standard periodic review of +her clearance ah joined the organisation one month before the outbreak of the great war and was +initially assigned to cairo because of her expertise in the levant on the outbreak of the conflict +she was reassigned to duties in france where she provided regular and valuable reports on troop +dispositions while coordinating sabotage and propaganda since versailles she has been a lead +operative in our europe office specialising in the weimar republic ah has no permanent base in the +uk and is known to spend significant periods in africa and asia at the end of her most recent +mission she took a walking holiday in india staying in mass our ie she has few friends and a +lifestyle consistent with her known resources both on and between operations on her recent return to +the uk ah took an apartment in greenwich where she lived until her current mission in germany began +she had a small number of visitors during this period including chadwick cockroft and the hungarian +scientist szilard presumably this is what led to her latest investigation die alchemist en which was +launched at her own initiative before leaving for munich ah drafted a paper recommending the launch +of a new branch of the agency dedicated to forward planning she nicknamed this group the +lamplighters the stated aim was to prepare long range reports outlining future threats in order to +forestall them the proposal was rejected by the foreign secretary who regarded it as unlikely to +succeed in its stated aims and very likely to distract from the more immediate threat posed by +facism there are no current grounds for concern but as a major asset the clearance for ah should be +revised biannually \ No newline at end of file -- 2.34.1 From bf4dff6375d2b1e7757a51a4c19402eacb30b903 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 25 Nov 2021 17:03:27 +0000 Subject: [PATCH 14/16] Done challenge 7 --- 2021/2021-challenge7.ipynb | 547 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge7.md | 144 ++++++++++ 2021/ciphertext.7a.txt | 1 + 2021/ciphertext.7b.txt | 1 + 2021/plaintext.7a.txt | 20 ++ 2021/plaintext.7b.txt | 25 ++ 6 files changed, 738 insertions(+) create mode 100644 2021/2021-challenge7.ipynb create mode 100644 2021/2021-challenge7.md create mode 100644 2021/ciphertext.7a.txt create mode 100644 2021/ciphertext.7b.txt create mode 100644 2021/plaintext.7a.txt create mode 100644 2021/plaintext.7b.txt diff --git a/2021/2021-challenge7.ipynb b/2021/2021-challenge7.ipynb new file mode 100644 index 0000000..967060a --- /dev/null +++ b/2021/2021-challenge7.ipynb @@ -0,0 +1,547 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.vigenere import *\n", + "from szyfrow.polybius import *\n", + "from szyfrow.support.text_prettify import *\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import collections\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d9dd1b5e", + "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": 7, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "nca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "numtrans = ''.maketrans('12345', 'abcde')\n", + "ca = nca.translate(numtrans)\n", + "\n", + "sca = sanitise(ca)\n", + "rsca = cat(reversed(sca))\n", + "scb = sanitise(cb)\n", + "rscb = cat(reversed(scb))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'e': 632, 'c': 619, 'a': 714, 'b': 410, 'd': 787})" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sca_counts = collections.Counter(sca)\n", + "sca_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD1CAYAAACrz7WZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAARfklEQVR4nO3dfYxd+V3f8fcnduKQ8BCbHRtje2MjTRe8EXnQ4GwbHmNgjdLiBWE0EaQW3ciV6pTwIBW7qhSCNNL+AYgHsUgWoR0eGmsIbNciUhpjiCIgiTOb3TSxN9ZO4409sWsPIYFAFQcv3/4xZ+sb7x3PtWeur/Pz+yVZ55zv+Z1zv3Nkf+7xmXPuTVUhSWrLi0bdgCRp9RnuktQgw12SGmS4S1KDDHdJapDhLkkNWjvqBgDuueee2r59+6jbkKSvKk888cTfVNVYv3V3RLhv376d2dnZUbchSV9VknxmqXVelpGkBg0U7kl+NsmpJJ9M8u4kL02yIcnxJM900/U94w8nmUtyJsmDw2tfktTPsuGeZAvw08BEVb0KWANMAoeAE1U1Dpzolkmys1t/P7AHeDTJmuG0L0nqZ9DLMmuBr0myFngZcAHYC0x366eBh7r5vcDRqrpSVWeBOWDXqnUsSVrWsuFeVZ8Ffhk4B1wE/q6q3g9sqqqL3ZiLwMZuky3A+Z5dzHc1SdJtMshlmfUsno3vAL4ZeHmSn7zRJn1qL/joySQHkswm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V95nb1ojtPktcB39UtfrCqnhxlP6PUXbrdzeKb/omqenrELS3JcJekBnmfuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSg/4fZamgIRhtg7UAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(sca_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "583312cf-a973-4671-9ba8-85fe10cb9e00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(('alchemy', , 'abcde', 'abcde', False),\n", + " -6776.263168839725)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_a, score_a = polybius_break(sca, column_labels='abcde', row_labels='abcde',\n", + " fitness=Ptrigrams)\n", + "key_a, score_a" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "4262216b-efed-491e-ade1-d7e8dffe4454", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'wemounhtbeattacbehkessayebdhhendntbeunherizdnycoheomandkayesentdnfungkaditopeopieattbeuseklasszdtkdybtbavesidppehpastuslutiucgdizbarrzanhdbahaireahzmdyurehouttbattbezkdybttrztocokkundcatetbdswaztbeconspdraczbahavodhehhetectdonmoroveracenturzsotbezwereunidgeiztokagetbekdstageomsenhdnykessayesexpidcdtizahhressehtooneanotberdtdsaiwazslestnottokageidngsletweenkeklersomanetworganhaweiibdhhenkessayednfungkadiavodhstbatrdsgespecdaiizdmdtdswdheizhdstrdlutehlzoneomtbelotnetworgsidgetbdsonedwastoomocussehontbehecrzptatmdrstanhwasntreahdnywbatdtsadhuntdidmounhbernakestardnylacgatkeattbeenhperbapswesbouihbaveaireahzreaidsehtbattrdndtzcouihlednvoivehlutdtneveroccurrehtoketbatbernakewasanztbdnyotbertbanacodncdhencetbemactsbescbaridesndecesbouihbaveidtuptbeidybtsontbehasbloarhtbouybanhdakworrdehtbatbarrzhdhntradsedtperbapsbedsaireahzsbahowdnyberanhhdhntidgetosazsooutomiozaitzlutbehdhntteiiketbatanhsokebowdtbdngbewouihdtbdngdtskoreidgeiztbatsbeslezonhsuspdcdondnbdskdnhsbebaspiazehandkportantroiednbdsnetworgmormourteenzearsanhtbemacttbatsbekdybtleahoulieayentwdiileareailiowtbatwaslahlutdtwasnttbeworstomdttbehetaditrdndtzydvesontbeconspdraczsrecentactdvdtdesdstruizmrdybtendnywbatcouihtbezwantattbebeartomtbepanhekdcresponseyroupssureiztbezcantbaveleenresponsdliemortbeoutlreaganhwbatweretbezhodnyatcopdhesperateizwanttotagetbdstobarrztotaigtobdkaloutdtluttbemdnaiparayrapbstoppehkednkztracgswbzoneartbhoestrdndtztbdngdkdybtfodntbekwbatbavedsadhorhonetbatwouihkagetbektbdngdcouihleatradtoranhwdiitbatkagebarrzhdstrustketoodknotsuredcantagetbatrdsgdkdybtbavetomdndsbtbdskdssdonaione'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_a, wrap_a, col_a, row_a, col_first_a = key_a\n", + "polybius_decipher(sca, keyword=word_a, column_order=col_a, row_order=row_a,\n", + " column_first=col_first_a, wrap_alphabet=wrap_a)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "bbe56403-8038-4659-9f3d-7056ef60e665", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'xefpvoduheauuachednettagehiddeoiouhevodesmziogcpdepfaoinageteouiokvolnaimupqepqmeauuhevtenbattziunighuhawetmiqqedqatuvtbvumvclimzhasszaodihadamseadzfigvsedpvuuhauuheznighuuszupcpnnvoicaueuhitxazuhecpotqisaczhadawpideddeuecuipofpspwesaceouvsztpuhezxesevomilemzupnaleuhenitualepfteodiognettageteyqmiciumzaddsetteduppoeaopuhesiuitamxaztbetuopuupnalemioltbeuxeeonenbestpfaoeuxpslaodaxemmhiddeonettageiokvolnaimawpidtuhausitletqeciammzifiuitxidemzditusibvuedbzpoepfuhebpuoeuxpsltmileuhitpoeixatuppfpcvttedpouhedecszquaufistuaodxatouseadiogxhauiutaidvouimifpvodhesoanetuasiogbaclauneauuheeodqeshaqtxethpvmdhaweamseadzseamiteduhauusioiuzcpvmdbeiowpmwedbvuiuoewespccvssedupneuhauhesoanexataozuhiogpuhesuhaoacpiocideoceuhefacuthetchasmietoiecethpvmdhawemiuvquhemighutpouhedathbpasduhpvghaodianxpssieduhauhasszdidousaiteiuqeshaqtheitamseadzthadpxioghesaoddidoumileuptaztppvupfmpzamuzbvuhedidouuemmneuhauaodtpnehpxiuhiolhexpvmdiuhioliutnpsemilemzuhauthetbezpodtvtqicipoiohitniodthehatqmazedaoinqpsuaouspmeiohitoeuxpslfpsfpvsueeozeastaoduhefacuuhauthenighubeadpvbmeageouximmbeaseambmpxuhauxatbadbvuiuxatouuhexpstupfiuuhedeuaimusioiuzgiwetpouhecpotqisacztseceouacuiwiuietitusvmzfsighueoiogxhaucpvmduhezxaouauuheheasupfuheqaodenicsetqpotegspvqttvsemzuhezcaouhawebeeosetqpotibmefpsuhepvubsealaodxhauxeseuhezdpiogaucpqidetqesauemzxaouupualeuhituphasszupuamluphinabpvuiubvuuhefioamqasagsaqhtupqqedneionzusacltxhzpoeasuhdpetusioiuzuhiolinighukpiouhenxhauhaweitaidpsdpoeuhauxpvmdnaleuhenuhiolicpvmdbeausaiupsaodximmuhaunalehasszditusvtuneuppinoputvseicaoualeuhausitlinighuhaweupfioithuhitnittipoampoe'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xca = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a,\n", + " column_first=col_first_a, wrap_alphabet=wrap_a)\n", + "xca" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "81c5bc01-b60b-4d26-9f19-231854f4f6de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'abcdefghiklmnopqrstuvwxyzj'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_a, _ = monoalphabetic_sa_break(xca)\n", + "word_a" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "7aa6dff2-f12c-4212-83df-3a9bb7b76334", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'wefoundtheattachedmessagehiddenintheunderlyingcodeofanimagesentinjunkmailtopeopleattheusembassyitmighthaveslippedpastusbutluckilyharryandihadalreadyfiguredoutthattheymighttrytocommunicatethiswaytheconspiracyhadavoideddetectionforoveracenturysotheywereunlikelytomakethemistakeofsendingmessagesexplicitlyaddressedtooneanotheritisalwaysbestnottomakelinksbetweenmembersofanetworkandawellhiddenmessageinjunkmailavoidsthatriskespeciallyifitiswidelydistributedbyoneofthebotnetworkslikethisoneiwastoofocussedonthedecryptatfirstandwasntreadingwhatitsaiduntilifoundhernamestaringbackatmeattheendperhapsweshouldhavealreadyrealisedthattrinitycouldbeinvolvedbutitneveroccurredtomethathernamewasanythingotherthanacoincidencethefactshescharliesnieceshouldhavelitupthelightsonthedashboardthoughandiamworriedthatharrydidntraiseitperhapsheisalreadyshadowingheranddidntliketosaysooutofloyaltybuthedidnttellmethatandsomehowithinkhewouldithinkitsmorelikelythatshesbeyondsuspicioninhismindshehasplayedanimportantroleinhisnetworkforfourteenyearsandthefactthatshemightbeadoubleagentwillbearealblowthatwasbadbutitwasnttheworstofitthedetailtrinitygivesontheconspiracysrecentactivitiesistrulyfrighteningwhatcouldtheywantattheheartofthepandemicresponsegroupssurelytheycanthavebeenresponsiblefortheoutbreakandwhatweretheydoingatcopidesperatelywanttotakethistoharrytotalktohimaboutitbutthefinalparagraphstoppedmeinmytrackswhyonearthdoestrinitythinkimightjointhemwhathaveisaidordonethatwouldmakethemthinkicouldbeatraitorandwillthatmakeharrydistrustmetooimnotsureicantakethatriskimighthavetofinishthismissionalone'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pa = keyword_decipher(xca, word_a)\n", + "pa" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "we found the attached message hidden in the underlying code of an image sent in junkmail to people\n", + "at the us embassy it might have slipped past us but luckily harry and i had already figured out that\n", + "they might try to communicate this way the conspiracy had avoided detection for over a century so\n", + "they were unlikely to make the mistake of sending messages explicitly addressed to one another it is\n", + "always best not to make links between members of a network and a well hidden message in junkmail\n", + "avoids that risk especially if it is widely distributed by one of the bot networks like this one i\n", + "was too focussed on the decrypt at first and wasnt reading what it said until i found her name\n", + "staring back at meat the end perhaps we should have already realised that trinity could be involved\n", + "but it never occurred to me that her name was anything other than a coincidence the fact shes\n", + "charlies niece should have lit up the lights on the dashboard though and i am worried that harry\n", + "didnt raise it perhaps he is already shadowing her and didnt like to say so out of loyalty but he\n", + "didnt tell me that and somehow i think he would i think its more likely that shes beyond suspicion\n", + "in his mind she has played an important role in his network for fourteen years and the fact that she\n", + "might be a double agent will be a real blow that was bad but it wasnt the worst of it the detail\n", + "trinity gives on the conspiracy s recent activities is truly frightening what could they want at the\n", + "heart of the pandemic response groups surely they cant have been responsible for the outbreak and\n", + "what were they doing at copi desperately want to take this to harry to talk to him about it but the\n", + "final paragraph stopped me in my tracks why on earth does trinity think i might join them what have\n", + "i said or done that would make them think i could be a traitor and will that make harry distrust me\n", + "too im not sure i can take that risk i might have to finish this mission alone\n" + ] + } + ], + "source": [ + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1953" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "07c92adb-74e2-476e-adff-887c0145617d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'10101 11000'" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cb[:11]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "832dc153-c9e3-4134-9425-8014847c3870", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "21" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int('10101', 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "d7002750-66fd-4435-8ee8-023ae8376f33", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9865" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scb = cat(c for c in cb if c in '01')\n", + "len(scb)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "f3c2587e-7b76-49fb-ba60-ed3efc148c85", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 25)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ncb = [int(g, 2) for g in cb.split()]\n", + "min(ncb), max(ncb)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "bf189676-3c25-420d-9330-b77cc57c7a82", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'vyietbcbuwabmfbeslwnqafcylayovkbuxrhcwalhlpvknvmpbjszmxrbeonvwwhlznzkgortuilzxvvawmgvvlogumljprqzfmvvvvzqnjxvkbmgyiezrqmvizqlyvkqimewbedramgzrbvvzmniweotlbjigqhlteljmayovbblhcovzlbaggxerktlmfxhbmfxdwsnmfxjkrvmsgwwebnltkmygbkpfzxqgepzbudxprtwaamptzvrlkclfcekxqwvacqmctctbckntelrubaiimcikymzwaabraraomxlarzqehpdfdrzmfxcifbxgzybrmgkhebuatqiciavxbpvcfmwravkeqlglkwruucwdwemhnxiigqoclrbgpxfxrzgwyehmmevfcgklrkbqbfvzidggxcalxpmympwockfnfizctelgpxmmymevxuvfuzqmrxvajmgmpyiimtlxkebzdmyjkvmgrbjbfigbxeovvxckjqaeagmvpnteubkpgpxbbimpbxykfnfmgghikvdbjlvziigrlrvqxhjbkqpqtllkprgtjlfprticwlagwblyztgztrxtwcobtbeohawgkvkgivaxjagwtlndjrzhdhkprzzmovzauxlmjbuimftuzrutggvlomrmguwhzkcttpjpbjxnmjmkcgfbnjecmfnhtewwvtvdxphewhzijteaswkrarbrdxlmkprkhlgvkgqhllnmziwcpzbuahkxfngpxuhitqaeykxmfbvmfgiaqxqtelfutjevagamymvajqejllzrtrntpwsnblmymzmwgndbrzfmgkprlhugjqqmbftmmabaywkprktnttqggblxvlgwpmkbwabacufafqgtxjbvotrbfvvvmmhlzbzzygzanbbmgkpnbbquvqaoksgwzbumfxrzpptchcwtgwgozavwgfximnbzaahquiwfhgmqbaymrafqzlfvvguxygkbuimravknaxutjzrotpwvlnaempgzvwkgmpjhbaykignalgzemqpbquvagizcgkrblbcmfzhvbrteltiocavzntfmlkcatbkbkmqzxqhlzpmlqavpnamctdanteyviwfamfxlsgztuezvtbaphloubacirxrzluxcmsbucazvqimravtvoarafcfmtlwkzlqgemfebzdmnkeuimravgzmtlbrufwtlzignbfwlvtsnhpmyigjnrbyiimickjwaiejrtprkdcwrvqiejmymzicmkzbruldkfugpxdhlvqimgheiekagoverzxqazxcmwmnkbbutqlfceqxygupndxzxvvfmvskvlnbmfxgiesbyljqtvxbtkmnummfrsranpxkpnbmfxbmllhandmabluximczhnxitlmgakpxgmwggtifmcmwzmfbxyfwqallravuocmebmmabacmrtrvmqavqfehpdzvtebrazvbemfbesjmfgzybamxbmfbnsxdnibumkqmvxfigbbgtnvmmozavbmfxyynalmheifqvygxmgipyrnprbackfzawmhhuqrigbavzgmtkpfzxwnrpyigexykvlbqgemymomlrprggwfydvahzxrarbuikpruwragmmwqalhsmdqtpmzxkwpwgtbekrpxpgfbgwmcecpvubftmmomxlvrzegblzfcgahkxsipszphlvqkacvbanvwgtdebvwckzvtqyuxjpbcebclagbkwmfzrkksbkprzwgkvkgtrgyjpretqpfzxqgepzbuclravvvulskvaumpmnclfmxravvrmwdhiarkkcvpbumwgkvkgiinkfippbqkzaxgusmkprwketeqfimghepnagcovzfpbcwrengyphdbuimzxwwemhprfcnvwgpfcylgruvebzdggxnbzbrbkpvvdgmzanzbqdnwebartbqaormnitbdblzeqrkxrkzvvbr'" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tcb = cat(unpos(n) for n in ncb)\n", + "tcb" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "59f072b0-f8ca-4f08-922d-cfb5dfc68fe4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'beuxmwnprjiztavlsfgkqdyhco'" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_b, score_b = monoalphabetic_sa_break(tcb)\n", + "word_b" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "16210c33-3bcb-43c8-9189-d82eea7cf53b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "trinity \n", + "\n", + "charlieidontthinkyoushouldhavecometolondonwecantriskmeetingandyourarrivalhasbeennoticedbybossheighteningsuspicionharrysteamisactivelyinvestigatingourorganisationandwehavetodoeverythingwecantoputthemoffthescentunfortunatelyimworkingwithveryconstrainedresourcesdespiteallourpandemicpreparationsithasbeenhardworkoverthelasteighteenmonthsasplannedweusedthecrisistoembedmoreoperativesattheheartofgovernmentdecisionmakingunderthecoverofsageandtheothernewcommitteeswenowhaveanetworkofscientistsandengineersinwhitehallwiththedirectearofseniorcivilservantsandpoliticianstheyalsohelpedustoinfiltratecopgivingusdirectaccesstoanumberofothergovernmentsthathadremainedbeyondourreachwhilewewerenotabletofullydeliveronourplansforthateventtheconnectionswemadewithsomeoftheworldslargestcompaniesandsmalleststateswillsurelypayoffinthemediumtermonthedownsideihaventhadthecapacityineedtoworkonthebossinvestigationintoourorganisationthatisbeingrunfromthearchaeologydivisionhereatgchqihadhopedthatassignmentmeantthatthecasewasregardedaslowprioritybutharryassignedhisbestagentjodietorunitandgaveheralmostunlimitedresourcesshehasteamsallacrosstheuktrawlingthroughthepapersweleftbehindatthelighthouseandtryingtoworkoutwhattheymeaniamsoangryatmyselfforthatbutihavepersonallycheckedandallthemajoritemsfromthefoundationarchivewereshippedouttomassourieandhavebeensecuredattheparkiassignedateamtomakesurethatthekeydocumentswereproperlyencryptedincasejodiesteamfindsthembutgiventhetalentsheisworkingwithinowthinkwemightneedtotakefurtherstepsandiplantovisitthehqassoonasicangetawaywhetherornotjodieandherteamworkoutwhatwearedoingthebestwaytomakesurethatharrydoesnotfindoutmightbetoconvincehernottotellhimihavebeencarryingoutsomebackgroundchecksandiamwonderingifweshouldjusttrytorecruitherdirectlyifshewasworkingwithusthenimsureshewouldseetheneedforsecrecythedirectapproachisriskybuttheorganisationhasnevershiedawayfromthatbeforeoryouandiwouldntbeworkingforitithinkitisariskworthtakingyourlovingniecetrinity\n" + ] + } + ], + "source": [ + "word_b, score_b = vigenere_frequency_break(tcb, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = vigenere_decipher(tcb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "fe094361-7c85-40d9-952e-0c84abbcf903", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "charlie i dont think you should have come to london we cant risk meeting and your arrival has been\n", + "noticed by boss heightening suspicion harry steam is actively investigating our organisation and we\n", + "have to do everything we can to put them off the scent unfortunately im working with very\n", + "constrained resources despite all our pandemic preparations it has been hard work over the last\n", + "eighteen months as planned we used the crisis to embed more operatives at the heart of government\n", + "decisionmaking under the cover of sage and the other new committees we now have a network of\n", + "scientists and engineers in whitehall with the direct ear of senior civil servants and politicians\n", + "they also helped us to infiltrate cop giving us direct access to a number of other governments that\n", + "had remained beyond our reach while we were notable to fully deliver on our plans for that event the\n", + "connections we made with some of the worlds largest companies and smallest states will surely payoff\n", + "in the medium term on the downside i havent had the capacity i need to work on the boss\n", + "investigation into our organisation that is being run from the archaeology division here at gchq i\n", + "had hoped that assignment meant that the case was regarded as low priority but harry assigned his\n", + "best agent jodie to run it and gave her almost unlimited resources she has teams all across the uk\n", + "trawling through the papers we left behind at the lighthouse and trying to workout what they mean i\n", + "am so angry at myself for that but i have personally checked and all the major items from the\n", + "foundation archive were shipped out to mass our ie and have been secured at the park i assigned a\n", + "team to make sure that the key documents were properly encrypted in case jodie steam finds them but\n", + "given the talent she is working with i now think we might need to take further steps and i plan to\n", + "visit the hq as soon as i can getaway whether or not jodie and her teamwork out what we are doing\n", + "the best way to make sure that harry does not find out might be to convince her not to tell him i\n", + "have been carrying out some background checks and i am wondering if we should just try to recruit\n", + "her directly if she was working with us then im sure she would see the need for secrecy the direct\n", + "approach is risky but the organisation has never shied away from that before or you and i wouldnt be\n", + "working for it i think it is a risk worth taking your loving niece trinity\n" + ] + } + ], + "source": [ + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2420" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge7.md b/2021/2021-challenge7.md new file mode 100644 index 0000000..56140fa --- /dev/null +++ b/2021/2021-challenge7.md @@ -0,0 +1,144 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.polybius import * +from szyfrow.support.text_prettify import * + +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +import collections +%matplotlib inline +``` + +```python Collapsed="false" +challenge_number = 7 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +nca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +numtrans = ''.maketrans('12345', 'abcde') +ca = nca.translate(numtrans) + +sca = sanitise(ca) +rsca = cat(reversed(sca)) +scb = sanitise(cb) +rscb = cat(reversed(scb)) +``` + +```python +sca_counts = collections.Counter(sca) +sca_counts +``` + +```python +pd.Series(sca_counts).sort_index().plot.bar() +``` + +```python +key_a, score_a = polybius_break(sca, column_labels='abcde', row_labels='abcde', + fitness=Ptrigrams) +key_a, score_a +``` + +```python +word_a, wrap_a, col_a, row_a, col_first_a = key_a +polybius_decipher(sca, keyword=word_a, column_order=col_a, row_order=row_a, + column_first=col_first_a, wrap_alphabet=wrap_a) +``` + +```python +xca = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a, + column_first=col_first_a, wrap_alphabet=wrap_a) +xca +``` + +```python +word_a, _ = monoalphabetic_sa_break(xca) +word_a +``` + +```python +pa = keyword_decipher(xca, word_a) +pa +``` + +```python +print(prettify(pa)) +``` + +```python Collapsed="false" +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +cb[:11] +``` + +```python +int('10101', 2) +``` + +```python +scb = cat(c for c in cb if c in '01') +len(scb) +``` + +```python +ncb = [int(g, 2) for g in cb.split()] +min(ncb), max(ncb) +``` + +```python +tcb = cat(unpos(n) for n in ncb) +tcb +``` + +```python +word_b, score_b = monoalphabetic_sa_break(tcb) +word_b +``` + +```python +word_b, score_b = vigenere_frequency_break(tcb, fitness=Ptrigrams) +print(word_b, '\n') +pb = vigenere_decipher(tcb, word_b) +print(pb) +``` + +```python +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.7a.txt b/2021/ciphertext.7a.txt new file mode 100644 index 0000000..596320b --- /dev/null +++ b/2021/ciphertext.7a.txt @@ -0,0 +1 @@ +53152 13551 34144 52315 11454 51113 23151 43315 44441 12215 23241 41415 34243 44523 15513 41415 43325 52434 22133 51415 35211 13424 33112 21544 15344 52434 25513 43133 11243 24535 41153 54132 15114 54523 15514 41533 12114 44455 24453 32422 23452 31152 15443 22441 41151 44111 44455 14412 51453 25113 31243 25523 11434 35511 34142 42311 14113 24315 11145 52124 22514 31514 35514 54523 11454 52315 55332 42223 45454 35545 35133 53333 51342 41311 45154 52324 44531 15545 23151 33534 44412 44311 13552 31114 11523 52414 15141 41545 15134 52435 34213 54335 52154 31113 15344 55143 55443 54523 15555 31543 15513 43224 31153 25545 35331 13115 45231 53324 44451 13115 35214 41534 14243 42233 15444 41122 15441 55441 32241 32445 32551 11414 43154 44415 14453 53534 15113 43545 23154 32445 24441 13253 11554 41215 44453 43545 45353 31131 15322 43431 44121 54553 15153 43315 33121 54344 35211 13415 45533 54331 11341 41153 15323 22324 14141 53433 15444 41122 15243 42551 34313 31124 32115 23524 14444 52311 45432 44431 15444 11513 24113 23255 24212 44524 44532 41415 32551 42444 45432 41251 45151 41255 35341 53521 45231 51235 45341 54553 35433 14432 24311 54523 24443 53415 24531 14445 35352 13513 51444 41514 35344 52315 14151 34355 41451 14521 24434 44511 34145 31144 34454 31511 14243 42253 23114 52445 44112 41451 34452 43224 21355 13414 23154 33411 33154 44511 43243 42212 11133 11145 33151 14545 23151 53414 41154 32311 41445 31544 23355 13214 23115 21511 32431 51114 55431 51132 24441 51445 23114 54543 24342 44555 13355 13214 12152 43452 35325 21514 12514 52445 34155 21543 35131 35143 43151 44535 33154 52311 45231 54334 11331 55311 44113 45545 23243 42235 45231 54345 23113 41113 35243 41324 14153 41315 45231 52111 13454 42315 44132 31143 32241 54434 24151 31544 23355 13214 23115 21532 24455 14145 23153 22422 23454 43534 45231 51411 44231 23511 43144 52335 51222 31134 14241 13353 35434 32415 14452 31145 23114 34355 14241 43445 43112 44415 24454 11543 23114 14423 15244 41132 43151 11455 44231 11435 53243 42223 15431 13414 14241 43445 32243 11545 35441 15544 35355 14535 21323 55511 32455 51251 45231 51424 14344 54515 32323 31545 23114 51134 14443 53315 23355 32445 23243 43123 15533 55132 14244 52324 34312 44544 33354 31532 24311 53255 45231 14544 23154 41215 55353 41444 51444 12413 24353 42434 23244 43324 34144 42315 23114 44132 11551 51411 34243 34135 43451 13445 43353 21524 34232 44434 15455 33543 31213 54321 35514 34515 15345 51511 43441 13414 45231 52111 13454 52311 45442 31533 24222 34512 15111 43551 12321 51122 15344 55324 32321 21511 43151 13212 32355 34523 11455 31144 12111 41251 45244 55311 44344 54523 15533 54344 45352 12445 45231 51415 45112 43245 43243 42445 55222 45215 44353 44523 15133 53444 41244 31113 55444 31513 15344 51113 45245 22445 24154 42444 45435 13255 21432 42223 45153 42434 22532 31145 13355 13214 45231 55553 11344 51145 45231 52315 11434 53521 45231 54111 34141 53324 13431 54441 35344 41522 43355 14144 44514 31532 55452 31555 13113 44523 11521 51215 15344 31544 41353 44424 12321 52135 43452 31535 51451 24315 11311 13414 53231 14553 15431 54523 15551 43524 34221 14513 35412 41415 44411 54311 45153 25553 11344 54535 45113 11545 23244 44535 23114 34355 45354 51132 31453 52324 33111 23551 45244 51251 45452 31521 24341 13241 11431 12243 11412 34445 35414 11514 33152 43433 55454 31113 31445 32355 35341 51143 45231 43515 44454 32434 24455 54523 24343 12433 24222 34525 35243 44523 15335 32311 45231 15215 24441 12414 35431 43534 15452 31145 53355 13214 33113 11545 23153 34523 24343 12413 35513 21412 15114 54311 24453 54311 34145 32432 32452 31145 33113 11523 11434 35514 24444 54351 44453 31545 35352 43334 35454 45143 15241 31134 45113 11545 23114 54324 44312 43324 22234 52311 52154 53521 24342 44423 45232 44433 24444 42435 34113 23534 15 diff --git a/2021/ciphertext.7b.txt b/2021/ciphertext.7b.txt new file mode 100644 index 0000000..f9291ae --- /dev/null +++ b/2021/ciphertext.7b.txt @@ -0,0 +1 @@ +10101 11000 01000 00100 10011 00001 00010 00001 10100 10110 00000 00001 01100 00101 00001 00100 10010 01011 10110 01101 10000 00000 00101 00010 11000 01011 00000 11000 01110 10101 01010 00001 10100 10111 10001 00111 00010 10110 00000 01011 00111 01011 01111 10101 01010 01101 10101 01100 01111 00001 01001 10010 11001 01100 10111 10001 00001 00100 01110 01101 10101 10110 10110 00111 01011 11001 01101 11001 01010 00110 01110 10001 10011 10100 01000 01011 11001 10111 10101 10101 00000 10110 01100 00110 10101 10101 01011 01110 00110 10100 01100 01011 01001 01111 10001 10000 11001 00101 01100 10101 10101 10101 10101 11001 10000 01101 01001 10111 10101 01010 00001 01100 00110 11000 01000 00100 11001 10001 10000 01100 10101 01000 11001 10000 01011 11000 10101 01010 10000 01000 01100 00100 10110 00001 00100 00011 10001 00000 01100 00110 11001 10001 00001 10101 10101 11001 01100 01101 01000 10110 00100 01110 10011 01011 00001 01001 01000 00110 10000 00111 01011 10011 00100 01011 01001 01100 00000 11000 01110 10101 00001 00001 01011 00111 00010 01110 10101 11001 01011 00001 00000 00110 00110 10111 00100 10001 01010 10011 01011 01100 00101 10111 00111 00001 01100 00101 10111 00011 10110 10010 01101 01100 00101 10111 01001 01010 10001 10101 01100 10010 00110 10110 10110 00100 00001 01101 01011 10011 01010 01100 11000 00110 00001 01010 01111 00101 11001 10111 10000 00110 00100 01111 11001 00001 10100 00011 10111 01111 10001 10011 10110 00000 00000 01100 01111 10011 11001 10101 10001 01011 01010 00010 01011 00101 00010 00100 01010 10111 10000 10110 10101 00000 00010 10000 01100 00010 10011 00010 10011 00001 00010 01010 01101 10011 00100 01011 10001 10100 00001 00000 01000 01000 01100 00010 01000 01010 11000 01100 11001 10110 00000 00000 00001 10001 00000 10001 00000 01110 01100 10111 01011 00000 10001 11001 10000 00100 00111 01111 00011 00101 00011 10001 11001 01100 00101 10111 00010 01000 00101 00001 10111 00110 11001 11000 00001 10001 01100 00110 01010 00111 00100 00001 10100 00000 10011 10000 01000 00010 01000 00000 10101 10111 00001 01111 10101 00010 00101 01100 10110 10001 00000 10101 01010 00100 10000 01011 00110 01011 01010 10110 10001 10100 10100 00010 10110 00011 10110 00100 01100 00111 01101 10111 01000 01000 00110 10000 01110 00010 01011 10001 00001 00110 01111 10111 00101 10111 10001 11001 00110 10110 11000 00100 00111 01100 01100 00100 10101 00101 00010 00110 01010 01011 10001 01010 00001 10000 00001 00101 10101 11001 01000 00011 00110 00110 10111 00010 00000 01011 10111 01111 01100 11000 01100 01111 10110 01110 00010 01010 00101 01101 00101 01000 11001 00010 10011 00100 01011 00110 01111 10111 01100 01100 11000 01100 00100 10101 10111 10100 10101 00101 10100 11001 10000 01100 10001 10111 10101 00000 01001 01100 00110 01100 01111 11000 01000 01000 01100 10011 01011 10111 01010 00100 00001 11001 00011 01100 11000 01001 01010 10101 01100 00110 10001 00001 01001 00001 00101 01000 00110 00001 10111 00100 01110 10101 10101 10111 00010 01010 01001 10000 00000 00100 00000 00110 01100 10101 01111 01101 10011 00100 10100 00001 01010 01111 00110 01111 10111 00001 00001 01000 01100 01111 00001 10111 11000 01010 00101 01101 00101 01100 00110 00110 00111 01000 01010 10101 00011 00001 01001 01011 10101 11001 01000 01000 00110 10001 01011 10001 10101 10000 10111 00111 01001 00001 01010 10000 01111 10000 10011 01011 01011 01010 01111 10001 00110 10011 01001 01011 00101 01111 10001 10011 01000 00010 10110 01011 00000 00110 10110 00001 01011 11000 11001 10011 00110 11001 10011 10001 10111 10011 10110 00010 01110 00001 10011 00001 00100 01110 00111 00000 10110 00110 01010 10101 01010 00110 01000 10101 00000 10111 01001 00000 00110 10110 10011 01011 01101 00011 01001 10001 11001 00111 00011 00111 01010 01111 10001 11001 11001 01100 01110 10101 11001 00000 10100 10111 01011 01100 01001 00001 10100 01000 01100 00101 10011 10100 11001 10001 10100 10011 00110 00110 10101 01011 01110 01100 10001 01100 00110 10100 10110 00111 11001 01010 00010 10011 10011 01111 01001 01111 00001 01001 10111 01101 01100 01001 01100 01010 00010 00110 00101 00001 01101 01001 00100 00010 01100 00101 01101 00111 10011 00100 10110 10110 10101 10011 10101 00011 10111 01111 00111 00100 10110 00111 11001 01000 01001 10011 00100 00000 10010 10110 01010 10001 00000 10001 00001 10001 00011 10111 01011 01100 01010 01111 10001 01010 00111 01011 00110 10101 01010 00110 10000 00111 01011 01011 01101 01100 11001 01000 10110 00010 01111 11001 00001 10100 00000 00111 01010 10111 00101 01101 00110 01111 10111 10100 00111 01000 10011 10000 00000 00100 11000 01010 10111 01100 00101 00001 10101 01100 00101 00110 01000 00000 10000 10111 10000 10011 00100 01011 00101 10100 10011 01001 00100 10101 00000 00110 00000 01100 11000 01100 10101 00000 01001 10000 00100 01001 01011 01011 11001 10001 10011 10001 01101 10011 01111 10110 10010 01101 00001 01011 01100 11000 01100 11001 01100 10110 00110 01101 00011 00001 10001 11001 00101 01100 00110 01010 01111 10001 01011 00111 10100 00110 01001 10000 10000 01100 00001 00101 10011 01100 01100 00000 00001 00000 11000 10110 01010 01111 10001 01010 10011 01101 10011 10011 10000 00110 00110 00001 01011 10111 10101 01011 00110 10110 01111 01100 01010 00001 10110 00000 00001 00000 00010 10100 00101 00000 00101 10000 00110 10011 10111 01001 00001 10101 01110 10011 10001 00001 00101 10101 10101 10101 01100 01100 00111 01011 11001 00001 11001 11001 11000 00110 11001 00000 01101 00001 00001 01100 00110 01010 01111 01101 00001 00001 10000 10100 10101 10000 00000 01110 01010 10010 00110 10110 11001 00001 10100 01100 00101 10111 10001 11001 01111 01111 10011 00010 00111 00010 10110 10011 00110 10110 00110 01110 11001 00000 10101 10110 00110 00101 10111 01000 01100 01101 00001 11001 00000 00000 00111 10000 10100 01000 10110 00101 00111 00110 01100 10000 00001 00000 11000 01100 10001 00000 00101 10000 11001 01011 00101 10101 10101 00110 10100 10111 11000 00110 01010 00001 10100 01000 01100 10001 00000 10101 01010 01101 00000 10111 10100 10011 01001 11001 10001 01110 10011 01111 10110 10101 01011 01101 00000 00100 01100 01111 00110 11001 10101 10110 01010 00110 01100 01111 01001 00111 00001 00000 11000 01010 01000 00110 01101 00000 01011 00110 11001 00100 01100 10000 01111 00001 10000 10100 10101 00000 00110 01000 11001 00010 00110 01010 10001 00001 01011 00001 00010 01100 00101 11001 00111 10101 00001 10001 10011 00100 01011 10011 01000 01110 00010 00000 10101 11001 01101 10011 00101 01100 01011 01010 00010 00000 10011 00001 01010 00001 01010 01100 10000 11001 10111 10000 00111 01011 11001 01111 01100 01011 10000 00000 10101 01111 01101 00000 01100 00010 10011 00011 00000 01101 10011 00100 11000 10101 01000 10110 00101 00000 01100 00101 10111 01011 10010 00110 11001 10011 10100 00100 11001 10101 10011 00001 00000 01111 00111 01011 01110 10100 00001 00000 00010 01000 10001 10111 10001 11001 01011 10100 10111 00010 01100 10010 00001 10100 00010 00000 11001 10101 10000 01000 01100 10001 00000 10101 10011 10101 01110 00000 10001 00000 00101 00010 00101 01100 10011 01011 10110 01010 11001 01011 10000 00110 00100 01100 00101 00100 00001 11001 00011 01100 01101 01010 00100 10100 01000 01100 10001 00000 10101 00110 11001 01100 10011 01011 00001 10001 10100 00101 10110 10011 01011 11001 01000 00110 01101 00001 00101 10110 01011 10101 10011 10010 01101 00111 01111 01100 11000 01000 00110 01001 01101 10001 00001 11000 01000 01000 01100 01000 00010 01010 01001 10110 00000 01000 00100 01001 10001 10011 01111 10001 01010 00011 00010 10110 10001 10101 10000 01000 00100 01001 01100 11000 01100 11001 01000 00010 01100 01010 11001 00001 10001 10100 01011 00011 01010 00101 10100 00110 01111 10111 00011 00111 01011 10101 10000 01000 01100 00110 00111 00100 01000 00100 01010 00000 00110 01110 10101 00100 10001 11001 10111 10000 00000 11001 10111 00010 01100 10110 01100 01101 01010 00001 00001 10100 10011 10000 01011 00101 00010 00100 10000 10111 11000 00110 10100 01111 01101 00011 10111 11001 10111 10101 10101 00101 01100 10101 10010 01010 10101 01011 01101 00001 01100 00101 10111 00110 01000 00100 10010 00001 11000 01011 01001 10000 10011 10101 10111 00001 10011 01010 01100 01101 10100 01100 01100 00101 10001 10010 10001 00000 01101 01111 10111 01010 01111 01101 00001 01100 00101 10111 00001 01100 01011 01011 00111 00000 01101 00011 01100 00000 00001 01011 10100 10111 01000 01100 00010 11001 00111 01101 10111 01000 10011 01011 01100 00110 00000 01010 01111 10111 00110 01100 10110 00110 00110 10011 01000 00101 01100 00010 01100 10110 11001 01100 00101 00001 10111 11000 00101 10110 10000 00000 01011 01011 10001 00000 10101 10100 01110 00010 01100 00100 00001 01100 01100 00000 00001 00000 00010 01100 10001 10011 10001 10101 01100 10000 00000 10101 10000 00101 00100 00111 01111 00011 11001 10101 10011 00100 00001 10001 00000 11001 10101 00001 00100 01100 00101 00001 00100 10010 01001 01100 00101 00110 11001 11000 00001 00000 01100 10111 00001 01100 00101 00001 01101 10010 10111 00011 01101 01000 00001 10100 01100 01010 10000 01100 10101 10111 00101 01000 00110 00001 00001 00110 10011 01101 10101 01100 01100 01110 11001 00000 10101 00001 01100 00101 10111 11000 11000 01101 00000 01011 01100 00111 00100 01000 00101 10000 10101 11000 00110 10111 01100 00110 01000 01111 11000 10001 01101 01111 10001 00001 00000 00010 01010 00101 11001 00000 10110 01100 00111 00111 10100 10000 10001 01000 00110 00001 00000 10101 11001 00110 01100 10011 01010 01111 00101 11001 10111 10110 01101 10001 01111 11000 01000 00110 00100 10111 11000 01010 10101 01011 00001 10000 00110 00100 01100 11000 01100 01110 01100 01011 10001 01111 10001 00110 00110 10110 00101 11000 00011 10101 00000 00111 11001 10111 10001 00000 10001 00001 10100 01000 01010 01111 10001 10100 10110 10001 00000 00110 01100 01100 10110 10000 00000 01011 00111 10010 01100 00011 10000 10011 01111 01100 11001 10111 01010 10110 01111 10110 00110 10011 00001 00100 01010 10001 01111 10111 01111 00110 00101 00001 00110 10110 01100 00010 00100 00010 01111 10101 10100 00001 00101 10011 01100 01100 01110 01100 10111 01011 10101 10001 11001 00100 00110 00001 01011 11001 00101 00010 00110 00000 00111 01010 10111 10010 01000 01111 10010 11001 01111 00111 01011 10101 10000 01010 00000 00010 10101 00001 00000 01101 10101 10110 00110 10011 00011 00100 00001 10101 10110 00010 01010 11001 10101 10011 10000 11000 10100 10111 01001 01111 00001 00010 00100 00001 00010 01011 00000 00110 00001 01010 10110 01100 00101 11001 10001 01010 01010 10010 00001 01010 01111 10001 11001 10110 00110 01010 10101 01010 00110 10011 10001 00110 11000 01001 01111 10001 00100 10011 10000 01111 00101 11001 10111 10000 00110 00100 01111 11001 00001 10100 00010 01011 10001 00000 10101 10101 10101 10100 01011 10010 01010 10101 00000 10100 01100 01111 01100 01101 00010 01011 00101 01100 10111 10001 00000 10101 10101 10001 01100 10110 00011 00111 01000 00000 10001 01010 01010 00010 10101 01111 00001 10100 01100 10110 00110 01010 10101 01010 00110 01000 01000 01101 01010 00101 01000 01111 01111 00001 10000 01010 11001 00000 10111 00110 10100 10010 01100 01010 01111 10001 10110 01010 00100 10011 00100 10000 00101 01000 01100 00110 00111 00100 01111 01101 00000 00110 00010 01110 10101 11001 00101 01111 00001 00010 10110 10001 00100 01101 00110 11000 01111 00111 00011 00001 10100 01000 01100 11001 10111 10110 10110 00100 01100 00111 01111 10001 00101 00010 01101 10101 10110 00110 01111 00101 00010 11000 01011 00110 10001 10100 10101 00100 00001 11001 00011 00110 00110 10111 01101 00001 11001 00001 10001 00001 01010 01111 10101 10101 00011 00110 01100 11001 00000 01101 11001 00001 10000 00011 01101 10110 00100 00001 00000 10001 10011 00001 10000 00000 01110 10001 01100 01101 01000 10011 00001 00011 00001 01011 11001 00100 10000 10001 01010 10111 10001 01010 11001 10101 10101 00001 10001 diff --git a/2021/plaintext.7a.txt b/2021/plaintext.7a.txt new file mode 100644 index 0000000..1ff5e11 --- /dev/null +++ b/2021/plaintext.7a.txt @@ -0,0 +1,20 @@ +we found the attached message hidden in the underlying code of an image sent in junkmail to people +at the us embassy it might have slipped past us but luckily harry and i had already figured out that +they might try to communicate this way the conspiracy had avoided detection for over a century so +they were unlikely to make the mistake of sending messages explicitly addressed to one another it is +always best not to make links between members of a network and a well hidden message in junkmail +avoids that risk especially if it is widely distributed by one of the bot networks like this one i +was too focussed on the decrypt at first and wasnt reading what it said until i found her name +staring back at meat the end perhaps we should have already realised that trinity could be involved +but it never occurred to me that her name was anything other than a coincidence the fact shes +charlies niece should have lit up the lights on the dashboard though and i am worried that harry +didnt raise it perhaps he is already shadowing her and didnt like to say so out of loyalty but he +didnt tell me that and somehow i think he would i think its more likely that shes beyond suspicion +in his mind she has played an important role in his network for fourteen years and the fact that she +might be a double agent will be a real blow that was bad but it wasnt the worst of it the detail +trinity gives on the conspiracy s recent activities is truly frightening what could they want at the +heart of the pandemic response groups surely they cant have been responsible for the outbreak and +what were they doing at copi desperately want to take this to harry to talk to him about it but the +final paragraph stopped me in my tracks why on earth does trinity think i might join them what have +i said or done that would make them think i could be a traitor and will that make harry distrust me +too im not sure i can take that risk i might have to finish this mission alone \ No newline at end of file diff --git a/2021/plaintext.7b.txt b/2021/plaintext.7b.txt new file mode 100644 index 0000000..87ac7a9 --- /dev/null +++ b/2021/plaintext.7b.txt @@ -0,0 +1,25 @@ +charlie i dont think you should have come to london we cant risk meeting and your arrival has been +noticed by boss heightening suspicion harry steam is actively investigating our organisation and we +have to do everything we can to put them off the scent unfortunately im working with very +constrained resources despite all our pandemic preparations it has been hard work over the last +eighteen months as planned we used the crisis to embed more operatives at the heart of government +decisionmaking under the cover of sage and the other new committees we now have a network of +scientists and engineers in whitehall with the direct ear of senior civil servants and politicians +they also helped us to infiltrate cop giving us direct access to a number of other governments that +had remained beyond our reach while we were notable to fully deliver on our plans for that event the +connections we made with some of the worlds largest companies and smallest states will surely payoff +in the medium term on the downside i havent had the capacity i need to work on the boss +investigation into our organisation that is being run from the archaeology division here at gchq i +had hoped that assignment meant that the case was regarded as low priority but harry assigned his +best agent jodie to run it and gave her almost unlimited resources she has teams all across the uk +trawling through the papers we left behind at the lighthouse and trying to workout what they mean i +am so angry at myself for that but i have personally checked and all the major items from the +foundation archive were shipped out to mass our ie and have been secured at the park i assigned a +team to make sure that the key documents were properly encrypted in case jodie steam finds them but +given the talent she is working with i now think we might need to take further steps and i plan to +visit the hq as soon as i can getaway whether or not jodie and her teamwork out what we are doing +the best way to make sure that harry does not find out might be to convince her not to tell him i +have been carrying out some background checks and i am wondering if we should just try to recruit +her directly if she was working with us then im sure she would see the need for secrecy the direct +approach is risky but the organisation has never shied away from that before or you and i wouldnt be +working for it i think it is a risk worth taking your loving niece trinity \ No newline at end of file -- 2.34.1 From a7e23b071bce27b0439a20285d8df8a56c4af52d Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 3 Dec 2021 09:35:52 +0000 Subject: [PATCH 15/16] Done challenge 8 --- 2021/2021-challenge7.ipynb | 71 ++-- 2021/2021-challenge7.md | 15 +- 2021/2021-challenge8.ipynb | 829 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge8.md | 185 +++++++++ 2021/ciphertext.8a.txt | 1 + 2021/ciphertext.8b.txt | 1 + 2021/plaintext.8a.txt | 24 ++ 7 files changed, 1073 insertions(+), 53 deletions(-) create mode 100644 2021/2021-challenge8.ipynb create mode 100644 2021/2021-challenge8.md create mode 100644 2021/ciphertext.8a.txt create mode 100644 2021/ciphertext.8b.txt create mode 100644 2021/plaintext.8a.txt diff --git a/2021/2021-challenge7.ipynb b/2021/2021-challenge7.ipynb index 967060a..089f680 100644 --- a/2021/2021-challenge7.ipynb +++ b/2021/2021-challenge7.ipynb @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "id": "0f1f792a", "metadata": { "Collapsed": "false" @@ -64,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", "metadata": {}, "outputs": [ @@ -74,7 +74,7 @@ "Counter({'e': 632, 'c': 619, 'a': 714, 'b': 410, 'd': 787})" ] }, - "execution_count": 9, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", "metadata": {}, "outputs": [ @@ -96,7 +96,7 @@ "" ] }, - "execution_count": 10, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, @@ -119,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 6, "id": "583312cf-a973-4671-9ba8-85fe10cb9e00", "metadata": {}, "outputs": [ @@ -130,7 +130,7 @@ " -6776.263168839725)" ] }, - "execution_count": 11, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -143,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "id": "4262216b-efed-491e-ade1-d7e8dffe4454", "metadata": {}, "outputs": [ @@ -153,7 +153,7 @@ "'wemounhtbeattacbehkessayebdhhendntbeunherizdnycoheomandkayesentdnfungkaditopeopieattbeuseklasszdtkdybtbavesidppehpastuslutiucgdizbarrzanhdbahaireahzmdyurehouttbattbezkdybttrztocokkundcatetbdswaztbeconspdraczbahavodhehhetectdonmoroveracenturzsotbezwereunidgeiztokagetbekdstageomsenhdnykessayesexpidcdtizahhressehtooneanotberdtdsaiwazslestnottokageidngsletweenkeklersomanetworganhaweiibdhhenkessayednfungkadiavodhstbatrdsgespecdaiizdmdtdswdheizhdstrdlutehlzoneomtbelotnetworgsidgetbdsonedwastoomocussehontbehecrzptatmdrstanhwasntreahdnywbatdtsadhuntdidmounhbernakestardnylacgatkeattbeenhperbapswesbouihbaveaireahzreaidsehtbattrdndtzcouihlednvoivehlutdtneveroccurrehtoketbatbernakewasanztbdnyotbertbanacodncdhencetbemactsbescbaridesndecesbouihbaveidtuptbeidybtsontbehasbloarhtbouybanhdakworrdehtbatbarrzhdhntradsedtperbapsbedsaireahzsbahowdnyberanhhdhntidgetosazsooutomiozaitzlutbehdhntteiiketbatanhsokebowdtbdngbewouihdtbdngdtskoreidgeiztbatsbeslezonhsuspdcdondnbdskdnhsbebaspiazehandkportantroiednbdsnetworgmormourteenzearsanhtbemacttbatsbekdybtleahoulieayentwdiileareailiowtbatwaslahlutdtwasnttbeworstomdttbehetaditrdndtzydvesontbeconspdraczsrecentactdvdtdesdstruizmrdybtendnywbatcouihtbezwantattbebeartomtbepanhekdcresponseyroupssureiztbezcantbaveleenresponsdliemortbeoutlreaganhwbatweretbezhodnyatcopdhesperateizwanttotagetbdstobarrztotaigtobdkaloutdtluttbemdnaiparayrapbstoppehkednkztracgswbzoneartbhoestrdndtztbdngdkdybtfodntbekwbatbavedsadhorhonetbatwouihkagetbektbdngdcouihleatradtoranhwdiitbatkagebarrzhdstrustketoodknotsuredcantagetbatrdsgdkdybtbavetomdndsbtbdskdssdonaione'" ] }, - "execution_count": 13, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -166,74 +166,53 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 25, "id": "bbe56403-8038-4659-9f3d-7056ef60e665", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'xefpvoduheauuachednettagehiddeoiouhevodesmziogcpdepfaoinageteouiokvolnaimupqepqmeauuhevtenbattziunighuhawetmiqqedqatuvtbvumvclimzhasszaodihadamseadzfigvsedpvuuhauuheznighuuszupcpnnvoicaueuhitxazuhecpotqisaczhadawpideddeuecuipofpspwesaceouvsztpuhezxesevomilemzupnaleuhenitualepfteodiognettageteyqmiciumzaddsetteduppoeaopuhesiuitamxaztbetuopuupnalemioltbeuxeeonenbestpfaoeuxpslaodaxemmhiddeonettageiokvolnaimawpidtuhausitletqeciammzifiuitxidemzditusibvuedbzpoepfuhebpuoeuxpsltmileuhitpoeixatuppfpcvttedpouhedecszquaufistuaodxatouseadiogxhauiutaidvouimifpvodhesoanetuasiogbaclauneauuheeodqeshaqtxethpvmdhaweamseadzseamiteduhauusioiuzcpvmdbeiowpmwedbvuiuoewespccvssedupneuhauhesoanexataozuhiogpuhesuhaoacpiocideoceuhefacuthetchasmietoiecethpvmdhawemiuvquhemighutpouhedathbpasduhpvghaodianxpssieduhauhasszdidousaiteiuqeshaqtheitamseadzthadpxioghesaoddidoumileuptaztppvupfmpzamuzbvuhedidouuemmneuhauaodtpnehpxiuhiolhexpvmdiuhioliutnpsemilemzuhauthetbezpodtvtqicipoiohitniodthehatqmazedaoinqpsuaouspmeiohitoeuxpslfpsfpvsueeozeastaoduhefacuuhauthenighubeadpvbmeageouximmbeaseambmpxuhauxatbadbvuiuxatouuhexpstupfiuuhedeuaimusioiuzgiwetpouhecpotqisacztseceouacuiwiuietitusvmzfsighueoiogxhaucpvmduhezxaouauuheheasupfuheqaodenicsetqpotegspvqttvsemzuhezcaouhawebeeosetqpotibmefpsuhepvubsealaodxhauxeseuhezdpiogaucpqidetqesauemzxaouupualeuhituphasszupuamluphinabpvuiubvuuhefioamqasagsaqhtupqqedneionzusacltxhzpoeasuhdpetusioiuzuhiolinighukpiouhenxhauhaweitaidpsdpoeuhauxpvmdnaleuhenuhiolicpvmdbeausaiupsaodximmuhaunalehasszditusvtuneuppinoputvseicaoualeuhausitlinighuhaweupfioithuhitnittipoampoe'" + "'wefoundtheattachedmessagehiddenintheunderlyingcodeofanimagesentinjunkmailtopeopleattheusembassyitmighthaveslippedpastusbutluckilyharryandihadalreadyfiguredoutthattheymighttrytocommunicatethiswaytheconspiracyhadavoideddetectionforoveracenturysotheywereunlikelytomakethemistakeofsendingmessagesexplicitlyaddressedtooneanotheritisalwaysbestnottomakelinksbetweenmembersofanetworkandawellhiddenmessageinjunkmailavoidsthatriskespeciallyifitiswidelydistributedbyoneofthebotnetworkslikethisoneiwastoofocussedonthedecryptatfirstandwasntreadingwhatitsaiduntilifoundhernamestaringbackatmeattheendperhapsweshouldhavealreadyrealisedthattrinitycouldbeinvolvedbutitneveroccurredtomethathernamewasanythingotherthanacoincidencethefactshescharliesnieceshouldhavelitupthelightsonthedashboardthoughandiamworriedthatharrydidntraiseitperhapsheisalreadyshadowingheranddidntliketosaysooutofloyaltybuthedidnttellmethatandsomehowithinkhewouldithinkitsmorelikelythatshesbeyondsuspicioninhismindshehasplayedanimportantroleinhisnetworkforfourteenyearsandthefactthatshemightbeadoubleagentwillbearealblowthatwasbadbutitwasnttheworstofitthedetailtrinitygivesontheconspiracysrecentactivitiesistrulyfrighteningwhatcouldtheywantattheheartofthepandemicresponsegroupssurelytheycanthavebeenresponsiblefortheoutbreakandwhatweretheydoingatcopidesperatelywanttotakethistoharrytotalktohimaboutitbutthefinalparagraphstoppedmeinmytrackswhyonearthdoestrinitythinkimightjointhemwhathaveisaidordonethatwouldmakethemthinkicouldbeatraitorandwillthatmakeharrydistrustmetooimnotsureicantakethatriskimighthavetofinishthismissionalone'" ] }, - "execution_count": 15, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "xca = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a,\n", - " column_first=col_first_a, wrap_alphabet=wrap_a)\n", - "xca" + "pa = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a,\n", + " column_first=col_first_a, wrap_alphabet=wrap_a,\n", + " letters_to_merge={'z': 'y'})\n", + "pa" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 26, "id": "81c5bc01-b60b-4d26-9f19-231854f4f6de", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'abcdefghiklmnopqrstuvwxyzj'" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "word_a, _ = monoalphabetic_sa_break(xca)\n", - "word_a" + "# word_a, _ = monoalphabetic_sa_break(xca)\n", + "# word_a" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 27, "id": "7aa6dff2-f12c-4212-83df-3a9bb7b76334", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'wefoundtheattachedmessagehiddenintheunderlyingcodeofanimagesentinjunkmailtopeopleattheusembassyitmighthaveslippedpastusbutluckilyharryandihadalreadyfiguredoutthattheymighttrytocommunicatethiswaytheconspiracyhadavoideddetectionforoveracenturysotheywereunlikelytomakethemistakeofsendingmessagesexplicitlyaddressedtooneanotheritisalwaysbestnottomakelinksbetweenmembersofanetworkandawellhiddenmessageinjunkmailavoidsthatriskespeciallyifitiswidelydistributedbyoneofthebotnetworkslikethisoneiwastoofocussedonthedecryptatfirstandwasntreadingwhatitsaiduntilifoundhernamestaringbackatmeattheendperhapsweshouldhavealreadyrealisedthattrinitycouldbeinvolvedbutitneveroccurredtomethathernamewasanythingotherthanacoincidencethefactshescharliesnieceshouldhavelitupthelightsonthedashboardthoughandiamworriedthatharrydidntraiseitperhapsheisalreadyshadowingheranddidntliketosaysooutofloyaltybuthedidnttellmethatandsomehowithinkhewouldithinkitsmorelikelythatshesbeyondsuspicioninhismindshehasplayedanimportantroleinhisnetworkforfourteenyearsandthefactthatshemightbeadoubleagentwillbearealblowthatwasbadbutitwasnttheworstofitthedetailtrinitygivesontheconspiracysrecentactivitiesistrulyfrighteningwhatcouldtheywantattheheartofthepandemicresponsegroupssurelytheycanthavebeenresponsiblefortheoutbreakandwhatweretheydoingatcopidesperatelywanttotakethistoharrytotalktohimaboutitbutthefinalparagraphstoppedmeinmytrackswhyonearthdoestrinitythinkimightjointhemwhathaveisaidordonethatwouldmakethemthinkicouldbeatraitorandwillthatmakeharrydistrustmetooimnotsureicantakethatriskimighthavetofinishthismissionalone'" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "pa = keyword_decipher(xca, word_a)\n", - "pa" + "# pa = keyword_decipher(xca, word_a)\n", + "# pa" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", "metadata": {}, "outputs": [ diff --git a/2021/2021-challenge7.md b/2021/2021-challenge7.md index 56140fa..ee251e2 100644 --- a/2021/2021-challenge7.md +++ b/2021/2021-challenge7.md @@ -73,19 +73,20 @@ polybius_decipher(sca, keyword=word_a, column_order=col_a, row_order=row_a, ``` ```python -xca = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a, - column_first=col_first_a, wrap_alphabet=wrap_a) -xca +pa = polybius_decipher(sca, keyword='a', column_order=col_a, row_order=row_a, + column_first=col_first_a, wrap_alphabet=wrap_a, + letters_to_merge={'z': 'y'}) +pa ``` ```python -word_a, _ = monoalphabetic_sa_break(xca) -word_a +# word_a, _ = monoalphabetic_sa_break(xca) +# word_a ``` ```python -pa = keyword_decipher(xca, word_a) -pa +# pa = keyword_decipher(xca, word_a) +# pa ``` ```python diff --git a/2021/2021-challenge8.ipynb b/2021/2021-challenge8.ipynb new file mode 100644 index 0000000..9202b46 --- /dev/null +++ b/2021/2021-challenge8.ipynb @@ -0,0 +1,829 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 31, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.vigenere import *\n", + "from szyfrow.polybius import *\n", + "from szyfrow.railfence import *\n", + "from szyfrow.support.text_prettify import *\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import collections\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 8\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": 3, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "ncb = open(ciphertext_b_filename).read()\n", + "\n", + "numtrans = ''.maketrans('12345', 'abcde')\n", + "cb = ncb.translate(numtrans)\n", + "\n", + "sca = sanitise(ca)\n", + "rsca = cat(reversed(sca))\n", + "scb = sanitise(cb)\n", + "rscb = cat(reversed(scb))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'d': 45,\n", + " 'e': 105,\n", + " 'c': 90,\n", + " 'r': 120,\n", + " 'o': 43,\n", + " 'a': 76,\n", + " 'k': 113,\n", + " 'n': 44,\n", + " 'y': 110,\n", + " 'z': 91,\n", + " 'j': 60,\n", + " 'l': 111,\n", + " 'p': 91,\n", + " 'w': 45,\n", + " 'f': 110,\n", + " 't': 93,\n", + " 'v': 118,\n", + " 'i': 87,\n", + " 'u': 61,\n", + " 'm': 58,\n", + " 'g': 43,\n", + " 's': 51,\n", + " 'x': 16,\n", + " 'b': 31,\n", + " 'h': 48,\n", + " 'q': 17})" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sca_counts = collections.Counter(sca)\n", + "sca_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAASjUlEQVR4nO3de7SldV3H8fdHMFDwMsQBJy4OuiYVzZZ6vBUVKzIpL1CJQWXjpWapaGalDN0oVxSt7lloE15GRZFQg7LEacqFVqIDqFwGA0VxdGSmvLFKhbFvf+xnYnvct7P3OTNnfvN+rbXXPs+zf7/n+Z7n7PPZv/3bez87VYUkqS332tcFSJKWnuEuSQ0y3CWpQYa7JDXIcJekBhnuktSgg/d1AQBHHnlkrVmzZl+XIUn7lWuuueY/q2pu0G0rItzXrFnD1q1b93UZkrRfSfLpYbc5LSNJDTLcJalBhrskNchwl6QGGe6S1KCx4Z7k9Ul2Jrmhb90fJLk5yceSvCvJA/tuOzfJrUk+nuSpy1S3JGmESUbubwROXbBuM/Coqno08B/AuQBJTgTOBB7Z9bkwyUFLVq0kaSJjw72qrgK+sGDde6tqd7f4QeDY7ufTgEuq6utVdRtwK/CEJaxXkjSBpfgQ0/OBt3c/H0Mv7PfY3q37FknWA+sBjj/++CUoQ9JirNnw7qG3feqCp+3FSrQcZnpBNcmvAbuBi/esGtBs4Fc9VdXGqpqvqvm5uYGfnpUkTWnqkXuSdcDTgVPqnu/q2w4c19fsWOBz05cnSZrGVCP3JKcC5wDPrKr/6bvpCuDMJIckOQFYC3xo9jIlSYsxduSe5G3AycCRSbYD59F7d8whwOYkAB+sqhdW1Y1JLgVuojddc3ZVfWO5ipekPYa9hnCgvn4wNtyr6qwBq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txx6y73+z524y930zzN5rmvrlSLfj9dwN3dCPZYe0vAC6pIW8eGLOvw+k90P8KvTc7HDKi7fzC/6skz6mqoa+HJHkV8Lohf7NHLFserORwl5ZTkr8G/mSCEZ4a1L2L5fvojd4/zT3vnPnnfVrYEjHcdcBKsg14KL0X+FbCtJT2oiSvoBfo14x6VrC/Mtx1wJp2ikXaHxjuktSgFfchJknS7Ax3SWqQ4S5JDTLcJalBhrskNej/AFp8npMkoqciAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(sca_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "583312cf-a973-4671-9ba8-85fe10cb9e00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('harry', -6318.403758350804)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams)\n", + "key_a, score_a" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "b371ff9c-dbe0-43d9-95a4-1b6766090a6e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'wellthatwasasurpriseifoundtheattachedletteronmydoormatinacopyofthelocalmagazineitwascleverreallythereisnowaytotrackbacktohowitgotthereandnopointinwastingtimeorresourcestryingtofindoutinanycaseitwasclearthattrinitysentitandequallyclearwhatshewantedeventheciphertheyhaveusedisamessagetomeitisdoubleencryptedwiththesecondstageusingthesamepolybiusgridiusedformylastdiaryentrytheyaretellingmethatihavenowheretohideonceistrippedthatoffiwasleftwithastandardbuttrickyciphertobreakfortunatelyilearnedthedarkartsoffrequencyanalysisandcribbingfromharrysoitdidnttakelongtocrackitthesecondsurpriseisthatidontknowwhattodonormallyanyunsolicitedapproachlikethiswouldbeinstantlyreportedtothelamplighterssotheycouldinvestigatebutastrinitypointsoutihadalreadyconcealedthelastinterceptfromharryworriedthatitmightdamagehistrustinmeitwillnotlookgoodifhefindsthatoutfromthembutifitellhimtheniwillalsohavetotellhimaboutthisdirectappealtojointhemidontthinkthatwillmakethingsanybetterbetweenusthereissomethingelsetoothefoundersoftheconspiracyarepersonalheroesofmineandicantbeartothinkthattheymighthavebeenworkingforthedarksideifitistruetheniwouldratherfindoutformyselfthanleaveittoothersinbossisupposeicouldtellallandoffertoinfiltratetheagencybutthehistoryofdoubleagentsisnotahappyoneitishardtoreallytrustsomeonewhohasworkedfortheoppositioneveniftheydoitundercovertoomanyhavebeencorruptedbythecompromisesrequiredandiamnotsureiamcutoutforthatsortofworkidontthinkharrywouldinsistbutiamcertainsomebodyinbosswouldthetalkofthepandemicandcopwillbearedflagandsomeonesomewherewillbedesperatetobreakintotheconspiracydesperateenoughtomakemeanoffericantrefuseiwillhavetotakethisfurtherbutbeforeiagreetomeettrinityineedtoknowmorethenameofthesouterpointlighthouseringsabellbuticantrememberwhereicameacrossitiwillhavetogetthetraineestofigureoutwhyitmightbeimportantmeanwhileihaveanothermoreurgenttriptomaketomassourie'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pa = vigenere_decipher(sca, key_a)\n", + "pa" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "c8506a7a-4444-4929-93e4-70d1e4d6f0cc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "well that was a surprise i found the attached letter on my doormat in a copy of the local magazine\n", + "it was clever really there is no way to trackback to how it got there and no point in wasting time\n", + "or resources trying to find out in any case it was clear that trinity sent it and equally clear what\n", + "she wanted even the cipher they have used is a message to me it is double encrypted with the second\n", + "stage using the same polybius grid i used for my last diary entry they are telling me that i have\n", + "nowhere to hide once i stripped that off i was left with a standard but tricky cipher to break\n", + "fortunately i learned the dark arts of frequency analysis and cribbing from harry so it didnt take\n", + "long to crack it the second surprise is that i dont know what to do normally any unsolicited\n", + "approach like this would be instantly reported to the lamplighters so they could investigate but as\n", + "trinity points out i had already concealed the last intercept from harry worried that it might\n", + "damage his trust in me it will not look good if he finds that out from them but if i tell him then i\n", + "will also have to tell him about this direct appeal to join them i dont think that will make things\n", + "any better between us there is something else too the founders of the conspiracy are personal heroes\n", + "of mine and icant bear to think that they might have been working for the darkside if it is true\n", + "then i would rather find out for myself than leave it to others in boss i suppose i could tell all\n", + "and offer to infiltrate the agency but the history of double agents is not a happy one it is hard to\n", + "really trust someone who has worked for the opposition even if they do it undercover too many have\n", + "been corrupted by the compromises required and i am not sure i am cutout for that sort of work i\n", + "dont think harry would insist but i am certain somebody in boss would the talk of the pandemic and\n", + "cop will be a red flag and someone somewhere will be desperate to break into the conspiracy\n", + "desperate enough to make mean offer icant refuse i will have to take this further but before i agree\n", + "to meet trinity i need to know more the name of the souter point lighthouse rings a bell but icant\n", + "remember where i came across it i will have to get the trainees to figure out why it might be\n", + "important meanwhile i have another more urgent trip to make to mass our ie\n" + ] + } + ], + "source": [ + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "46512a70-68d4-4ea9-8f66-b39966232fa6", + "metadata": { + "Collapsed": "false", + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2333" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "4262216b-efed-491e-ade1-d7e8dffe4454", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'wemounhtbeattacbehkessayebdhhendntbeunherizdnycoheomandkayesentdnfungkaditopeopieattbeuseklasszdtkdybtbavesidppehpastuslutiucgdizbarrzanhdbahaireahzmdyurehouttbattbezkdybttrztocokkundcatetbdswaztbeconspdraczbahavodhehhetectdonmoroveracenturzsotbezwereunidgeiztokagetbekdstageomsenhdnykessayesexpidcdtizahhressehtooneanotberdtdsaiwazslestnottokageidngsletweenkeklersomanetworganhaweiibdhhenkessayednfungkadiavodhstbatrdsgespecdaiizdmdtdswdheizhdstrdlutehlzoneomtbelotnetworgsidgetbdsonedwastoomocussehontbehecrzptatmdrstanhwasntreahdnywbatdtsadhuntdidmounhbernakestardnylacgatkeattbeenhperbapswesbouihbaveaireahzreaidsehtbattrdndtzcouihlednvoivehlutdtneveroccurrehtoketbatbernakewasanztbdnyotbertbanacodncdhencetbemactsbescbaridesndecesbouihbaveidtuptbeidybtsontbehasbloarhtbouybanhdakworrdehtbatbarrzhdhntradsedtperbapsbedsaireahzsbahowdnyberanhhdhntidgetosazsooutomiozaitzlutbehdhntteiiketbatanhsokebowdtbdngbewouihdtbdngdtskoreidgeiztbatsbeslezonhsuspdcdondnbdskdnhsbebaspiazehandkportantroiednbdsnetworgmormourteenzearsanhtbemacttbatsbekdybtleahoulieayentwdiileareailiowtbatwaslahlutdtwasnttbeworstomdttbehetaditrdndtzydvesontbeconspdraczsrecentactdvdtdesdstruizmrdybtendnywbatcouihtbezwantattbebeartomtbepanhekdcresponseyroupssureiztbezcantbaveleenresponsdliemortbeoutlreaganhwbatweretbezhodnyatcopdhesperateizwanttotagetbdstobarrztotaigtobdkaloutdtluttbemdnaiparayrapbstoppehkednkztracgswbzoneartbhoestrdndtztbdngdkdybtfodntbekwbatbavedsadhorhonetbatwouihkagetbektbdngdcouihleatradtoranhwdiitbatkagebarrzhdstrustketoodknotsuredcantagetbatrdsgdkdybtbavetomdndsbtbdskdssdonaione'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_a, wrap_a, col_a, row_a, col_first_a = key_a\n", + "polybius_decipher(sca, keyword=word_a, column_order=col_a, row_order=row_a,\n", + " column_first=col_first_a, wrap_alphabet=wrap_a)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "bbe56403-8038-4659-9f3d-7056ef60e665", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'pafdmtiswsencmysllreooojytttyisirmenpsuuoyaawttriweotyotnunpiscaoemuciepiagopawggrptioyhbrliuoekskltttnhofendeoeoawowednemeeegoopuengermnbiwnedoeoarcnfhdmsoiapwoaefseryohyrehagtdinyooerofnirdconotitaoisleottswonailntuhisohwhwdirifinnayrneadrschnosalfpycrshooneyiuodamgrheeikaindeieteayhabuudiordruiheyydeeerncarobhmueodykotirutwrysaitcubkecviihonnuulofaufsemciodeelsacntaebrtyewdsooahcilirooybllupaaunpdndmgtfnnoeftnfyeeuoteoehatagaiuowuooemsrenieosouvrntcelupsuteupdwbureiolacrituhrisioittnthahylrtstdhleiysowoeelbwhegatodisyaddaattbrahdiowwrtrehthomrelionessipetltrtaiahcydglbrsnorkaftontrdorlaaoostaahtttuionidtebrrboehwnicordaeheytepltnnoybltohlniirteleoshtnefneloesoeocsouulkvhsydrtntkannnecroohbreurrixhetjoeoioocaboroefometuoebtyiotensotelueyfenieswtruoriwusetwrucrwktaeattnertarcruescsenrmaasuaootedsdbuoeahafgonvntahoeuedreareuoeaudttwhoeaetbhvonetrgtreddtaogrteouvstiodletiofaaahleoiaaeecaemoybhsoyytahirhacttocidoerliyttehtnmnmcsuehdcuhdaoorhhceunktetthyhuerohioslegneiieopeaoriaeyftldiegaihgtiunhenlogsanhnveeptnyotipayldhmhcfmoepaptsuysuynyelirasinagollghgsyetussbmnkenpooroodrtddgtruuetetcuioomfrarihyoslsahwispkennepivtsluiltochaanuirpiclecinvoeitdhatnuceilrnpnuoeiisisinloiceerweeiultitatwmsuowbdirenycnrlthuuaaeybylaliiweeihoyeteuthrsrtiurecoultoistvepgetunhegowricleiwhiaartahnhuosleairtnupeneloreoelouigeaooyneronuooybrttongeraeutcbolnohhytonthorsgrtrltttnnoterdpnsawenawfioytjoatsdfnureeydeoceevlngmrlxnlofaptddbtsttsuthnghcaaernefwbfamcaatoeoylstneotrgrwgttuioeiavhitltorutcgyulbaapvutdodtseypmhoeinsrnestgasoithiisnehitikrbegktnetehduitdteiaelohpirotitenashottptcnktsutiarwotduftetwuvtidodautanhkftedlultriaooemstdeuaebtahoyoisbhcirhtoyiweawduedthtuiscrealrglrswelneuteepnswiietgavahhnynakoaueshengityeboecrtitlesimreaiavrtnytaieoaadetasuynbantnnrheykfiareochlifwtsdeeytttorklmitviageffohoothntrodeeaaiheftivoyut'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xcb = polybius_decipher(scb, keyword='a', column_order='abcde', row_order='abcde',\n", + " column_first=False, wrap_alphabet=KeywordWrapAlphabet.from_a,\n", + " letters_to_merge={'z': 'y'})\n", + "xcb" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "77a5c146-fa17-41db-9908-7bf2645fe3a1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'pafdmtiswsencmysllreooojytttyisirmenpsuuoyaawttriweotyotnunpiscaoemuciepiagopawggrptioyhbrliuoekskltttnhofendeoeoawowednemeeegoopuengermnbiwnedoeoarcnfhdmsoiapwoaefseryohyrehagtdinyooerofnirdconotitaoisleottswonailntuhisohwhwdirifinnayrneadrschnosalfpycrshooneyiuodamgrheeikaindeieteayhabuudiordruiheyydeeerncarobhmueodykotirutwrysaitcubkecviihonnuulofaufsemciodeelsacntaebrtyewdsooahcilirooybllupaaunpdndmgtfnnoeftnfyeeuoteoehatagaiuowuooemsrenieosouvrntcelupsuteupdwbureiolacrituhrisioittnthahylrtstdhleiysowoeelbwhegatodisyaddaattbrahdiowwrtrehthomrelionessipetltrtaiahcydglbrsnorkaftontrdorlaaoostaahtttuionidtebrrboehwnicordaeheytepltnnoybltohlniirteleoshtnefneloesoeocsouulkvhsydrtntkannnecroohbreurrixhetjoeoioocaboroefometuoebtyiotensotelueyfenieswtruoriwusetwrucrwktaeattnertarcruescsenrmaasuaootedsdbuoeahafgonvntahoeuedreareuoeaudttwhoeaetbhvonetrgtreddtaogrteouvstiodletiofaaahleoiaaeecaemoybhsoyytahirhacttocidoerliyttehtnmnmcsuehdcuhdaoorhhceunktetthyhuerohioslegneiieopeaoriaeyftldiegaihgtiunhenlogsanhnveeptnyotipayldhmhcfmoepaptsuysuynyelirasinagollghgsyetussbmnkenpooroodrtddgtruuetetcuioomfrarihyoslsahwispkennepivtsluiltochaanuirpiclecinvoeitdhatnuceilrnpnuoeiisisinloiceerweeiultitatwmsuowbdirenycnrlthuuaaeybylaliiweeihoyeteuthrsrtiurecoultoistvepgetunhegowricleiwhiaartahnhuosleairtnupeneloreoelouigeaooyneronuooybrttongeraeutcbolnohhytonthorsgrtrltttnnoterdpnsawenawfioytjoatsdfnureeydeoceevlngmrlxnlofaptddbtsttsuthnghcaaernefwbfamcaatoeoylstneotrgrwgttuioeiavhitltorutcgyulbaapvutdodtseypmhoeinsrnestgasoithiisnehitikrbegktnetehduitdteiaelohpirotitenashottptcnktsutiarwotduftetwuvtidodautanhkftedlultriaooemstdeuaebtahoyoisbhcirhtoyiweawduedthtuiscrealrglrswelneuteepnswiietgavahhnynakoaueshengityeboecrtitlesimreaiavrtnytaieoaadetasuynbantnnrheykfiareochlifwtsdeeytttorklmitviageffohoothntrodeeaaiheftivoyut'" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sncb = cat(l for l in ncb if l in '12345')\n", + "xcb = polybius_decipher(sncb, keyword='a', column_order='12345', row_order='12345',\n", + " column_first=False, wrap_alphabet=KeywordWrapAlphabet.from_a,\n", + " letters_to_merge={'z': 'y'})\n", + "xcb" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "24d8ad2e-b237-479b-9a62-af9bc8d100d5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'p': 34,\n", + " 'a': 131,\n", + " 'f': 33,\n", + " 'd': 66,\n", + " 'm': 29,\n", + " 't': 186,\n", + " 'i': 134,\n", + " 's': 84,\n", + " 'w': 43,\n", + " 'e': 208,\n", + " 'n': 115,\n", + " 'c': 49,\n", + " 'y': 63,\n", + " 'l': 70,\n", + " 'r': 114,\n", + " 'o': 179,\n", + " 'j': 3,\n", + " 'u': 91,\n", + " 'g': 38,\n", + " 'h': 92,\n", + " 'b': 33,\n", + " 'k': 19,\n", + " 'v': 18,\n", + " 'x': 2})" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scb_counts = collections.Counter(xcb)\n", + "scb_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "d66dd0d0-badb-44f3-a8a6-f7edd17d1532", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUaElEQVR4nO3df7BkZX3n8fdHNGiARAgXMgWMA9SIgjFjuKJbQpYNMY5RgyZimE2xE2MccWFXd7OuYLLRtcKGbERr1wSSQYijQX5ERKjSiOxsNshGxDuA/BpY+akjE+YGVKYSRWf87h99rnSufW/37e47c+fM+1XV1X2ePs853zl3+tOnnz59TqoKSVK7PGN3FyBJGj/DXZJayHCXpBYy3CWphQx3SWohw12SWuiZu7sAgIMPPrhWrFixu8uQpD3Kpk2b/qGqJno9tyTCfcWKFUxNTe3uMiRpj5Lkkbmec1hGklrIcJekFjLcJamFDHdJaiHDXZJayHCXpBYy3CWphQx3SWqhJfEjpr3NinM+M+dzD5//ml1YiaS2cs9dklrIcJekFjLcJamFDHdJaqG+4Z7kiCR/k2RzkruTvKNpPyjJDUm+2twf2NXn3CT3J7kvyasW8x8gSfpRg+y57wB+p6peCLwcOCvJscA5wMaqWglsbKZpnjsdOA5YDVyYZJ/FKF6S1FvfcK+qrVV1a/N4O7AZOAw4FdjQzLYBe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kJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(scb_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "60b68dbb-7e93-4ba6-aca3-2aebe2902a70", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAD4CAYAAADy46FuAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAbMUlEQVR4nO3df5TddZ3f8efLRJFFwQQHFhMwuKQqsP4iBvbottasSTzqhrawjW1l1mY3LYtb7Q9X0m6bXWgsnHalhS3sshIJKEI2u5R0LWanoR61GwMDopFfJ6MgpCDJOhFTV9Ckr/7x/czmm+HO596ZTCaT5PU4557v/b6/n/fnfu6dO/Oez/fznTuyTURExFhecrgHEBER01sKRUREVKVQREREVQpFRERUpVBERERVCkVERFTNPNwDmGyvfvWrPW/evMM9jIiII8r999//l7b7Oh076grFvHnzGBwcPNzDiIg4okj67ljHcuopIiKqUigiIqIqhSIiIqpSKCIioiqFIiIiqlIoIiKiKoUiIiKqUigiIqLqqPuDu6PZvMu/MOaxJ6563xSOJCKOJZlRREREVQpFRERUpVBERERVCkVERFSlUERERFUKRUREVKVQREREVQpFRERUpVBERERVCkVERFSlUERERFXXQiHp9ZIebN1+KOljkmZLGpC0vWxntXJWSRqS9JikJa34eZK2lWPXSlKJHyfpjhLfKmleK6e/PMZ2Sf2T/PwjIqKLroXC9mO232L7LcB5wF8BdwKXA5ttzwc2l30knQ0sB84BlgLXS5pRursBWAnML7elJb4C2G37LOAa4OrS12xgNXA+sBBY3S5IERFx6I331NMi4N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plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(english_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "e7a1c634-7050-4620-a970-713fde32af40", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(set(xcb))" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "81c5bc01-b60b-4d26-9f19-231854f4f6de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((4, 2, 1, 6, 3, 5, 0), False, True)" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_b, _ = column_transposition_break(xcb, fitness=Ptrigrams)\n", + "word_b, fill_b, empty_b = key_b\n", + "word_b, fill_b, empty_b" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "7aa6dff2-f12c-4212-83df-3a9bb7b76334", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'isuspectyoualreadyfoundandreadmymessagetocharliesothisletterwontbeasurpriseimtakingachanceandiamaskingyoutodosoaswellyouwillnotregretittherearegoodreasonswhyyoudothejobthatyoudobutyoumustbefrustratedbythelimitationsofworkingundergovernmentsupervisionandihopetopersuadeyouthatyoucoulddobetteryouaretalentedandhardworkingthefactthatharryrecruitedyouwouldbeenoughtotellmethatbutyourrecordisoutstandingtooyourworkonthekompromatfilesfirstattractedourattentionbutwhenharrymovedyoutobosscentralirealisedthatapproachingyouwastoobigarisksowesteppedbackandhavewatchingwaitingfortherightopportunitytoinviteyoutojoinusyouwillhavedoubtsatfirstwealldidbutifourfounderscouldbeheretomakethecaseithinkyouwouldfinditeasiertoacceptcarolineherscheladalovelaceflorencenightingaleandmaryeverestboolewereexceptionallytalentedwomenwhofoundawaytostepbeyondtheboundsplacedonthembysocietywhilestillretainingtheirpositionourgroupthatyouhavebeencallingthelighthouseconspiracyhasmaintainedanunbrokenlineofpowerandinfluencewieldedbysomeofthegreatestwomenofeachgenerationicantcountmyselfoneofthembutidocountmyselfasluckytoservewiththemandisuspectyouwouldtootherewardstobegainedfromthisworkaregreaterthananythingyoucanachieveinyourcurrentroleiknowthatyouhavethoughtaboutitireadtheemailyousentharryyouareboredinyourexiletothearchaeologistsifyoujoinusyouwillneverbeboredagainicannothopetoconvinceyouinaletterbutidohopetopersuadeyoutotakethisofferseriouslyiampreparedtomeetwithyoubutofcoursetherewillbeconditionsifyouarewillingtoatleastconsideritthenisuggestthatyouvisitthesouterpointlighthousewhereithinkyouwillfindsomethinginterestingihavetofinishwithawarningthinkverycarefullybeforereportingthisweknowthatyoudidnotsharethelastinterceptwithharryandyoushouldconsiderwhathewouldmakeofthatespeciallyifhebecameawareofthisletterhopingtohaveanopportunitytopersuadeyoutrinity'" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pb = column_transposition_decipher(xcb, word_b, \n", + " fillcolumnwise=fill_b, emptycolumnwise=empty_b)\n", + "pb" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i suspect you already found and read my message to charlie so this letter wont be a surprise im\n", + "taking a chance and i a masking you to do so as well you will not regret it there are good reasons\n", + "why you do the job that you do but you must be frustrated by the limitations of working under\n", + "government supervision and i hope to persuade you that you could do better you are talented and\n", + "hardworking the fact that harry recruited you would be enough to tell me that but your record is\n", + "outstanding too your work on the kom prom at files first attracted our attention but when harry\n", + "moved you to boss central i realised that approaching you was too big a risk so we stepped back and\n", + "have watching waiting for the right opportunity to invite you to join us you will have doubts at\n", + "first we all did but if our founders could be here to make the case i think you would find it easier\n", + "to accept caroline herschel ada lovelace florence nightingale and mary everest boole were\n", + "exceptionally talented women who found away to step beyond the bounds placed on them by society\n", + "while still retaining their position our group that you have been calling the lighthouse conspiracy\n", + "has maintained an unbroken line of power and influence wielded by some of the greatest women of each\n", + "generation icant count myself one of them but i do count myself as lucky to serve with them and i\n", + "suspect you would too the rewards to be gained from this work are greater than anything you can\n", + "achieve in your current role i know that you have thought about it i read the email you sent harry\n", + "you are bored in your exile to the archaeologists if you join us you will never be bored again i can\n", + "not hope to convince you in a letter but i do hope to persuade you to take this offer seriously i am\n", + "prepared to meet with you but of course there will be conditions if you are willing to atleast\n", + "consider it then i suggest that you visit the souter point lighthouse where i think you will find\n", + "something interesting i have to finish with a warning think very carefully before reporting this we\n", + "know that you did not share the last intercept with harry and you should consider what he would make\n", + "of that especially if he became aware of this letter hoping to have an opportunity to persuade you\n", + "trinity\n" + ] + } + ], + "source": [ + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "6cecddd9", + "metadata": { + "Collapsed": "false", + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2333" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "07c92adb-74e2-476e-adff-887c0145617d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'10101 11000'" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cb[:11]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "832dc153-c9e3-4134-9425-8014847c3870", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "21" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int('10101', 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "d7002750-66fd-4435-8ee8-023ae8376f33", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9865" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scb = cat(c for c in cb if c in '01')\n", + "len(scb)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "f3c2587e-7b76-49fb-ba60-ed3efc148c85", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 25)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ncb = [int(g, 2) for g in cb.split()]\n", + "min(ncb), max(ncb)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "bf189676-3c25-420d-9330-b77cc57c7a82", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'vyietbcbuwabmfbeslwnqafcylayovkbuxrhcwalhlpvknvmpbjszmxrbeonvwwhlznzkgortuilzxvvawmgvvlogumljprqzfmvvvvzqnjxvkbmgyiezrqmvizqlyvkqimewbedramgzrbvvzmniweotlbjigqhlteljmayovbblhcovzlbaggxerktlmfxhbmfxdwsnmfxjkrvmsgwwebnltkmygbkpfzxqgepzbudxprtwaamptzvrlkclfcekxqwvacqmctctbckntelrubaiimcikymzwaabraraomxlarzqehpdfdrzmfxcifbxgzybrmgkhebuatqiciavxbpvcfmwravkeqlglkwruucwdwemhnxiigqoclrbgpxfxrzgwyehmmevfcgklrkbqbfvzidggxcalxpmympwockfnfizctelgpxmmymevxuvfuzqmrxvajmgmpyiimtlxkebzdmyjkvmgrbjbfigbxeovvxckjqaeagmvpnteubkpgpxbbimpbxykfnfmgghikvdbjlvziigrlrvqxhjbkqpqtllkprgtjlfprticwlagwblyztgztrxtwcobtbeohawgkvkgivaxjagwtlndjrzhdhkprzzmovzauxlmjbuimftuzrutggvlomrmguwhzkcttpjpbjxnmjmkcgfbnjecmfnhtewwvtvdxphewhzijteaswkrarbrdxlmkprkhlgvkgqhllnmziwcpzbuahkxfngpxuhitqaeykxmfbvmfgiaqxqtelfutjevagamymvajqejllzrtrntpwsnblmymzmwgndbrzfmgkprlhugjqqmbftmmabaywkprktnttqggblxvlgwpmkbwabacufafqgtxjbvotrbfvvvmmhlzbzzygzanbbmgkpnbbquvqaoksgwzbumfxrzpptchcwtgwgozavwgfximnbzaahquiwfhgmqbaymrafqzlfvvguxygkbuimravknaxutjzrotpwvlnaempgzvwkgmpjhbaykignalgzemqpbquvagizcgkrblbcmfzhvbrteltiocavzntfmlkcatbkbkmqzxqhlzpmlqavpnamctdanteyviwfamfxlsgztuezvtbaphloubacirxrzluxcmsbucazvqimravtvoarafcfmtlwkzlqgemfebzdmnkeuimravgzmtlbrufwtlzignbfwlvtsnhpmyigjnrbyiimickjwaiejrtprkdcwrvqiejmymzicmkzbruldkfugpxdhlvqimgheiekagoverzxqazxcmwmnkbbutqlfceqxygupndxzxvvfmvskvlnbmfxgiesbyljqtvxbtkmnummfrsranpxkpnbmfxbmllhandmabluximczhnxitlmgakpxgmwggtifmcmwzmfbxyfwqallravuocmebmmabacmrtrvmqavqfehpdzvtebrazvbemfbesjmfgzybamxbmfbnsxdnibumkqmvxfigbbgtnvmmozavbmfxyynalmheifqvygxmgipyrnprbackfzawmhhuqrigbavzgmtkpfzxwnrpyigexykvlbqgemymomlrprggwfydvahzxrarbuikpruwragmmwqalhsmdqtpmzxkwpwgtbekrpxpgfbgwmcecpvubftmmomxlvrzegblzfcgahkxsipszphlvqkacvbanvwgtdebvwckzvtqyuxjpbcebclagbkwmfzrkksbkprzwgkvkgtrgyjpretqpfzxqgepzbuclravvvulskvaumpmnclfmxravvrmwdhiarkkcvpbumwgkvkgiinkfippbqkzaxgusmkprwketeqfimghepnagcovzfpbcwrengyphdbuimzxwwemhprfcnvwgpfcylgruvebzdggxnbzbrbkpvvdgmzanzbqdnwebartbqaormnitbdblzeqrkxrkzvvbr'" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tcb = cat(unpos(n) for n in ncb)\n", + "tcb" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "59f072b0-f8ca-4f08-922d-cfb5dfc68fe4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'beuxmwnprjiztavlsfgkqdyhco'" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_b, score_b = monoalphabetic_sa_break(tcb)\n", + "word_b" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "16210c33-3bcb-43c8-9189-d82eea7cf53b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "trinity \n", + "\n", + "charlieidontthinkyoushouldhavecometolondonwecantriskmeetingandyourarrivalhasbeennoticedbybossheighteningsuspicionharrysteamisactivelyinvestigatingourorganisationandwehavetodoeverythingwecantoputthemoffthescentunfortunatelyimworkingwithveryconstrainedresourcesdespiteallourpandemicpreparationsithasbeenhardworkoverthelasteighteenmonthsasplannedweusedthecrisistoembedmoreoperativesattheheartofgovernmentdecisionmakingunderthecoverofsageandtheothernewcommitteeswenowhaveanetworkofscientistsandengineersinwhitehallwiththedirectearofseniorcivilservantsandpoliticianstheyalsohelpedustoinfiltratecopgivingusdirectaccesstoanumberofothergovernmentsthathadremainedbeyondourreachwhilewewerenotabletofullydeliveronourplansforthateventtheconnectionswemadewithsomeoftheworldslargestcompaniesandsmalleststateswillsurelypayoffinthemediumtermonthedownsideihaventhadthecapacityineedtoworkonthebossinvestigationintoourorganisationthatisbeingrunfromthearchaeologydivisionhereatgchqihadhopedthatassignmentmeantthatthecasewasregardedaslowprioritybutharryassignedhisbestagentjodietorunitandgaveheralmostunlimitedresourcesshehasteamsallacrosstheuktrawlingthroughthepapersweleftbehindatthelighthouseandtryingtoworkoutwhattheymeaniamsoangryatmyselfforthatbutihavepersonallycheckedandallthemajoritemsfromthefoundationarchivewereshippedouttomassourieandhavebeensecuredattheparkiassignedateamtomakesurethatthekeydocumentswereproperlyencryptedincasejodiesteamfindsthembutgiventhetalentsheisworkingwithinowthinkwemightneedtotakefurtherstepsandiplantovisitthehqassoonasicangetawaywhetherornotjodieandherteamworkoutwhatwearedoingthebestwaytomakesurethatharrydoesnotfindoutmightbetoconvincehernottotellhimihavebeencarryingoutsomebackgroundchecksandiamwonderingifweshouldjusttrytorecruitherdirectlyifshewasworkingwithusthenimsureshewouldseetheneedforsecrecythedirectapproachisriskybuttheorganisationhasnevershiedawayfromthatbeforeoryouandiwouldntbeworkingforitithinkitisariskworthtakingyourlovingniecetrinity\n" + ] + } + ], + "source": [ + "word_b, score_b = vigenere_frequency_break(tcb, fitness=Ptrigrams)\n", + "print(word_b, '\\n')\n", + "pb = vigenere_decipher(tcb, word_b)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "fe094361-7c85-40d9-952e-0c84abbcf903", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "charlie i dont think you should have come to london we cant risk meeting and your arrival has been\n", + "noticed by boss heightening suspicion harry steam is actively investigating our organisation and we\n", + "have to do everything we can to put them off the scent unfortunately im working with very\n", + "constrained resources despite all our pandemic preparations it has been hard work over the last\n", + "eighteen months as planned we used the crisis to embed more operatives at the heart of government\n", + "decisionmaking under the cover of sage and the other new committees we now have a network of\n", + "scientists and engineers in whitehall with the direct ear of senior civil servants and politicians\n", + "they also helped us to infiltrate cop giving us direct access to a number of other governments that\n", + "had remained beyond our reach while we were notable to fully deliver on our plans for that event the\n", + "connections we made with some of the worlds largest companies and smallest states will surely payoff\n", + "in the medium term on the downside i havent had the capacity i need to work on the boss\n", + "investigation into our organisation that is being run from the archaeology division here at gchq i\n", + "had hoped that assignment meant that the case was regarded as low priority but harry assigned his\n", + "best agent jodie to run it and gave her almost unlimited resources she has teams all across the uk\n", + "trawling through the papers we left behind at the lighthouse and trying to workout what they mean i\n", + "am so angry at myself for that but i have personally checked and all the major items from the\n", + "foundation archive were shipped out to mass our ie and have been secured at the park i assigned a\n", + "team to make sure that the key documents were properly encrypted in case jodie steam finds them but\n", + "given the talent she is working with i now think we might need to take further steps and i plan to\n", + "visit the hq as soon as i can getaway whether or not jodie and her teamwork out what we are doing\n", + "the best way to make sure that harry does not find out might be to convince her not to tell him i\n", + "have been carrying out some background checks and i am wondering if we should just try to recruit\n", + "her directly if she was working with us then im sure she would see the need for secrecy the direct\n", + "approach is risky but the organisation has never shied away from that before or you and i wouldnt be\n", + "working for it i think it is a risk worth taking your loving niece trinity\n" + ] + } + ], + "source": [ + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2420" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge8.md b/2021/2021-challenge8.md new file mode 100644 index 0000000..4bb2ff7 --- /dev/null +++ b/2021/2021-challenge8.md @@ -0,0 +1,185 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.polybius import * +from szyfrow.railfence import * +from szyfrow.support.text_prettify import * + +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +import collections +%matplotlib inline +``` + +```python Collapsed="false" +challenge_number = 8 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +ncb = open(ciphertext_b_filename).read() + +numtrans = ''.maketrans('12345', 'abcde') +cb = ncb.translate(numtrans) + +sca = sanitise(ca) +rsca = cat(reversed(sca)) +scb = sanitise(cb) +rscb = cat(reversed(scb)) +``` + +```python +sca_counts = collections.Counter(sca) +sca_counts +``` + +```python tags=[] +pd.Series(sca_counts).sort_index().plot.bar() +``` + +```python +key_a, score_a = vigenere_frequency_break(sca, fitness=Ptrigrams) +key_a, score_a +``` + +```python +pa = vigenere_decipher(sca, key_a) +pa +``` + +```python +print(prettify(pa)) +``` + +```python Collapsed="false" tags=[] +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +word_a, wrap_a, col_a, row_a, col_first_a = key_a +polybius_decipher(sca, keyword=word_a, column_order=col_a, row_order=row_a, + column_first=col_first_a, wrap_alphabet=wrap_a) +``` + +```python +xcb = polybius_decipher(scb, keyword='a', column_order='abcde', row_order='abcde', + column_first=False, wrap_alphabet=KeywordWrapAlphabet.from_a, + letters_to_merge={'z': 'y'}) +xcb +``` + +```python +sncb = cat(l for l in ncb if l in '12345') +xcb = polybius_decipher(sncb, keyword='a', column_order='12345', row_order='12345', + column_first=False, wrap_alphabet=KeywordWrapAlphabet.from_a, + letters_to_merge={'z': 'y'}) +xcb +``` + +```python +scb_counts = collections.Counter(xcb) +scb_counts +``` + +```python tags=[] +pd.Series(scb_counts).sort_index().plot.bar() +``` + +```python tags=[] +pd.Series(english_counts).sort_index().plot.bar() +``` + +```python +len(set(xcb)) +``` + +```python +key_b, _ = column_transposition_break(xcb, fitness=Ptrigrams) +word_b, fill_b, empty_b = key_b +word_b, fill_b, empty_b +``` + +```python +pb = column_transposition_decipher(xcb, word_b, + fillcolumnwise=fill_b, emptycolumnwise=empty_b) +pb +``` + +```python +print(prettify(pb)) +``` + +```python Collapsed="false" tags=[] +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +cb[:11] +``` + +```python +int('10101', 2) +``` + +```python +scb = cat(c for c in cb if c in '01') +len(scb) +``` + +```python +ncb = [int(g, 2) for g in cb.split()] +min(ncb), max(ncb) +``` + +```python +tcb = cat(unpos(n) for n in ncb) +tcb +``` + +```python +word_b, score_b = monoalphabetic_sa_break(tcb) +word_b +``` + +```python +word_b, score_b = vigenere_frequency_break(tcb, fitness=Ptrigrams) +print(word_b, '\n') +pb = vigenere_decipher(tcb, word_b) +print(pb) +``` + +```python +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.8a.txt b/2021/ciphertext.8a.txt new file mode 100644 index 0000000..11c470e --- /dev/null +++ b/2021/ciphertext.8a.txt @@ -0,0 +1 @@ +DECCR OAKNY ZAJLP WRZJC PFFLL KTYVY ATRTF LDCVR AEIFL TYUFM YMRKG UATFN FOWKF LLFTY SMRXY GIEVG AWRJA SEMVP YERCJ FTYVP LIJEM DAPKM ARRTI IATBR VHFNG AGFKR OEIVY UDEFN VIEKG UWRJR PNXKG TEFIP LSFLP JEJKP FIEXR VFZEB VUKZL HNPTY ZEZKU HSTCC HRKYY ATIZL PTPJC UTZKY UDVHS HLCPA SERIU OAKJF LWRER LDVMC UTYVA PPYVP AHVPF HVVLQ LDZJY TEJJY NEKFK LIKZQ KOLSJ LEETP FPKVB DIKYR OEJVA VNUJR HGVLQ PNXKF LSRDC WOCPZ PUJXP PDZLQ LDWFP TYCRQ ADZRP FEEKP FTYVW HRVKC SLZEE TEKYY AIYRT LNFNF LRVKM OIUVM UCVZQ ARZGN LDKYY AOWWG DAJCC MTNZR OAJKY UDRIB IUKKP PCBPA PPYVP AOSIC HKWFP AUERR LLPZJ LAIEC KTYVB HRBRP ASFWD YEHLC UCPRL HLPJG ZAEUA YISSG UGWIM THRIP FSFZR KIUER AABVJ VNXKM JRRTI PTKYC ZETFL KSLIN YIJVG ZTYRR PDFER RNFNU OAKKM KOEFP TACCW HNPLL ZOCZA PTVUY WPIFY JHCZI LTYZQ DOLCB IEZEQ AAEKJ FRVGM YTVUR VTYVJ HMGCG NHKVP ZSFKF LYTFS SDZET LSKZE HTVSS AAJKP PNZKW WOZER ZOLKG OAURJ YERUW JOETC HLVUR OECRQ AIEKC YCVGR MRFDF HRIPU VRIZC KTYRR PTDZE OTURK HGVYG ZTILQ AIEDC PTNZJ SNFKJ VOBXM VDZWF LFZEB ZTYRR VUKWP VMKYC TBLKG MIKVJ SHZDR OEEZU PLCRJ ZOYRT LTFKC SLYZK HBFLR AHZJB PRVTR HPGVY STFAM PNKYC TIUFL ATYZL RTYRR DICCK HKVKF PNXJY UYSVR AEISC AWVVL BSKYC YEZJQ VMVKF PNXVJ ZEKFM AHVWM BNUVP ZOWKF LCFEQ WIIRA FAIVN LRJFL HLYVP VEJFD TIEVY UDZTY UTSVY YTFKF PNBKF HTKYC FMZXF AHRMC IEVEU VRBZL NFFIR OEURP RSZUC PFZKG ZTILC AHVEG DOLCB YAKYC YFZEB VUKWM YMPJC SFKYY ULVRT LIKKM VTYVP ZIESM ZSZJS WPFJC PCFLJ KTVCJ HLCRL KOWWC YTFZL MICKP HTVKF LAXVL JYSLR AHVYG ZTFIW VFUFS ILVRE LNKJG ZNFKY OAGGW VNVZR PSYRP KTFIC HLCPR YUJKQ VMVFL LWYFF HSNFP REUWM YTYVM WPFJG AIFEC CEEZD AHVPB VIKLL KEITM CEIKM VMREW OAMVZ LEETM YRLGR LDSPR OETFK WRFDG ZEJIC XUZIC KAEUG HMEFR ZUIVG HMTLR VUKWM YTYRR ZOIKM MWFII PDFER AHZEI OAIIW DOLCB PNJZQ ABLKG HMTVP AAZEQ VMVSM KYZEZ VSJNM BLUKF LTRCI VFKYC WAEUC TITRL KCFGU PLCSC HRVUD SAXRL KSFDC VNVJM TENYC YENZJ SBVUC ZPVIY AEKFZ YERBG UTFKF LCFEQ WIIRA FDVJN LRRKC LNFLE OTFDY REDVY UOWWC YITRL ARVWS ZEZNG SLYRT LTFKY REKYG ZFLIR OEISS ABVWM YEZRE YEVKM TEVKR YIEZR FIEVC KTFBL VWDFP LTYVL HMVFD AHVJM BTVIN VIEKJ PGYKF VUJVP PNXJY IECCZ BTZTY UTIVK LMSVP DHVIC PCRDC HCIFQ ZIKZU PLCYY CEKFE LTKYC ARRZL LEJKM MIXLP LOLKU OYZKK PGYKZ LIDGM YTRER TEREU OICVG OAMVY UOKYC YMFIC BRXVL ATIZN AODRI LTFDY ZSFLP PE \ No newline at end of file diff --git a/2021/ciphertext.8b.txt b/2021/ciphertext.8b.txt new file mode 100644 index 0000000..b90daf3 --- /dev/null +++ b/2021/ciphertext.8b.txt @@ -0,0 +1 @@ +41112 11433 45244 45344 15341 33355 44323 24315 35353 52555 45454 55524 44244 33315 34414 45151 35551 11153 45454 32453 15354 55535 45345 13441 24441 31135 15335 11324 15412 41122 35411 15322 22434 14524 35552 31243 32245 13515 31443 13245 45453 42335 21153 41415 35153 51153 35531 51434 15331 51515 22353 54151 15342 21543 33341 22453 34151 43515 35114 31334 21231 43344 35241 14153 35111 52144 15435 53523 55431 52311 22451 42434 55353 51543 35213 42443 14133 53435 45244 51135 24443 21535 45454 45335 34112 43234 45512 32444 35235 32353 14244 32421 24343 41155 43341 51114 43441 32334 35441 13221 41551 34344 23353 53415 55245 13514 11332 24323 15152 43111 24341 41524 15451 51155 23111 25151 14243 54314 43512 42315 55551 41515 15433 41311 43351 22333 51153 51455 31354 52443 51455 34355 44112 44513 51123 11513 52242 42335 34345 15132 35211 15121 44153 31324 35141 51532 44111 33445 11151 24345 55155 31444 35351 12313 24322 44335 35551 23232 51411 11151 34411 43414 33224 52134 34351 52145 34215 51515 51354 51535 15231 14511 22112 45135 53513 53515 33444 31534 24153 54435 51524 33445 13153 25141 44514 51551 41145 31251 43152 43532 11134 32445 51234 32444 24352 44545 34452 31123 55324 34544 45142 33215 24554 43553 35151 53212 53231 52211 45351 42444 55111 41411 11454 51243 11231 42435 53534 34543 15234 52335 33431 53224 35341 54444 24411 54532 45434 51124 11231 35514 22321 24344 34354 33111 21453 53445 43143 54332 11113 53544 45111 12345 45455 12435 34241 44515 12434 31235 15235 33424 13354 31411 15231 55545 15413 24534 34355 51232 45352 33234 24244 34515 32153 54423 45341 52134 15323 51544 35153 51344 35515 13231 52234 45514 43453 44531 11343 43415 13433 53523 12431 55143 43245 42315 45253 51535 24353 51311 12354 33515 21353 31545 51351 51245 55243 54515 34443 54515 32511 55521 15342 41544 53454 35135 43245 35144 15455 34351 13435 33145 11151 14545 34154 34511 43134 35115 44134 41534 43331 11144 51113 53545 15144 41412 51351 51123 11212 23534 52344 51123 35155 11514 43151 14315 51351 51151 14454 55323 35151 11545 12235 23534 15454 32245 43151 41445 11352 24345 15355 15244 45243 51432 15452 43521 11111 12332 15352 41111 15151 31115 33355 51223 44355 55545 11232 44323 11134 54535 13241 43515 43322 45545 45152 34534 33343 31344 51152 31413 51231 41135 35432 32313 15513 43145 15454 52355 23511 54335 23243 54432 15223 41524 24153 54115 11354 32411 15552 14532 14241 52211 24232 24524 51342 31534 32352 24411 34233 45215 15414 53455 35452 44111 55321 42333 23132 13335 15411 14145 44515 54451 55345 51532 24431 14424 34112 23532 32222 32244 55154 55144 44123 33431 15344 13535 43353 51443 45141 42245 43515 11545 15451 35124 35353 32143 11432 42355 35443 24411 23532 44441 31153 43415 41245 24544 32512 43245 35132 31111 34512 44341 24133 21513 24345 23515 24451 42311 45345 11315 24324 33441 34513 51524 24442 44424 34323 52413 15154 35315 15245 13245 24451 14553 33445 13553 12142 44315 34551 33443 32452 35151 11111 55512 55321 13224 24531 51524 23355 51545 15514 52343 44434 52451 43151 33551 32453 52444 45521 54122 15455 13423 15223 55343 24133 21524 53232 41111 43451 12334 23513 54432 15112 44345 34514 11534 15323 54315 35153 23551 24221 51135 35553 41543 35345 13535 55124 34545 35342 21543 11155 14513 12353 23435 23235 54535 34452 33543 44224 34543 32454 54534 34354 51543 14413 44411 53153 41153 21243 55545 25351 14544 14213 45143 15155 51415 35131 51552 32342 23343 32543 43235 21114 14514 14124 54445 45445 14523 34222 31311 11154 33415 21531 22111 33131 11145 35153 55532 44453 41535 45432 24353 22454 55124 35152 41152 23244 53245 35435 14513 22555 13212 11114 15251 45143 51445 44155 54133 23351 52434 44433 41544 45221 14435 24452 32424 44341 52324 45243 14312 15223 14534 15451 52314 51244 51445 15241 11532 35234 12443 35452 44515 34114 42335 45454 14513 34314 54451 45241 14353 35451 45121 45154 55351 52452 41435 14115 14511 34233 12145 15143 25132 45432 41135 35153 34445 14155 11115 12451 12335 55352 44412 23132 44323 45355 52453 15115 31451 15144 52345 51244 41343 15113 24322 32434 45315 32341 55145 15154 13444 53242 41545 22115 21123 23345 53411 31351 15115 44231 53422 24455 51512 35151 34345 24453 21544 24334 31511 24115 24345 34554 51124 15351 11114 15451 14451 55341 21134 45343 44323 15553 12124 11431 53513 23322 42153 45441 41515 55454 54535 43313 23324 45522 41122 15212 13523 35354 52334 45433 51415 15111 12423 15214 52452 35555 145 \ No newline at end of file diff --git a/2021/plaintext.8a.txt b/2021/plaintext.8a.txt new file mode 100644 index 0000000..c409609 --- /dev/null +++ b/2021/plaintext.8a.txt @@ -0,0 +1,24 @@ +well that was a surprise i found the attached letter on my doormat in a copy of the local magazine +it was clever really there is no way to trackback to how it got there and no point in wasting time +or resources trying to find out in any case it was clear that trinity sent it and equally clear what +she wanted even the cipher they have used is a message to me it is double encrypted with the second +stage using the same polybius grid i used for my last diary entry they are telling me that i have +nowhere to hide once i stripped that off i was left with a standard but tricky cipher to break +fortunately i learned the dark arts of frequency analysis and cribbing from harry so it didnt take +long to crack it the second surprise is that i dont know what to do normally any unsolicited +approach like this would be instantly reported to the lamplighters so they could investigate but as +trinity points out i had already concealed the last intercept from harry worried that it might +damage his trust in me it will not look good if he finds that out from them but if i tell him then i +will also have to tell him about this direct appeal to join them i dont think that will make things +any better between us there is something else too the founders of the conspiracy are personal heroes +of mine and icant bear to think that they might have been working for the darkside if it is true +then i would rather find out for myself than leave it to others in boss i suppose i could tell all +and offer to infiltrate the agency but the history of double agents is not a happy one it is hard to +really trust someone who has worked for the opposition even if they do it undercover too many have +been corrupted by the compromises required and i am not sure i am cutout for that sort of work i +dont think harry would insist but i am certain somebody in boss would the talk of the pandemic and +cop will be a red flag and someone somewhere will be desperate to break into the conspiracy +desperate enough to make mean offer icant refuse i will have to take this further but before i agree +to meet trinity i need to know more the name of the souter point lighthouse rings a bell but icant +remember where i came across it i will have to get the trainees to figure out why it might be +important meanwhile i have another more urgent trip to make to mass our ie \ No newline at end of file -- 2.34.1 From 7d717b0a1967a6df0d214013105e14822d446304 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 12 Dec 2021 16:05:48 +0000 Subject: [PATCH 16/16] Done challenge 9 --- 2021/2021-challenge9.ipynb | 545 +++++++++++++++++++++++++++++++++++++ 2021/2021-challenge9.md | 125 +++++++++ 2021/ciphertext.9a.txt | 1 + 2021/ciphertext.9b.txt | 1 + 2021/plaintext.9a.txt | 29 ++ 2021/plaintext.9b.txt | 40 +++ 6 files changed, 741 insertions(+) create mode 100644 2021/2021-challenge9.ipynb create mode 100644 2021/2021-challenge9.md create mode 100644 2021/ciphertext.9a.txt create mode 100644 2021/ciphertext.9b.txt create mode 100644 2021/plaintext.9a.txt create mode 100644 2021/plaintext.9b.txt diff --git a/2021/2021-challenge9.ipynb b/2021/2021-challenge9.ipynb new file mode 100644 index 0000000..ba65216 --- /dev/null +++ b/2021/2021-challenge9.ipynb @@ -0,0 +1,545 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 78, + "id": "5c19999b", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "from szyfrow.caesar import *\n", + "from szyfrow.affine import *\n", + "from szyfrow.keyword_cipher import *\n", + "from szyfrow.column_transposition import *\n", + "from szyfrow.vigenere import *\n", + "from szyfrow.polybius import *\n", + "from szyfrow.railfence import *\n", + "from szyfrow.hill import *\n", + "from szyfrow.support.text_prettify import *\n", + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import collections\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "d9dd1b5e", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "challenge_number = 9\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": 38, + "id": "0f1f792a", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "\n", + "sca = sanitise(ca)\n", + "rsca = cat(reversed(sca))\n", + "scb = sanitise(cb)\n", + "rscb = cat(reversed(scb))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b8d5f9ec-27f1-498b-8e64-c5eb2424e581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'a': 190,\n", + " 'g': 49,\n", + " 'y': 56,\n", + " 'b': 28,\n", + " 'w': 66,\n", + " 'd': 80,\n", + " 'l': 101,\n", + " 'k': 21,\n", + " 'n': 160,\n", + " 't': 242,\n", + " 'o': 168,\n", + " 'h': 132,\n", + " 'i': 184,\n", + " 'r': 122,\n", + " 'p': 31,\n", + " 'e': 260,\n", + " 's': 119,\n", + " 'u': 59,\n", + " 'f': 39,\n", + " 'c': 57,\n", + " 'v': 26,\n", + " 'm': 48,\n", + " 'x': 2,\n", + " 'j': 1})" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sca_counts = collections.Counter(sca)\n", + "sca_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b5cabba1-ac75-46ea-ac05-8699cc88d986", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAR4UlEQVR4nO3df7DldV3H8edLJDRAg1hwA3TR2RQow1zBRpwoKlBz0BJbaojK2iIo7IcFZmlOmzilzmRholibobipBDOWRFsNUirsAvFjF8ZVfriywfordhxFdn33x/munC7n3vO95967e++H52PmzDnfz/l8zvd9v3fP63zO9/u9301VIUlqyxP2dQGSpPlnuEtSgwx3SWqQ4S5JDTLcJalBhrskNeiJ+7oAgMMOO6xWrFixr8uQpCVl06ZNX6yqZaOeWxThvmLFCjZu3Livy5CkJSXJvdM9524ZSWqQ4S5JDTLcJalBhrskNchwl6QGGe6S1CDDXZIaZLhLUoMWxR8xPd6suPBj0z53z8Uv24uVSGqVM3dJapDhLkkNMtwlqUGGuyQ1aGy4Jzk6yb8n2ZLkjiQXdO1vSvKFJLd0t5cOjbkoydYkdyU5bSF/AEnSY/U5W2YX8DtVdVOSg4FNSa7tnntHVf35cOckxwGrgeOB7wH+Ncn3VtXu+SxckjS9sTP3qtpeVTd1j3cCW4AjZxhyBnBFVT1cVXcDW4ET56NYSVI/s9rnnmQF8Dzg013T+UluTfK+JId0bUcCnx8ato0RHwZJ1iTZmGTjjh07Zl+5JGlavcM9yUHAR4DXVtVDwLuAZwEnANuBt+3pOmJ4Paah6tKqWlVVq5Yt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Boa7NEtJtgDPYnDwbzHurtI8S/I6BoG+qc83hMXAcJdmadLdK9LeZLhLUoMW5R8xSZLmxnCXpAYZ7pLUIMNdkhpkuEtSg/4P/RyaCr9NUrgAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(sca_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "4a063a9d-2965-4d80-b01c-211d5d884d8f", + "metadata": {}, + "outputs": [], + "source": [ + "import itertools" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "000a175e-5afa-45fd-b347-a99fb619b469", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "362880" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "permutes = [transpositions_of(cat(t)) for t in itertools.permutations('abcdefghi')]\n", + "len(permutes)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "9055ba6c-6fea-4668-aa83-41deff3ba806", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((1, 4, 6, 3, 5, 7, 0, 2, 8), False, True)" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_a, _ = column_transposition_break(sca, translist=permutes, fitness=Ptrigrams)\n", + "word_a, fill_a, empty_a = key_a\n", + "word_a, fill_a, empty_a" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "7fad89d5-b42e-40d6-ad4d-a8d41cacca84", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'harryifyouarereadingthisthenyouareprobablyalsowonderingwhereiamiamsorrytodisappearbutihavealottothinkaboutandneedtoworkthingsoutonmyowniamonthetraintomassourienowandhopingthatiwillfindtheanswersineedtherethoughihavealreadybeguntoputthepiecestogetherthestorystartedatmichaelfaradayslighthouseattrinitywharfandthatshouldhavebeenabigclueespeciallywiththereferencetothefacilityinflorenceslettertohimwetakeitsomuchforgrantednowthatwemissedtheimportanceofthatplaceitwaswhenilookedintosouterpointthatirealisedwhyitmightberelevantandnowasitravelthroughthefoothillsofthehimalayaitisallcomingintofocustheattachedreportwasdiscoveredbyoneoftheelvesinthelampatsouterpointandwasclearlyleftthereformetofindiamstillnotsurewhattheconspiracysetouttodobutinowknowthesignificanceoftrinitywharfandsouterandicantakeagoodguessatwhytheywereinterestedingeorgeeverestshouseinthemountainsidontknowwhyithinktheremightstillbesomethingtofindtherebutsincetheconspiracyisclearlystillactiveihavetoknowwhattheyaredoingandthisistheonlyleadihavetheconnectionbetweentheearlyconspiratorsisalsomuchclearertomenowtheyallhadaninterestinmathematicsandthenaturalsciencesadalovelacewasakeymemberofbabbagesteamwithherearlyexperimentswithprogrammingmaryeverestboolewasanexpertinlogichighlyeducatedandwellversedinindianmathematicalthoughtatfirstflorencenightingaledoesntlooklikeagreatfitwiththegroupsheiscelebratedmoreformodernisingnursingbutherinnovationswerebasedonseriousdataanalysisusingeverythingsheknewaboutstatisticsandthatwasalotcarolineherschelwasanotherremarkablewomanthefirsttobepaidasalaryasascientistbutithinkherrolewassomethingmoreshehadhugeinfluenceinsocietyandalsoheldapositioningovernmentlikecharlieandtrinityshewastechnicallygiftedandwellplacedtotakefulladvantageofthosegiftsineedtoknowwhattheyaretryingtodowhyandhowtrinitywarnedmenottotellyouaboutherletterbutthatwasneverapossibilityevenifididntletyouknowwhatwasgoingoniamprettysurethatyouwouldhavefoundoutandiwouldmuchrathertellyoumyselftheonlyreasonididntcometoyoustraightawayisthatistilldontknowwhatisgoingonandididntwanttoputyouinthedifficultpositionofhavingtodecidewhethertotrustmeornothopefullythisvisitwillprovidetheevidenceweneedtounraveltheconspiracyandtoclearmynameiwillwritetoyouagainwithnewsfromtheparkjodie'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# mod_word_a = (1, 3, 6, 4, 5, 7, 0, 2, 8)\n", + "pa = column_transposition_decipher(sca, word_a, \n", + " fillcolumnwise=fill_a, emptycolumnwise=empty_a)\n", + "pa" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "b3271971-d4b5-4f8a-aab7-0ca141b83f5f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harry if you are reading this then you are probably also wondering where i am i am sorry to\n", + "disappear but i have alot to think about and need to work things out on my own i am on the train to\n", + "mass our ie now and hoping that i will find the answers i need there though i have already begun to\n", + "put the pieces together the story started at michael far a days lighthouse at trinity wharf and that\n", + "should have been a big clue especially with the reference to the facility in florence s letter to\n", + "him we take it so much for granted now that we missed the importance of that place it was when i\n", + "looked into souter point that i realised why it might be relevant and no was i travel through the\n", + "foothills of the himalaya it is all coming into focus the attached report was discovered by one of\n", + "the elves in the lamp at souter point and was clearly left there for met of india m still not sure\n", + "what the conspiracy set out to do but i now know the significance of trinity wharf and souter and i\n", + "can take a good guess at why they were interested in george everest s house in the mountains i dont\n", + "know why i think there might still be something to find there but since the conspiracy is clearly\n", + "still active i have to know what they are doing and this is the only lead i have the connection\n", + "between the early conspirators is also much clearer to me now they all had an interest in\n", + "mathematics and the natural sciences ada lovelace was a key member of babbage steam with her early\n", + "experiments with programming mary everest boole was an expert in logic highly educated and well\n", + "versed in indian mathematical thought at first florence nightingale doesnt look like a great fit\n", + "with the group she is celebrated more for modernising nursing but her innovations were based on\n", + "serious data analysis using everything she knew about statistics and that was alot caroline herschel\n", + "was another remarkable woman the first to be paid a salary as a scientist but i think her role was\n", + "something more she had huge influence in society and also held a position in government like charlie\n", + "and trinity she was technically gifted and well placed to take full advantage of those gifts i need\n", + "to know what they are trying to do why and how trinity warned me not to tell you about her letter\n", + "but that was never a possibility even if i didnt let you know what was going on i am pretty sure\n", + "that you would have found out and i would much rather tell you myself the only reason i didnt come\n", + "to you straightaway is that i still dont know what is going on and i didnt want to put you in the\n", + "difficult position of having to decide whether to trust me or not hopefully this visit will provide\n", + "the evidence we need to unravel the conspiracy and to clear my name i will write to you again with\n", + "news from the park jodie\n" + ] + } + ], + "source": [ + "print(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "46512a70-68d4-4ea9-8f66-b39966232fa6", + "metadata": { + "Collapsed": "false", + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2772" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(prettify(pa))" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "24d8ad2e-b237-479b-9a62-af9bc8d100d5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Counter({'v': 129,\n", + " 'r': 173,\n", + " 'd': 103,\n", + " 'p': 124,\n", + " 'k': 68,\n", + " 'w': 107,\n", + " 'f': 95,\n", + " 'a': 234,\n", + " 'o': 176,\n", + " 'm': 96,\n", + " 'z': 47,\n", + " 'e': 265,\n", + " 'u': 66,\n", + " 't': 245,\n", + " 'c': 92,\n", + " 'l': 170,\n", + " 'h': 173,\n", + " 'g': 111,\n", + " 'i': 152,\n", + " 'x': 51,\n", + " 'n': 164,\n", + " 'b': 119,\n", + " 's': 118,\n", + " 'y': 40,\n", + " 'q': 68,\n", + " 'j': 44})" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scb_counts = collections.Counter(scb)\n", + "scb_counts" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "d66dd0d0-badb-44f3-a8a6-f7edd17d1532", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAA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MsZ7XJXkXsAb4/9uoqj46YszEt1mf0Jt97rCdactuA8z0/jyb+yaMn0FP9+0k7wB+D3hjt0w1bAXgA8B/03sg6P/a7601ZplxgF8FHjJBvzuA7wDfo/csaahu6WMfekH9WeDxVXXHmP3/AvgpvUnTfYFbqmro3/MOVVVJvtPVtg3YH/hwkiuqatAz61TVNuDlSZ5Pb1lu/3HH6bcYw31Tkl8D/hO4IskPGPHVBX2BcB/gT5N8s9t+ML1ZyUBV9d4ka4HfpfeH9gc1bS1tgPcBVye5pDvGc+g9LR3lX4FLgIOSrKK35PDaMWNm4wP0nmJf2m0/C/hgkn2Ydjv03Wb3Bl6Q5Ov0wm3smvMCe+ZOPt4L6D0zvA93PeAWMCrcjwWen+QWJr/N3k3vAeqSbvvZwPljansCd92foRfeG3b87gYcbzb3TarqG+P6TPM84ATgTVX1wyRLgVcP2feP6L3uc/Kg60eZ9kC/F7AEGPq6RpKXAX/U9fsw8OIJ/p6vAx4H/GZX5w+TfL6qfjpizJfoLc09Hvh14B1JnltVzx1R218Ap9L74q93Aa+uql8kuRfwVWBQuL99x4Wqek93e5w25ue5+3G7pwCLUpLfpvd05BPV++rgQX0ePGofs7jzjqvpsdz1wtiVVfXlCcY8HHgKvSBYU1Ub5rOmvuM8jl74hN6Sw8C1+p19my1WSa6vqkfOcMzA227cbdbdb3b8bsbeb2bzO5rNfXOxmvbzbwNu72ayw/qfDVxcQ948MOZY+9J7oP9rem922HtE36npf1dJTqmqoa+HJHkDcP6Q39kjFiwPFnO4SwspyTuBt04ww1ODunexPJne7P0b3PXOmf/ZpYXNE8Nde6wkG4Aj6L3AtxiWpbQTJXk1vUBfN+pZwe7KcNcea7ZLLNLuwHCXpAYtug8xSZLmznCXpAYZ7pLUIMNdkhpkuEtSg/4PXG2p4WznpsMAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "pd.Series(scb_counts).sort_index().plot.bar()" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "5bb4afa4-22c2-4826-87ad-a0f3e7aa867d", + "metadata": {}, + "outputs": [], + "source": [ + "key_b, _ = hill_break(scb, fitness=Ptrigrams)" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "875b1073-dd5c-4c4d-a028-865933ac472e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "matrix([[1, 1],\n", + " [1, 0]])" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_b" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "8107ca5f-b2e7-475b-abc5-0f9b7ec1863a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'reportfrommaryeverestbooletothecuriaofthetrinityfoundationthisreportwascommissionedbythecuriatorecordtheoutcomeofthecommissioningandactivitiesofthesouterpointfacilityandtomakerecommendationsonitsdevelopmentafteryearsofpioneeringworkbyfaradayandothersthedevelopmentoftheirextraordinarymachinesoutgrewthecapacityinourheadquartersattrinitywharfwitheachnewincreaseinspeedandpowertheriskofdiscoverygrewuntilthecuriahadnochoicebuttocommissionanewfacilityinspiredbythelessonslearnedinlondonitwasdecidedtobuildalargerestablishmentundercoveroftheconstructionofthesouterpointlighthousethefirstdedicatedelectricallypoweredlampofitskindthegrowthinminingintheareaprovidedexcellentcoverfortheinstallationofournetworkofcavernsunderneaththelighthouseandtheinstallationandmaintenanceofthelighthouselampsteamenginespumpsandgeneratorsdisguisedourownactivitiesasweequippedthebasetheholmesgeneratorsthatweprocuredareidenticaltothoseselectedforthelighthousesothatsparepartscanbeprocuredeasilywithoutraisingsuspiciontheyaredrivenbyapairofsteamengineslocateddeepintherockofcleadonhillbeneaththelighthouseengineroommuchofthenoiseandheattheyproduceismuffledbytherocksandthatwhichescapesismistakenbyneighboursforthechurningofthelighthousemachineryitseemsthatnosuspicionshavebeenarousedamongthelocalswhocontinuetobelievethatouractivitiesaresomehowrelatedtothelighthouseandtheminesitisawondertobeholdtheheavymachineryconvertingthemovementofthemassiveflywheelintotheimperceptiblemotionofmysteriouselectricalchargesthroughthewiresitisdifficulttocomprehendthatthevariouspartsofthemachinecancombinetoproduceanythingapproachinghumanthoughtandyetitcomputesmoreoverthiscomputerembodiesthevisionofthecountessoflovelacethatofamachinewhichcangobeyondmerecalculationtotheanalysisofthevastscreedsofinformationthatnowcrosstheworldbythemiracleoftelegraphyourstaffatsouterpointhavebeenabletoexploittheadditionalenergyprovidedbythenewgeneratorstodoublethecomputingpoweroftheanalyticalengineandarenowabletoprocesstwiceasmanytelegramsinthesametimeusingthestatisticaltechniquespioneeredbybabbageandnightingaleandaidedbythepowerofthedevicethemostsecurelyencipheredmessagesyieldtheirsecretsprovidingintelligencebeyondanythingthatcouldbeascertainedbyeventhelargestnetworkofagentswhilethismuchisgoodandtobecelebratedthereisalsobadnewsiamdisappointedtoreportthattheadditionalvolumeoftrafficonthetelegraphynetworkandtheincreasedrateatwhichwehavebeenabletodecipherthosemessageshasstretchedtheabilityofourmostpowerfulenginethefoundationmachinetosupporttheanalystsintheirworkasaresultweriskdrowningininformationwecannotusewehavereachedthelimitsofwhatonemachinecandoandifwearetomakethemostofthisnewbountythenwewillneedtolinkseveralintheircomputationssothattheycananalyseandreportwhattheyfindasfastasthemessagesflowthiswillrequireanenormousincreaseinourproductionofelectricitywhichcannotbeachievedbycombustionwithoutalargeincreaseintheconsumptionoffuelthecostwouldbeprohibitivebutevenifitcouldbemetthecorrespondingincreaseintheproductionofheatandnoisewouldbeunlikelytoescapeattentionevenonthewildnortheastcoastifwearetorealiseourfullambitionsweneedtofindamoreremotelocationwithareadysourceofpoweredisonsworkatappletonshowsgreatpromiseandithinkiknowtheideallocationtobuilditmaryeverestboole'" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pb = hill_decipher(key_b, scb)\n", + "pb" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "c7f2e770-8062-4d18-b90a-cb2e410ef88c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "report from mary everest boole to the curia of the trinity foundation this report was commissioned\n", + "by the curia to record the outcome of the commissioning and activities of the souter point facility\n", + "and to make recommendations on its development after years of pioneering work by faraday and others\n", + "the development of their extraordinary machines outgrew the capacity in our headquarters at trinity\n", + "wharf with each new increase in speed and power the risk of discovery grew until the curia had no\n", + "choice but to commission a new facility inspired by the lessons learned in london it was decided to\n", + "build a larger establishment undercover of the construction of the souter point lighthouse the first\n", + "dedicated electrically powered lamp of its kind the growth in mining in the area provided excellent\n", + "cover for the installation of our network of caverns underneath the lighthouse and the installation\n", + "and maintenance of the lighthouse lamps team engines pumps and generators disguised our own\n", + "activities as we equipped the base the holmes generators that we procured are identical to those\n", + "selected for the lighthouse so that spareparts can be procured easily without raising suspicion they\n", + "are driven by a pair of steam engines located deep in the rock of c lead on hill beneath the\n", + "lighthouse engine room much of the noise and heat they produce is muffled by the rocks and that\n", + "which escapes is mistaken by neighbours for the churning of the lighthouse machinery it seems that\n", + "no suspicions have been aroused among the locals who continue to believe that our activities are\n", + "somehow related to the lighthouse and the mines it is a wonder to behold the heavy machinery\n", + "converting the movement of the massive flywheel into the imperceptible motion of mysterious\n", + "electrical charges through the wires it is difficult to comprehend that the various parts of the\n", + "machine can combine to produce anything approaching human thought and yet it computes moreover this\n", + "computer embodies the vision of the countess of lovelace that of a machine which can go beyond mere\n", + "calculation to the analysis of the vast screeds of information that now cross the world by the\n", + "miracle of telegraph your staff at souter point have be enable to exploit the additional energy\n", + "provided by the new generators to double the computing power of the analytical engine and are now\n", + "able to process twice as many telegrams in the same time using the statistical techniques pioneered\n", + "by babbage and nightingale and aided by the power of the device the most securely enciphered\n", + "messages yield their secrets providing intelligence beyond anything that could be ascertained by\n", + "even the largest network of agents while this much is good and to be celebrated there is also bad\n", + "new siam disappointed to report that the additional volume of traffic on the telegraphy network and\n", + "the increased rate at which we have be enable to decipher those messages has stretched the ability\n", + "of our most powerful engine the foundation machine to support the analysts in their work as a result\n", + "we risk drowning in information we can not use we have reached the limits of what one machine can do\n", + "and if we are to make the most of this new bounty then we will need to link several in their\n", + "computations so that they can analyse and report what they find as fast as the messages flow this\n", + "will require an enormous increase in our production of electricity which can not be achieved by\n", + "combustion without a large increase in the consumption of fuel the cost would be prohibitive but\n", + "even if it could be met the corresponding increase in the production of heat and noise would be\n", + "unlikely to escape attention even on the wild northeast coast if we are to realise our full\n", + "ambitions we need to find a more remote location with a ready source of powered i sons work at\n", + "appleton shows great promise and i think i know the ideal location to build it mary everest boole\n" + ] + } + ], + "source": [ + "print(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "d12a663c", + "metadata": { + "Collapsed": "false" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3897" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(prettify(pb))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "504ec2e2", + "metadata": { + "Collapsed": "false" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2021/2021-challenge9.md b/2021/2021-challenge9.md new file mode 100644 index 0000000..a280dd4 --- /dev/null +++ b/2021/2021-challenge9.md @@ -0,0 +1,125 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.11.1 + kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```python Collapsed="false" +from szyfrow.caesar import * +from szyfrow.affine import * +from szyfrow.keyword_cipher import * +from szyfrow.column_transposition import * +from szyfrow.vigenere import * +from szyfrow.polybius import * +from szyfrow.railfence import * +from szyfrow.hill import * +from szyfrow.support.text_prettify import * + +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +import collections +%matplotlib inline +``` + +```python Collapsed="false" +challenge_number = 9 +plaintext_a_filename = f'plaintext.{challenge_number}a.txt' +plaintext_b_filename = f'plaintext.{challenge_number}b.txt' +ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt' +ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt' +``` + +```python Collapsed="false" +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + + +sca = sanitise(ca) +rsca = cat(reversed(sca)) +scb = sanitise(cb) +rscb = cat(reversed(scb)) +``` + +```python +sca_counts = collections.Counter(sca) +sca_counts +``` + +```python tags=[] +pd.Series(sca_counts).sort_index().plot.bar() +``` + +```python +import itertools +``` + +```python +permutes = [transpositions_of(cat(t)) for t in itertools.permutations('abcdefghi')] +len(permutes) +``` + +```python +key_a, _ = column_transposition_break(sca, translist=permutes, fitness=Ptrigrams) +word_a, fill_a, empty_a = key_a +word_a, fill_a, empty_a +``` + +```python +# mod_word_a = (1, 3, 6, 4, 5, 7, 0, 2, 8) +pa = column_transposition_decipher(sca, word_a, + fillcolumnwise=fill_a, emptycolumnwise=empty_a) +pa +``` + +```python +print(prettify(pa)) +``` + +```python Collapsed="false" tags=[] +open(plaintext_a_filename, 'w').write(prettify(pa)) +``` + +```python +scb_counts = collections.Counter(scb) +scb_counts +``` + +```python tags=[] +pd.Series(scb_counts).sort_index().plot.bar() +``` + +```python +key_b, _ = hill_break(scb, fitness=Ptrigrams) +``` + +```python +key_b +``` + +```python +pb = hill_decipher(key_b, scb) +pb +``` + +```python +print(prettify(pb)) +``` + +```python Collapsed="false" +open(plaintext_b_filename, 'w').write(prettify(pb)) +``` + +```python Collapsed="false" + +``` diff --git a/2021/ciphertext.9a.txt b/2021/ciphertext.9a.txt new file mode 100644 index 0000000..183426f --- /dev/null +++ b/2021/ciphertext.9a.txt @@ -0,0 +1 @@ +AAGYB WWADB LKNKT AAONH IWTGR NPETE ESSTD LNEYE OIEET UNADT AWOSN AIRNR UTHAO FTPSY EEUAA HTSUE COWIC TDDAS YREEI TTTEL HDSOI SVKHN ILTTE YTORW AEEDA SAYBE REIME OXGEN SATGT NLORT PERRR EIAIN IHEAN AIEHA TOACU ESMDU CLOGT LNSLA AENON WATDT ELHBS SEDKA ISOVT DEMON MRYTN GDNUF IVIRE ESLHE UECEI EISAY RIALD ROAIT ODIMN TIOIT SRHDP CEYTA GTHAA IETRE IEOEF DEECL WETHS IEOET LIINU CTVEE MRWYE ILWNE BOIFH UAOWR TGSHN ONGEG ECPLL HWANH DCNHN SCTEN ITECA WMBWR MPNRW RHCEI AAAOH OLTHE AOSNN SDSYE GBSHT HAREF PRNTO EEGCT HTEKA YCGWD LGGDA TOWAT ULTVB NLWOP EOODC EEYIO GTLWN IOTUO GWTNL SOVNA NNMLY IOJFA TEARI RPATT OGOHM NIIEN TVBTS TTIAT RRSEC ITNAF LITRO IMOCE IRTDH AATES AAITE ARFIA OSEOD NAPOT TIRRE TGYID EOMIW TTOOE TRAAV HETOH NEEPS CMANM CAEOS EGTYN OMSSI GTLIH TFEIS KIGSE MNBOE NAIEH UITAR AMORI AIIEH HIIAL ONCDH NFLOA OFOTY HRNOB TARLF THNEH LNWRL FENOT AOAON UETOO EUTYT IDEEP TNWUH TDREH UBNES STTBE HNONR HTDRE IAOEH RAFIA WHHBP IEHYC TKHEW HNPSK UTIML NVHIH TICAR ONVAE DLRFI EOSON NOWOC OTESR TTINI IBNHN SCIIO YATAE OTORU RHATA HSDEE BMAIH IEEEC UWDMC TLGDK ATHRF IIINE ULGNA ITOEW RLEEA EIRMR UNEOI VIETE YDEUA EEHED OWOOR TEIET OGMRW FNUTS LDTIS LWIDT NCINE ORUIR EEROA RIOWR KIESR YEERP HOUTN YTOEP WHIEA YUERS MRHTA TVGCH EFNSH IONMI EAHDE AEGVW LHLMS GSHWE OSPPA LFNLH STUWF TATND HEEEH ESWKH STREI ELAWR DEIOB ESIHO YININ ILABA ILERG EATIA LNTLT RTEIF EITRI GNWOD SVSOT ACESE WIAYT HLTSE EYEIR ENSHI ETLEI TTRWT RTAEH EIIEW IRTUU IHLLR DYHHD HGDPH LNTHR OLIVI EVSDY LOTMO YDHPL IAYEV HAWSW EAONL AEHEE TTHAC DHIFH BLAHC CLEMS GWSPF ENNPI WTNSH FOLLN HDSET NTICF RIOTI UIHCI FRAUT NIVUO DHHSM FBHAR CEADH NANTA IALEL TASTN VAREH ETGAT ANHEV NEHIN NNETR CDOGU VRSTS RETCW RSNAM SDSSN WIENN NDNMH TEITL TDFTK HIYIE TOTTA IIYAG TADDO AYTAT UATNT NTTDP FDTSH TWDED LIOAR ANHIH UNNOO GIORA NDRUI RSATF SDULU EGSTA YUINU EELRT LRTEM AHERH TLOIE YEATO OTYCO AEIBE HOTET EMSHA TOSNI NNESE EGREN NIRIT NTCYY IOTIS YECEL ASAOH RHNRE LEFTE PWAYO EOYAR IAUSE ALGIU LOEUH TBRAS TNTAS LHTKN TSSBH SGALO APNNR IAADL KAHIO YGNIM LTRAO YIUWN YYAUL HUEOO TASKS NAOFS ACEMP ILTCO HALET AWPRR TOAOH MIUOA ETOMI UDANE HHETI TODLL EYTDA SWFTT NRACT TTATA OOTLT EDAGH EIMOT OCOLL TNREO TRCYD KGEYS IGAWE OSNAK HMLIT INSTE NEGSE HINCO METDS MTLAC MAAER TMVLP IDDEN IHFIE OEHSB ENSRO SOANI WTDLN LEBHB LITRO OHEIS SOLII TLNCF TSEWR OHYNY EUNSV NNSAU UEAMR YNIEA IIOOI TIITI DTOFV PEWNC YAWTN FROIE RSNMT AEINO ONTSW GLNEO AGHOE RHAON AOEUL EEIOT WORTS OTIIT ORHBT IROFA LTERD DHTSN LTMAT TRTNE ANAAK EHTNE SUOYE TEIUE CLTTT OILVE WRRLE NLETA UCEKO SHXSR RBNLL DEDMO RCGTA WOEMD NTAEE AUYKS SAOCO RATAA TKANH FSDAI EARWC EPAVT SNENA NDEUE WPTDO TOTTH OUTOH SCSWI TIAWY IOHEH TOHIE NTTRC MIGEE E \ No newline at end of file diff --git a/2021/ciphertext.9b.txt b/2021/ciphertext.9b.txt new file mode 100644 index 0000000..5a94732 --- /dev/null +++ b/2021/ciphertext.9b.txt @@ -0,0 +1 @@ +VRDPK RWFAO MMPRZ EVEWE UTCOP LHTAT GELUI ITOAT XEZRV NRTTF HUDDB TBOAT AIVRD PKRWW USAOU MKSWI RNEDR YLHWC ZRTAF OGEFO WDLHI OVTAO SEYFL HQCYM AIASB OVIGG QNCAB TDVBT WETOA TWEIO XTGRW OGNFF KCTLR TNAWD AOKAV EGEAO QMQNT AWIFN BOBIV SZEPE DOQMG NFAXT PREEJ RTOXP BOIEZ RTNKW BRZBF FRRDD YYQNH OLHJR ATHEZ EPEDO QMGNT OATME VRQXR RFOLD NNPRM MJCVI WEIOZ TVRPW LHCCP PKCRT VIIOY REETD UUKRV ESSMT ZRVNR TDWRA BFBIL HCAUH AEVIT CEEWS VIHSI EDDQN DPAWK RLHZR CSTOL DUSJO VEEYV RQWGN TIATG ELUII HHQDQ OVHKI FENUH TQCYM AIASB ONAAE FFKCT LRTVI HSZIH EZBAT PEWEG SFNPL RARNL DYNBO RDVNP TSAHD KCHDW DPOCU OLLAR AKGVR LSBAT LZSQM GNHUH DTRJO VETOA TGEBO LSLRV CWIBN YFLHG SNUVE DPVIE TOIAH VHMUX ELHNF JRWTH EKITA HEPEG EKTKI LAJLD PAWVR ODMAD PNFLT SKQNA TKEFR PWPHZ NVIVI OGGNL HRAEE GPJOL IHEBE GCWLR EVTJO VETFK RLHVI LSLAL LBTBO TOIOE RXEKW BRTOC CZVER MSQNV ERNTA AHLHT LNGAT IOWSN AWDLH VILSL ALLBT BONAP DIAGN RENAG CTOAT PEOIA HVHMU PEMAH PXTMA REOGR NHSGU HPNAJ DREVE TAFOV SAIAG AIHEI OFRJW CABTD VBTWE SAAWU ECUEP HEATF ESAXE LHVHX LWEKG RNRRH TJRAT TAAWG PQOLU HERAM EHDGN KILAH TATGO WEPEG EXTID FOATP EOIAH VHMUW EHOHH LTPPV RPPKR USNAF BGPQO LUHEE EASJL EWATI OKTIA ASTNM SHSKI WIGNL HYYVR UDDIR EZBPA IAFRX FXTMA REOGR NDSQO TAHEH DTEVI ATVEQ OYKHF PLDAB OPHWL FBRNT AAHLH TLNGA TIOWS REOGR NFRAO GMJCT OATRE WOWSN AKDEE MTLHN YFRXD GCAIG MKFPL EDRYL HFRMC SSQNA TTADW KILHU SPAWE AIUML SKARE ZBRNO IIHIO JRTFK RLHJC LUVNT NTOAT PEOIA HVHMU QECAP HRNPR BIWSQ ELSHH GTGOM UXPKC BOZSV AFEIE NNFRM UHEMA BOZGL HZLCC DLDWQ OBOBT HNXEP OPEMI ZVATT AIORR VCDIB IMISS VRGSQ MVHNW PETAH EHTAT PEOIA HVHMU EEQNA TQEVI WEBIA IWABO HDKRP OLEZO WDLHL HVAKY CAPHR NPRQC INVEB TTNAT QEJOQ EREHT YFLHM MKSDI JEJLD WIETL GNHOL HUITP TRTEB TMBQE HOWIB NRFQY XTZRI OWSPL VCZRC CNLHH XRWEA TFRAU AHLHE WVRAS BTVSN INFWC ELHTQ CBMVR LHQNA TTAAT ZERAW IMUPP KRGSY FLHMM JCVIG ENAQC NMVIX EDOFR XDGCN ARYPH TNPAG POOJC VINGG UNAAT IONGT TQNCY BTVTA OJPXT ESFOS EZVKR PHUSA OJPXT VRNMR OMILS LHDVA SBOTO ATGEI OGNWE GSQFJ OPECA XEHHH TFFMM JCVIA EPHJC CCTNP OCEBO PDVEG ELAWC LLBTB OHTAT EENNJ LASGS YFLHV VLSUS VRHEG SNFSN FOMMB TBOAT TABNY WFRKS ATAEF OOLZB ATQEZ ICAPL TOXTP LXGPA FHIOJ RTTKF TAGSN UVEDP VIATV AFEIE NNMBX ESOMX ZLBIA TEEGD BIWIN NPLRN XRNYF RDVHD EDRYL HRNCW REVET AFOLS ROIOM BXELH QCBMN UVIVG KOVET OATEE NNJLB TCCPL TNVIE EQNRA REKOB APLHT GPQOW ELSEW GCSAM MLNXT PLXGM AASGN LHSSQ MBTQM MUVIZ GLHLS TAAIB TCCEL GEUHY IYUHS WIRNV EHEZB BBCBG AEEQN VNNGB TTNLA EEQNI AHDED RYLHD PAWFR YFLHH DDVGC ATQEG OLTGE LUPEC YPNXI LHVRP DWESS KGQSM IOLAT MEJRG EVRLT GPJOL IVIOG GNPET LKGPN FECEB ODDLN ATVIZ GHHVT IOOLF BSAGC KRIAR NEDCY ZVGNL HLLXR WEGTX EKWBR TOGAR ELTDW TIXEP HESWU PHYSC ODDQN HTFBG CPLSB TAHEA TVEME SSDLP ODARN OWIIP MAIPA DPVIX TWDFO TEFOM THHMT LHDAL DBTBO LAJVF LQMTO KTFAN FQCGN LHXTP LXGPA FHRNP TFOKK QNATM EPNVR SAHER RXTTA DWKID HLEVA FEIEN NMBXE ROGEX ILHKR VHWSQ MKSGA WEHHK SKTXE JCHEA TEEJB TLRTT OIODR GOITK OVEZF PLTNV IXELH TFHUD DBTBO MMJCV IXEGO JUDPK RATEE NNJLL SASGN LHZIK WBRSA RAWEF UPTVE AINKF RJWVI OGVNS NFOMM BTBOA WCCAN HOMUA ELEVA VEEEJ CHEAT PEUIB IGSBF HHHTR NMMJC VIGEN ARDNA LDBFE EVRHT MMOKA TQEGO HTYFP HFSAE PBHUR TATRE AWEWW LRNHE HTTLX NWSZV RRTLG NLHZI QCBMN UTAWI FNGSA TTAAT CECCN NNNJL WSNAU DTEFO PTHHM TLHDY VIDDX SSATT LSLHQ MKSGA WEQFK OATAI EWWLV RKQZI EERNB NDRIO ASPNV RSAME BNLUG PROWU BTBOT OPEGE KTKIB IUYPH JCCCA NHOFB CAPHZ EHEZB QCNMM UBTBO EWATI OTTLL XRMEP NVRSA MEGNL HQCFN GUIPW IBNKF YUELL HQCLS KWFUE DTEFR PHJBB TZVVB XTZVV NNFVT IOOLF BQMMT LHQCI RWEDP QNVIO GPNVR SAMEG NLHGP ROWUB TBOTO LHTAN AQDWO WSKWF UEDYE YNSIP ERYSO USPAE EMTRE BTBOZ EREBO ATAET IQDFO ATEEL SQCSA BTBFE EVRHT VRLAA ISELU ZFWLM AJBBT BOOSR EIEWD TOVID DAMVR VRAMX TZLCC BTBOE WATRA EEBDG SLUGC TODPA WVRLD GSFNK WBRTA PAAPX EBOZS KOYSV RTAGP AOAIE EQNBI PHXNS IBNPW LHLIE EWLQO TAWIG NPOCU OLBIM MPRZE VEWEU TCOPL \ No newline at end of file diff --git a/2021/plaintext.9a.txt b/2021/plaintext.9a.txt new file mode 100644 index 0000000..3e62b3e --- /dev/null +++ b/2021/plaintext.9a.txt @@ -0,0 +1,29 @@ +harry if you are reading this then you are probably also wondering where i am i am sorry to +disappear but i have alot to think about and need to work things out on my own i am on the train to +mass our ie now and hoping that i will find the answers i need there though i have already begun to +put the pieces together the story started at michael far a days lighthouse at trinity wharf and that +should have been a big clue especially with the reference to the facility in florence s letter to +him we take it so much for granted now that we missed the importance of that place it was when i +looked into souter point that i realised why it might be relevant and no was i travel through the +foothills of the himalaya it is all coming into focus the attached report was discovered by one of +the elves in the lamp at souter point and was clearly left there for met of india m still not sure +what the conspiracy set out to do but i now know the significance of trinity wharf and souter and i +can take a good guess at why they were interested in george everest s house in the mountains i dont +know why i think there might still be something to find there but since the conspiracy is clearly +still active i have to know what they are doing and this is the only lead i have the connection +between the early conspirators is also much clearer to me now they all had an interest in +mathematics and the natural sciences ada lovelace was a key member of babbage steam with her early +experiments with programming mary everest boole was an expert in logic highly educated and well +versed in indian mathematical thought at first florence nightingale doesnt look like a great fit +with the group she is celebrated more for modernising nursing but her innovations were based on +serious data analysis using everything she knew about statistics and that was alot caroline herschel +was another remarkable woman the first to be paid a salary as a scientist but i think her role was +something more she had huge influence in society and also held a position in government like charlie +and trinity she was technically gifted and well placed to take full advantage of those gifts i need +to know what they are trying to do why and how trinity warned me not to tell you about her letter +but that was never a possibility even if i didnt let you know what was going on i am pretty sure +that you would have found out and i would much rather tell you myself the only reason i didnt come +to you straightaway is that i still dont know what is going on and i didnt want to put you in the +difficult position of having to decide whether to trust me or not hopefully this visit will provide +the evidence we need to unravel the conspiracy and to clear my name i will write to you again with +news from the park jodie \ No newline at end of file diff --git a/2021/plaintext.9b.txt b/2021/plaintext.9b.txt new file mode 100644 index 0000000..e7f507c --- /dev/null +++ b/2021/plaintext.9b.txt @@ -0,0 +1,40 @@ +report from mary everest boole to the curia of the trinity foundation this report was commissioned +by the curia to record the outcome of the commissioning and activities of the souter point facility +and to make recommendations on its development after years of pioneering work by faraday and others +the development of their extraordinary machines outgrew the capacity in our headquarters at trinity +wharf with each new increase in speed and power the risk of discovery grew until the curia had no +choice but to commission a new facility inspired by the lessons learned in london it was decided to +build a larger establishment undercover of the construction of the souter point lighthouse the first +dedicated electrically powered lamp of its kind the growth in mining in the area provided excellent +cover for the installation of our network of caverns underneath the lighthouse and the installation +and maintenance of the lighthouse lamps team engines pumps and generators disguised our own +activities as we equipped the base the holmes generators that we procured are identical to those +selected for the lighthouse so that spareparts can be procured easily without raising suspicion they +are driven by a pair of steam engines located deep in the rock of c lead on hill beneath the +lighthouse engine room much of the noise and heat they produce is muffled by the rocks and that +which escapes is mistaken by neighbours for the churning of the lighthouse machinery it seems that +no suspicions have been aroused among the locals who continue to believe that our activities are +somehow related to the lighthouse and the mines it is a wonder to behold the heavy machinery +converting the movement of the massive flywheel into the imperceptible motion of mysterious +electrical charges through the wires it is difficult to comprehend that the various parts of the +machine can combine to produce anything approaching human thought and yet it computes moreover this +computer embodies the vision of the countess of lovelace that of a machine which can go beyond mere +calculation to the analysis of the vast screeds of information that now cross the world by the +miracle of telegraph your staff at souter point have be enable to exploit the additional energy +provided by the new generators to double the computing power of the analytical engine and are now +able to process twice as many telegrams in the same time using the statistical techniques pioneered +by babbage and nightingale and aided by the power of the device the most securely enciphered +messages yield their secrets providing intelligence beyond anything that could be ascertained by +even the largest network of agents while this much is good and to be celebrated there is also bad +new siam disappointed to report that the additional volume of traffic on the telegraphy network and +the increased rate at which we have be enable to decipher those messages has stretched the ability +of our most powerful engine the foundation machine to support the analysts in their work as a result +we risk drowning in information we can not use we have reached the limits of what one machine can do +and if we are to make the most of this new bounty then we will need to link several in their +computations so that they can analyse and report what they find as fast as the messages flow this +will require an enormous increase in our production of electricity which can not be achieved by +combustion without a large increase in the consumption of fuel the cost would be prohibitive but +even if it could be met the corresponding increase in the production of heat and noise would be +unlikely to escape attention even on the wild northeast coast if we are to realise our full +ambitions we need to find a more remote location with a ready source of powered i sons work at +appleton shows great promise and i think i know the ideal location to build it mary everest boole \ No newline at end of file -- 2.34.1