From fb27ec808421a2bd8dd5c253138a23db12a9aefa Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 26 Nov 2020 15:54:36 +0000 Subject: [PATCH] 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