--- /dev/null
+{
+ "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
+}
--- /dev/null
+---
+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"
+
+```
--- /dev/null
+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