From: Neil Smith Date: Fri, 20 Oct 2017 20:37:38 +0000 (+0100) Subject: Work on polybus cipher procedures X-Git-Url: https://git.njae.me.uk/?p=cipher-tools.git;a=commitdiff_plain;h=162d24790a67f99182b5252978146f33e96e4747 Work on polybus cipher procedures --- diff --git a/2017/2017-challenge3.ipynb b/2017/2017-challenge3.ipynb index a6421ad..dc53777 100644 --- a/2017/2017-challenge3.ipynb +++ b/2017/2017-challenge3.ipynb @@ -1609,6 +1609,496 @@ " print('')" ] }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 abcdefghijklmnopqrsutvwxyz -6521.8056961355105 mhaleauasuifeuhousfeunrafsseufwuheyarolpouulemauhpnfdattooumoulargsuieeuhehodreauheiuheuinnwsrniuheuotuatolopalaubunnveitnceuhehfgerfceiatoldasodvoruogeyotedpbhasoicbmauhnfuuhesfwwniunyogiatnloordhasuoleruedstnfusdeyeoumnfldhovepeerarevauopleordmauhauuhelnssnypiauorraohovargieolaseduhouuheaterameieieodarghastnccfratouanrsogiatnlooiiorgedunwloruyolsearynicouanropnfuuhewlorreddaswnsauanrnyuinnwsseuuargouiowarunmhathuheaterayellauassuallfrtleoihnmuhesovogeuiapeshodleoiredundetawheinfioicbstnccfratouanrsosuhebhodrnmiauargnyuheainmrhnmeveieveiboicbhosausuioaunisordauseecslakelbunceuhounrenicnienyuhelntoluiapeswenwleufiredsncenresheodlnvenicnrebauasolluieotheibpfuuhasotuuhieoueredunfrdeicareuheecwaieseruaiesbsuecnysetfietnccfratouanruhetoesoitawheiweihowscnieuhorinodshoderopleduheecwaieunyfrtuanrsetfielbordauslnssmosodasosueiufirarguhoulnssarunovatunibnruhepouuleyaelddeseivedcnieietngrauanruhorauieteavedweihowssfeunrafsreveikremniweihowsheyoaledunfrdeisuorduhetfrrargnyuhewlorpfueauheimobdeswaueuhevatunibogiatnloorduheraruhleganriecoaredardasgiotenrheoiarguhasremstlofdafstoesoiofgfsufsgeicoratfsreinecweiniassfedosetieuwintlocouanresuoplashargotawheisthnnlundevelnworemsbsuecnyacweiaoltawheisaumnikedarsetieuyninveiumerubbeoisdevelnwargremceuhndsunsetfietnccfratouanrsotinssuheecwaiesufdbarguhemniksnyuhegieeksogeseftladordhbwouaoordevernldeimniksyincortaerupopblnruhesthnnldevelnwedremmobsunsoyegfoidtnccfratouanrsyincinceserecaesuheseremsbsuecsmeiemiauuerdnmrorddasuiapfuedaruhetndexnttflunifcweihowsuhecnsusuiatulbgfoideddntfceruarollhasunibmheraumosyarollbtncwleuedcorbbeoisloueiuheecweinidncauaorassfedorexetfuavenideimhathwieyotedeveibtnwbnyuhetndexuhouaumosunpegfoidedpbeveibleganrunuhelosucoruhedeyeounyuheateraorduhesfatadenypnfdattoweihowswinuetueduheraruhleganryincdassnlfuanrogiatnlomosloigelbleyuunhasnmrdevatesaruhewinvarteuhnfghaumoscodetleoiunhacuhouunieufirmnfldceoroupesudasgioteordoumnisudeouharopieokmauhuiodauanruheraruhioasedoremsuordoiduheleganrmosexaledardasgioteunerdfieuhehoidorddorgeinfsmniknysfpdfarguhetolednraaaruhepleokmaldeiressesnytolednraosfeunrafsnideieduheraruhuncoithunepniotfcmhathuhebmeieuncokeuheaiposeyniioadsaruntolednraouhefrswnkerieosnryniuheaiexalemosuhouaruellagerteiewniussfggesueduhouuhasmosmheieuhebcaghuyarduheailnsuoqfalouhnsemhnmnfldieodnrcfsuynllnmcbyoauhyflsloveuainmhnyotesogioveuoskweihowsuheloigesuundoueosheuiovelsuntnrteoluheynfiuhthowueinyuhasuiogatuole\n", + "0 aocdefghijklmnbpqrstuvwxyz -6521.891540991668 mhaleatastifethbtsfetnrafssetfwtheyarblpbttlemathpnfdauubbtmbtlargstieethehbdreatheithetinnwsrnithetbutaublbpalatotnnveiuncethehfgerfceiaubldasbdvbrtbgeybuedpohasbicomathnftthesfwwnitnybgiaunlbbrdhastblertedsunftsdeyebtmnfldhbvepeerarevatbplebrdmathatthelnssnypiatbrrabhbvargieblasedthbttheauerameieiebdarghasunccfraubtanrsbgiaunlbbiibrgedtnwlbrtyblsearynicbtanrbpnftthewlbrreddaswnsatanrnytinnwssettargbtibwartnmhauhtheauerayellatasstallfrulebihnmthesbvbgetiapeshbdlebiredtndeuawheinfibicosunccfraubtanrsbstheohbdrnmiatargnytheainmrhnmeveieveiobicohbsatstibatnisbrdatseecslakelotncethbtnrenicnienythelnubltiapeswenwletfiredsncenreshebdlnvenicnreoatasblltiebuheiopftthasbutthiebteredtnfrdeicaretheecwaiesertaiesostecnyseufieunccfraubtanrtheubesbiuawheiweihbwscniethbrinbdshbderbpledtheecwaietnyfrutanrseufielobrdatslnssmbsbdasbsteitfirargthbtlnssartnbvautnionrthepbttleyaelddeseivedcnieieungratanrthbratieueavedweihbwssfetnrafsreveikremniweihbwsheybaledtnfrdeistbrdtheufrrargnythewlbrpfteatheimbodeswatethevautniobgiaunlbbrdtherarthleganriecbaredardasgibuenrhebiargthasremsulbfdafsubesbibfgfstfsgeicbraufsreinecweiniassfedbseuietwinulbcbtanrestbplashargbuawheisuhnnltndevelnwbremsostecnyacweiabluawheisatmnikedarseuietyninveitmertooebisdevelnwargremcethndstnseufieunccfraubtanrsbuinsstheecwaiestfdoargthemniksnythegieeksbgesefuladbrdhowbtabbrdevernldeimniksyincbruaertpbpolnrthesuhnnldevelnwedremmbostnsbyegfbidunccfraubtanrsyincinceserecaestheseremsostecsmeiemiatterdnmrbrddastiapftedartheundexnuufltnifcweihbwsthecnststiautlogfbideddnufcertarbllhastniomheratmbsyarbllouncwletedcbrooebislbteitheecweinidncatabrassfedbrexeuftavenideimhauhwieybuedeveiounwonytheundexthbtatmbstnpegfbidedpoeveioleganrtnthelbstcbrthedeyebtnytheauerabrdthesfauadenypnfdauubweihbwswinteutedtherarthleganryincdassnlftanrbgiaunlbmbslbigeloleyttnhasnmrdevauesarthewinvaruethnfghatmbscbdeulebitnhacthbttnietfirmnfldcebrbtpestdasgibuebrdbtmnistdebtharbpiebkmathtibdatanrtherarthibasedbremstbrdbidtheleganrmbsexaledardasgibuetnerdfiethehbidbrddbrgeinfsmniknysfpdfargtheublednraaartheplebkmaldeiressesnyublednrabsfetnrafsnideiedtherarthtncbiuhtnepnibufcmhauhtheomeietncbketheaipbseyniibadsartnublednrabthefrswnkeriebsnrynitheaiexalembsthbtartellagerueiewnitssfggestedthbtthasmbsmheietheocaghtyardtheailnstbqfalbthnsemhnmnfldiebdnrcfstynllnmcoybathyflslbvetainmhnybuesbgibvetbskweihbwsthelbigesttndbtebshetibvelstnunruebltheynfithuhbwteinythastibgautble\n", + "0 abcdefghijklmnopqwstuvrxyz -6436.025956653204 mhaleatastifethotsfetnwafssetfrtheyawolpottlemathpnfdauuootmotlawgstieethehodweatheithetinnrswnithetoutauolopalatbtnnveiuncethehfgewfceiauoldasodvowtogeyouedpbhasoicbmathnftthesfrrnitnyogiaunloowdhastolewtedsunftsdeyeotmnfldhovepeewawevatopleowdmathatthelnssnypiatowwaohovawgieolasedthottheauewameieieodawghasunccfwauotanwsogiaunlooiiowgedtnrlowtyolseawynicotanwopnfttherlowweddasrnsatanwnytinnrssettawgotiorawtnmhauhtheauewayellatasstallfwuleoihnmthesovogetiapeshodleoiwedtndeuarheinfioicbsunccfwauotanwsosthebhodwnmiatawgnytheainmwhnmeveieveiboicbhosatstioatnisowdatseecslakelbtncethotnwenicnienythelnuoltiapesrenrletfiwedsncenwesheodlnvenicnwebatasolltieouheibpftthasoutthieotewedtnfwdeicawetheecraiesewtaiesbstecnyseufieunccfwauotanwtheuoesoiuarheireihorscniethowinodshodewopledtheecraietnyfwutanwseufielbowdatslnssmosodasosteitfiwawgthotlnssawtnovautnibnwthepottleyaelddeseivedcnieieungwatanwthowatieueavedreihorssfetnwafsweveikwemnireihorsheyoaledtnfwdeistowdtheufwwawgnytherlowpfteatheimobdesratethevautnibogiaunloowdthewawthleganwiecoawedawdasgiouenwheoiawgthaswemsulofdafsuoesoiofgfstfsgeicowaufsweinecreiniassfedoseuietrinulocotanwestoplashawgouarheisuhnnltndevelnrowemsbstecnyacreiaoluarheisatmnikedawseuietyninveitmewtbbeoisdevelnrawgwemcethndstnseufieunccfwauotanwsouinsstheecraiestfdbawgthemniksnythegieeksogesefuladowdhbrotaoowdevewnldeimniksyincowuaewtpopblnwthesuhnnldevelnredwemmobstnsoyegfoidunccfwauotanwsyincincesewecaesthesewemsbstecsmeiemiattewdnmwowddastiapftedawtheundexnuufltnifcreihorsthecnststiautlbgfoideddnufcewtawollhastnibmhewatmosyawollbuncrletedcowbbeoisloteitheecreinidncataowassfedowexeuftavenideimhauhrieyouedeveibunrbnytheundexthotatmostnpegfoidedpbeveibleganwtnthelostcowthedeyeotnytheauewaowdthesfauadenypnfdauuoreihorsrinteutedthewawthleganwyincdassnlftanwogiaunlomosloigelbleyttnhasnmwdevauesawtherinvawuethnfghatmoscodeuleoitnhacthottnietfiwmnfldceowotpestdasgioueowdotmnistdeothawopieokmathtiodatanwthewawthioasedowemstowdoidtheleganwmosexaledawdasgiouetnewdfiethehoidowddowgeinfsmniknysfpdfawgtheuolednwaaawthepleokmaldeiwessesnyuolednwaosfetnwafsnideiedthewawthtncoiuhtnepnioufcmhauhthebmeietncoketheaiposeyniioadsawtnuolednwaothefwsrnkewieosnwynitheaiexalemosthotawtellagewueiernitssfggestedthotthasmosmheiethebcaghtyawdtheailnstoqfalothnsemhnmnfldieodnwcfstynllnmcbyoathyflslovetainmhnyouesogiovetoskreihorstheloigesttndoteoshetiovelstnunwueoltheynfithuhorteinythastiogautole\n", + "0 abndefghijklmcopqrstuvwxyz -6281.062482373658 mhaleatastifethotsfetcrafssetfwtheyarolpottlemathpcfdauuootmotlargstieethehodreatheitheticcwsrcithetoutauolopalatbtccveiucnethehfgerfneiauoldasodvortogeyouedpbhasoinbmathcftthesfwwcitcyogiaucloordhastolertedsucftsdeyeotmcfldhovepeerarevatopleordmathatthelcsscypiatorraohovargieolasedthottheauerameieieodarghasucnnfrauotacrsogiauclooiiorgedtcwlortyolsearycinotacropcftthewlorreddaswcsatacrcyticcwssettargotiowartcmhauhtheauerayellatasstallfruleoihcmthesovogetiapeshodleoiredtcdeuawheicfioinbsucnnfrauotacrsosthebhodrcmiatargcytheaicmrhcmeveieveiboinbhosatstioatcisordatseenslakelbtcnethotcrecinciecythelcuoltiapeswecwletfiredscnecresheodlcvecincrebatasolltieouheibpftthasoutthieoteredtcfrdeinaretheenwaiesertaiesbstencyseufieucnnfrauotacrtheuoesoiuawheiweihowsnciethoricodshoderopledtheenwaietcyfrutacrseufielbordatslcssmosodasosteitfirargthotlcssartcovautcibcrthepottleyaelddeseivedncieieucgratacrthoratieueavedweihowssfetcrafsreveikremciweihowsheyoaledtcfrdeistordtheufrrargcythewlorpfteatheimobdeswatethevautcibogiaucloordtherarthlegacrienoaredardasgiouecrheoiargthasremsulofdafsuoesoiofgfstfsgeinoraufsreicenweiciassfedoseuietwiculonotacrestoplashargouawheisuhccltcdevelcworemsbstencyanweiaoluawheisatmcikedarseuietycicveitmertbbeoisdevelcwargremnethcdstcseufieucnnfrauotacrsouicsstheenwaiestfdbargthemcikscythegieeksogesefuladordhbwotaoordevercldeimciksyicnoruaertpopblcrthesuhccldevelcwedremmobstcsoyegfoiducnnfrauotacrsyicnicneserenaestheseremsbstensmeiemiatterdcmrorddastiapftedartheucdexcuufltcifnweihowsthencststiautlbgfoideddcufnertarollhastcibmheratmosyarollbucnwletednorbbeoisloteitheenweicidcnataorassfedorexeuftavecideimhauhwieyouedeveibucwbcytheucdexthotatmostcpegfoidedpbeveiblegacrtcthelostnorthedeyeotcytheaueraordthesfauadecypcfdauuoweihowswicteutedtherarthlegacryicndassclftacrogiauclomosloigelbleyttchascmrdevauesarthewicvaruethcfghatmosnodeuleoitchanthottcietfirmcfldneorotpestdasgioueordotmcistdeotharopieokmathtiodatacrtherarthioasedoremstordoidthelegacrmosexaledardasgiouetcerdfiethehoidorddorgeicfsmcikcysfpdfargtheuoledcraaarthepleokmaldeiressescyuoledcraosfetcrafscideiedtherarthtcnoiuhtcepcioufnmhauhthebmeietcnoketheaiposeyciioadsartcuoledcraothefrswckerieoscrycitheaiexalemosthotartellagerueiewcitssfggestedthotthasmosmheiethebnaghtyardtheailcstoqfalothcsemhcmcfldieodcrnfstycllcmnbyoathyflslovetaicmhcyouesogiovetoskweihowstheloigesttcdoteoshetiovelstcucrueoltheycfithuhowteicythastiogautole\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 abmdefghijklcnopqrstuvwxyz -6227.81870975455 chaleatastifethotsfetnrafssetfwtheyarolpottlecathpnfdauuootcotlargstieethehodreatheithetinnwsrnithetoutauolopalatbtnnveiunmethehfgerfmeiauoldasodvortogeyouedpbhasoimbcathnftthesfwwnitnyogiaunloordhastolertedsunftsdeyeotcnfldhovepeerarevatopleordcathatthelnssnypiatorraohovargieolasedthottheaueraceieieodarghasunmmfrauotanrsogiaunlooiiorgedtnwlortyolsearynimotanropnftthewlorreddaswnsatanrnytinnwssettargotiowartnchauhtheauerayellatasstallfruleoihncthesovogetiapeshodleoiredtndeuawheinfioimbsunmmfrauotanrsosthebhodrnciatargnytheaincrhnceveieveiboimbhosatstioatnisordatseemslakelbtnmethotnrenimnienythelnuoltiapeswenwletfiredsnmenresheodlnvenimnrebatasolltieouheibpftthasoutthieoteredtnfrdeimaretheemwaiesertaiesbstemnyseufieunmmfrauotanrtheuoesoiuawheiweihowsmniethorinodshoderopledtheemwaietnyfrutanrseufielbordatslnsscosodasosteitfirargthotlnssartnovautnibnrthepottleyaelddeseivedmnieieungratanrthoratieueavedweihowssfetnrafsreveikrecniweihowsheyoaledtnfrdeistordtheufrrargnythewlorpfteatheicobdeswatethevautnibogiaunloordtherarthleganriemoaredardasgiouenrheoiargthasrecsulofdafsuoesoiofgfstfsgeimoraufsreinemweiniassfedoseuietwinulomotanrestoplashargouawheisuhnnltndevelnworecsbstemnyamweiaoluawheisatcnikedarseuietyninveitcertbbeoisdevelnwargrecmethndstnseufieunmmfrauotanrsouinsstheemwaiestfdbargthecniksnythegieeksogesefuladordhbwotaoordevernldeicniksyinmoruaertpopblnrthesuhnnldevelnwedreccobstnsoyegfoidunmmfrauotanrsyinminmeseremaestheserecsbstemsceieciatterdncrorddastiapftedartheundexnuufltnifmweihowsthemnststiautlbgfoideddnufmertarollhastnibcheratcosyarollbunmwletedmorbbeoisloteitheemweinidnmataorassfedorexeuftavenideichauhwieyouedeveibunwbnytheundexthotatcostnpegfoidedpbeveibleganrtnthelostmorthedeyeotnytheaueraordthesfauadenypnfdauuoweihowswinteutedtherarthleganryinmdassnlftanrogiaunlocosloigelbleyttnhasncrdevauesarthewinvaruethnfghatcosmodeuleoitnhamthottnietfircnfldmeorotpestdasgioueordotcnistdeotharopieokcathtiodatanrtherarthioasedorecstordoidtheleganrcosexaledardasgiouetnerdfiethehoidorddorgeinfscniknysfpdfargtheuolednraaarthepleokcaldeiressesnyuolednraosfetnrafsnideiedtherarthtnmoiuhtnepnioufmchauhthebceietnmoketheaiposeyniioadsartnuolednraothefrswnkerieosnrynitheaiexalecosthotartellagerueiewnitssfggestedthotthascoscheiethebmaghtyardtheailnstoqfalothnsechncnfldieodnrmfstynllncmbyoathyflslovetainchnyouesogiovetoskweihowstheloigesttndoteoshetiovelstnunrueoltheynfithuhowteinythastiogautole\n", + "0 abfdecghijklmnopqrstuvwxyz -6237.213026406104 mhaleatasticethotscetnracssetcwtheyarolpottlemathpncdauuootmotlargstieethehodreatheithetinnwsrnithetoutauolopalatbtnnveiunfethehcgercfeiauoldasodvortogeyouedpbhasoifbmathnctthescwwnitnyogiaunloordhastolertedsunctsdeyeotmncldhovepeerarevatopleordmathatthelnssnypiatorraohovargieolasedthottheauerameieieodarghasunffcrauotanrsogiaunlooiiorgedtnwlortyolsearynifotanropnctthewlorreddaswnsatanrnytinnwssettargotiowartnmhauhtheauerayellatasstallcruleoihnmthesovogetiapeshodleoiredtndeuawheincioifbsunffcrauotanrsosthebhodrnmiatargnytheainmrhnmeveieveiboifbhosatstioatnisordatseefslakelbtnfethotnrenifnienythelnuoltiapeswenwletciredsnfenresheodlnvenifnrebatasolltieouheibpctthasoutthieoteredtncrdeifaretheefwaiesertaiesbstefnyseucieunffcrauotanrtheuoesoiuawheiweihowsfniethorinodshoderopledtheefwaietnycrutanrseucielbordatslnssmosodasosteitcirargthotlnssartnovautnibnrthepottleyaelddeseivedfnieieungratanrthoratieueavedweihowsscetnracsreveikremniweihowsheyoaledtncrdeistordtheucrrargnythewlorpcteatheimobdeswatethevautnibogiaunloordtherarthleganriefoaredardasgiouenrheoiargthasremsulocdacsuoesoiocgcstcsgeiforaucsreinefweiniasscedoseuietwinulofotanrestoplashargouawheisuhnnltndevelnworemsbstefnyafweiaoluawheisatmnikedarseuietyninveitmertbbeoisdevelnwargremfethndstnseucieunffcrauotanrsouinsstheefwaiestcdbargthemniksnythegieeksogeseculadordhbwotaoordevernldeimniksyinforuaertpopblnrthesuhnnldevelnwedremmobstnsoyegcoidunffcrauotanrsyinfinfeserefaestheseremsbstefsmeiemiatterdnmrorddastiapctedartheundexnuucltnicfweihowsthefnststiautlbgcoideddnucfertarollhastnibmheratmosyarollbunfwletedforbbeoisloteitheefweinidnfataorasscedorexeuctavenideimhauhwieyouedeveibunwbnytheundexthotatmostnpegcoidedpbeveibleganrtnthelostforthedeyeotnytheaueraordthescauadenypncdauuoweihowswinteutedtherarthleganryinfdassnlctanrogiaunlomosloigelbleyttnhasnmrdevauesarthewinvaruethncghatmosfodeuleoitnhafthottnietcirmncldfeorotpestdasgioueordotmnistdeotharopieokmathtiodatanrtherarthioasedoremstordoidtheleganrmosexaledardasgiouetnerdciethehoidorddorgeincsmniknyscpdcargtheuolednraaarthepleokmaldeiressesnyuolednraoscetnracsnideiedtherarthtnfoiuhtnepnioucfmhauhthebmeietnfoketheaiposeyniioadsartnuolednraothecrswnkerieosnrynitheaiexalemosthotartellagerueiewnitsscggestedthotthasmosmheiethebfaghtyardtheailnstoqcalothnsemhnmncldieodnrfcstynllnmfbyoathyclslovetainmhnyouesogiovetoskweihowstheloigesttndoteoshetiovelstnunrueoltheyncithuhowteinythastiogautole\n", + "0 abcxefghijklmnopqrstuvwdyz -6488.945354263256 mhaleatastifethotsfetnrafssetfwtheyarolpottlemathpnfxauuootmotlargstieethehoxreatheithetinnwsrnithetoutauolopalatbtnnveiuncethehfgerfceiauolxasoxvortogeyouexpbhasoicbmathnftthesfwwnitnyogiaunloorxhastolertexsunftsxeyeotmnflxhovepeerarevatopleorxmathatthelnssnypiatorraohovargieolasexthottheauerameieieoxarghasunccfrauotanrsogiaunlooiiorgextnwlortyolsearynicotanropnftthewlorrexxaswnsatanrnytinnwssettargotiowartnmhauhtheauerayellatasstallfruleoihnmthesovogetiapeshoxleoirextnxeuawheinfioicbsunccfrauotanrsosthebhoxrnmiatargnytheainmrhnmeveieveiboicbhosatstioatnisorxatseecslakelbtncethotnrenicnienythelnuoltiapeswenwletfirexsncenresheoxlnvenicnrebatasolltieouheibpftthasoutthieoterextnfrxeicaretheecwaiesertaiesbstecnyseufieunccfrauotanrtheuoesoiuawheiweihowscniethorinoxshoxeroplextheecwaietnyfrutanrseufielborxatslnssmosoxasosteitfirargthotlnssartnovautnibnrthepottleyaelxxeseivexcnieieungratanrthoratieueavexweihowssfetnrafsreveikremniweihowsheyoalextnfrxeistorxtheufrrargnythewlorpfteatheimobxeswatethevautnibogiaunloorxtherarthleganriecoarexarxasgiouenrheoiargthasremsulofxafsuoesoiofgfstfsgeicoraufsreinecweiniassfexoseuietwinulocotanrestoplashargouawheisuhnnltnxevelnworemsbstecnyacweiaoluawheisatmnikexarseuietyninveitmertbbeoisxevelnwargremcethnxstnseufieunccfrauotanrsouinsstheecwaiestfxbargthemniksnythegieeksogesefulaxorxhbwotaoorxevernlxeimniksyincoruaertpopblnrthesuhnnlxevelnwexremmobstnsoyegfoixunccfrauotanrsyincinceserecaestheseremsbstecsmeiemiatterxnmrorxxastiapftexartheunxednuufltnifcweihowsthecnststiautlbgfoixexxnufcertarollhastnibmheratmosyarollbuncwletexcorbbeoisloteitheecweinixncataorassfexoredeuftavenixeimhauhwieyouexeveibunwbnytheunxedthotatmostnpegfoixexpbeveibleganrtnthelostcorthexeyeotnytheaueraorxthesfauaxenypnfxauuoweihowswinteutextherarthleganryincxassnlftanrogiaunlomosloigelbleyttnhasnmrxevauesarthewinvaruethnfghatmoscoxeuleoitnhacthottnietfirmnflxceorotpestxasgioueorxotmnistxeotharopieokmathtioxatanrtherarthioasexoremstorxoixtheleganrmosedalexarxasgiouetnerxfiethehoixorxxorgeinfsmniknysfpxfargtheuolexnraaarthepleokmalxeiressesnyuolexnraosfetnrafsnixeiextherarthtncoiuhtnepnioufcmhauhthebmeietncoketheaiposeyniioaxsartnuolexnraothefrswnkerieosnrynitheaiedalemosthotartellagerueiewnitssfggestexthotthasmosmheiethebcaghtyarxtheailnstoqfalothnsemhnmnflxieoxnrcfstynllnmcbyoathyflslovetainmhnyouesogiovetoskweihowstheloigesttnxoteoshetiovelstnunrueoltheynfithuhowteinythastiogautole\n", + "0 abcdefghijklrnopqmstuvwxyz -6349.496693126095 rhaleatastifethotsfetnmafssetfwtheyamolpottlerathpnfdauuootrotlamgstieethehodmeatheithetinnwsmnithetoutauolopalatbtnnveiuncethehfgemfceiauoldasodvomtogeyouedpbhasoicbrathnftthesfwwnitnyogiaunloomdhastolemtedsunftsdeyeotrnfldhovepeemamevatopleomdrathatthelnssnypiatommaohovamgieolasedthottheauemareieieodamghasunccfmauotanmsogiaunlooiiomgedtnwlomtyolseamynicotanmopnftthewlommeddaswnsatanmnytinnwssettamgotiowamtnrhauhtheauemayellatasstallfmuleoihnrthesovogetiapeshodleoimedtndeuawheinfioicbsunccfmauotanmsosthebhodmnriatamgnytheainrmhnreveieveiboicbhosatstioatnisomdatseecslakelbtncethotnmenicnienythelnuoltiapeswenwletfimedsncenmesheodlnvenicnmebatasolltieouheibpftthasoutthieotemedtnfmdeicametheecwaiesemtaiesbstecnyseufieunccfmauotanmtheuoesoiuawheiweihowscniethominodshodemopledtheecwaietnyfmutanmseufielbomdatslnssrosodasosteitfimamgthotlnssamtnovautnibnmthepottleyaelddeseivedcnieieungmatanmthomatieueavedweihowssfetnmafsmeveikmerniweihowsheyoaledtnfmdeistomdtheufmmamgnythewlompfteatheirobdeswatethevautnibogiaunloomdthemamthleganmiecoamedamdasgiouenmheoiamgthasmersulofdafsuoesoiofgfstfsgeicomaufsmeinecweiniassfedoseuietwinulocotanmestoplashamgouawheisuhnnltndevelnwomersbstecnyacweiaoluawheisatrnikedamseuietyninveitremtbbeoisdevelnwamgmercethndstnseufieunccfmauotanmsouinsstheecwaiestfdbamgtherniksnythegieeksogesefuladomdhbwotaoomdevemnldeirniksyincomuaemtpopblnmthesuhnnldevelnwedmerrobstnsoyegfoidunccfmauotanmsyincincesemecaesthesemersbstecsreieriattemdnrmomddastiapftedamtheundexnuufltnifcweihowsthecnststiautlbgfoideddnufcemtamollhastnibrhematrosyamollbuncwletedcombbeoisloteitheecweinidncataomassfedomexeuftavenideirhauhwieyouedeveibunwbnytheundexthotatrostnpegfoidedpbeveibleganmtnthelostcomthedeyeotnytheauemaomdthesfauadenypnfdauuoweihowswinteutedthemamthleganmyincdassnlftanmogiaunlorosloigelbleyttnhasnrmdevauesamthewinvamuethnfghatroscodeuleoitnhacthottnietfimrnfldceomotpestdasgioueomdotrnistdeothamopieokrathtiodatanmthemamthioasedomerstomdoidtheleganmrosexaledamdasgiouetnemdfiethehoidomddomgeinfsrniknysfpdfamgtheuolednmaaamthepleokraldeimessesnyuolednmaosfetnmafsnideiedthemamthtncoiuhtnepnioufcrhauhthebreietncoketheaiposeyniioadsamtnuolednmaothefmswnkemieosnmynitheaiexalerosthotamtellagemueiewnitssfggestedthotthasrosrheiethebcaghtyamdtheailnstoqfalothnserhnrnfldieodnmcfstynllnrcbyoathyflslovetainrhnyouesogiovetoskweihowstheloigesttndoteoshetiovelstnunmueoltheynfithuhowteinythastiogautole\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 abcdefghnjylmiopqwstuvrxkz -6332.700651780452 mhaleatastnfethotsfetiwafssetfrthekawolpottlemathpifdauuootmotlawgstneethehodweathenthetniirswinthetoutauolopalatbtiivenuicethehfgewfcenauoldasodvowtogekouedpbhasoncbmathiftthesfrrintikognauiloowdhastolewtedsuiftsdekeotmifldhovepeewawevatopleowdmathatthelissikpnatowwaohovawgneolasedthottheauewameneneodawghasuiccfwauotaiwsognauiloonnowgedtirlowtkolseawkincotaiwopifttherlowweddasrisataiwiktniirssettawgotnorawtimhauhtheauewakellatasstallfwuleonhimthesovogetnapeshodleonwedtideuarhenifnoncbsuiccfwauotaiwsosthebhodwimnatawgiktheanimwhimevenevenboncbhosatstnoatinsowdatseecslayelbticethotiweincineiktheliuoltnapesreirletfnwedsiceiwesheodliveinciwebatasolltneouhenbpftthasoutthneotewedtifwdencawetheecranesewtanesbstecikseufneuiccfwauotaiwtheuoesonuarhenrenhorscinethowniodshodewopledtheecranetikfwutaiwseufnelbowdatslissmosodasostentfnwawgthotlissawtiovautinbiwthepottlekaelddesenvedcineneuigwataiwthowatneueavedrenhorssfetiwafswevenyweminrenhorshekoaledtifwdenstowdtheufwwawgiktherlowpfteathenmobdesratethevautinbognauiloowdthewawthlegaiwnecoawedawdasgnoueiwheonawgthaswemsulofdafsuoesonofgfstfsgencowaufsweniecreninassfedoseunetrniulocotaiwestoplashawgouarhensuhiiltidevelirowemsbstecikacrenaoluarhensatminyedawseunetkiniventmewtbbeonsdevelirawgwemcethidstiseufneuiccfwauotaiwsounisstheecranestfdbawgtheminysikthegneeysogesefuladowdhbrotaoowdevewildenminysknicowuaewtpopbliwthesuhiildeveliredwemmobstisokegfonduiccfwauotaiwsknicnicesewecaesthesewemsbstecsmenemnattewdimwowddastnapftedawtheuidexiuufltinfcrenhorstheciststnautlbgfondeddiufcewtawollhastinbmhewatmoskawollbuicrletedcowbbeonslotentheecrenindicataowassfedowexeuftaveindenmhauhrnekouedevenbuirbiktheuidexthotatmostipegfondedpbevenblegaiwtithelostcowthedekeotiktheauewaowdthesfauadeikpifdauuorenhorsrniteutedthewawthlegaiwknicdassilftaiwognauilomoslongelblekttihasimwdevauesawthernivawuethifghatmoscodeuleontihacthottinetfnwmifldceowotpestdasgnoueowdotminstdeothawopneoymathtnodataiwthewawthnoasedowemstowdondthelegaiwmosexaledawdasgnouetiewdfnethehondowddowgenifsminyiksfpdfawgtheuolediwaaawthepleoymaldenwessesikuolediwaosfetiwafsindenedthewawthticonuhtiepinoufcmhauhthebmeneticoyetheanposekinnoadsawtiuolediwaothefwsriyewneosiwkintheanexalemosthotawtellagewuenerintssfggestedthotthasmosmhenethebcaghtkawdtheanlistoqfalothisemhimifldneodiwcfstkillimcbkoathkflslovetanimhikouesognovetosyrenhorsthelongesttidoteoshetnovelstiuiwueolthekifnthuhortenikthastnogautole\n", + "0 awcdefghijklmnopqrstuvbxyz -6259.828883380676 mhaleatastifethotsfetnrafssetfbtheyarolpottlemathpnfdauuootmotlargstieethehodreatheithetinnbsrnithetoutauolopalatwtnnveiuncethehfgerfceiauoldasodvortogeyouedpwhasoicwmathnftthesfbbnitnyogiaunloordhastolertedsunftsdeyeotmnfldhovepeerarevatopleordmathatthelnssnypiatorraohovargieolasedthottheauerameieieodarghasunccfrauotanrsogiaunlooiiorgedtnblortyolsearynicotanropnfttheblorreddasbnsatanrnytinnbssettargotiobartnmhauhtheauerayellatasstallfruleoihnmthesovogetiapeshodleoiredtndeuabheinfioicwsunccfrauotanrsosthewhodrnmiatargnytheainmrhnmeveieveiwoicwhosatstioatnisordatseecslakelwtncethotnrenicnienythelnuoltiapesbenbletfiredsncenresheodlnvenicnrewatasolltieouheiwpftthasoutthieoteredtnfrdeicaretheecbaiesertaieswstecnyseufieunccfrauotanrtheuoesoiuabheibeihobscniethorinodshoderopledtheecbaietnyfrutanrseufielwordatslnssmosodasosteitfirargthotlnssartnovautniwnrthepottleyaelddeseivedcnieieungratanrthoratieueavedbeihobssfetnrafsreveikremnibeihobsheyoaledtnfrdeistordtheufrrargnytheblorpfteatheimowdesbatethevautniwogiaunloordtherarthleganriecoaredardasgiouenrheoiargthasremsulofdafsuoesoiofgfstfsgeicoraufsreinecbeiniassfedoseuietbinulocotanrestoplashargouabheisuhnnltndevelnboremswstecnyacbeiaoluabheisatmnikedarseuietyninveitmertwweoisdevelnbargremcethndstnseufieunccfrauotanrsouinsstheecbaiestfdwargthemniksnythegieeksogesefuladordhwbotaoordevernldeimniksyincoruaertpopwlnrthesuhnnldevelnbedremmowstnsoyegfoidunccfrauotanrsyincinceserecaestheseremswstecsmeiemiatterdnmrorddastiapftedartheundexnuufltnifcbeihobsthecnststiautlwgfoideddnufcertarollhastniwmheratmosyarollwuncbletedcorwweoisloteitheecbeinidncataorassfedorexeuftavenideimhauhbieyouedeveiwunbwnytheundexthotatmostnpegfoidedpweveiwleganrtnthelostcorthedeyeotnytheaueraordthesfauadenypnfdauuobeihobsbinteutedtherarthleganryincdassnlftanrogiaunlomosloigelwleyttnhasnmrdevauesarthebinvaruethnfghatmoscodeuleoitnhacthottnietfirmnfldceorotpestdasgioueordotmnistdeotharopieokmathtiodatanrtherarthioasedoremstordoidtheleganrmosexaledardasgiouetnerdfiethehoidorddorgeinfsmniknysfpdfargtheuolednraaarthepleokmaldeiressesnyuolednraosfetnrafsnideiedtherarthtncoiuhtnepnioufcmhauhthewmeietncoketheaiposeyniioadsartnuolednraothefrsbnkerieosnrynitheaiexalemosthotartellagerueiebnitssfggestedthotthasmosmheiethewcaghtyardtheailnstoqfalothnsemhnmnfldieodnrcfstynllnmcwyoathyflslovetainmhnyouesogiovetoskbeihobstheloigesttndoteoshetiovelstnunrueoltheynfithuhobteinythastiogautole\n", + "0 abtdefghijklmnopqrscuvwxyz -6404.904935483241 mhaleacascifechocsfecnrafssecfwcheyarolpocclemachpnfdauuoocmoclargscieechehodreacheichecinnwsrnichecoucauolopalacbcnnveiuntechehfgerfteiauoldasodvorcogeyouedpbhasoitbmachnfcchesfwwnicnyogiaunloordhascolercedsunfcsdeyeocmnfldhovepeerarevacopleordmachacchelnssnypiacorraohovargieolasedchoccheauerameieieodarghasunttfrauocanrsogiaunlooiiorgedcnwlorcyolsearynitocanropnfcchewlorreddaswnsacanrnycinnwsseccargociowarcnmhauhcheauerayellacasscallfruleoihnmchesovogeciapeshodleoiredcndeuawheinfioitbsunttfrauocanrsoschebhodrnmiacargnycheainmrhnmeveieveiboitbhosacscioacnisordacseetslakelbcntechocnrenitnienychelnuolciapeswenwlecfiredsntenresheodlnvenitnrebacasollcieouheibpfcchasoucchieoceredcnfrdeitarecheetwaiesercaiesbscetnyseufieunttfrauocanrcheuoesoiuawheiweihowstniechorinodshoderopledcheetwaiecnyfrucanrseufielbordacslnssmosodasosceicfirargchoclnssarcnovaucnibnrchepoccleyaelddeseivedtnieieungracanrchoracieueavedweihowssfecnrafsreveikremniweihowsheyoaledcnfrdeiscordcheufrrargnychewlorpfceacheimobdeswacechevaucnibogiaunloordcherarchleganrietoaredardasgiouenrheoiargchasremsulofdafsuoesoiofgfscfsgeitoraufsreinetweiniassfedoseuiecwinulotocanrescoplashargouawheisuhnnlcndevelnworemsbscetnyatweiaoluawheisacmnikedarseuiecyninveicmercbbeoisdevelnwargremtechndscnseufieunttfrauocanrsouinsscheetwaiescfdbargchemniksnychegieeksogesefuladordhbwocaoordevernldeimniksyintoruaercpopblnrchesuhnnldevelnwedremmobscnsoyegfoidunttfrauocanrsyintinteseretaescheseremsbscetsmeiemiaccerdnmrorddasciapfcedarcheundexnuuflcniftweihowschetnscsciauclbgfoideddnuftercarollhascnibmheracmosyarollbuntwlecedtorbbeoisloceicheetweinidntacaorassfedorexeufcavenideimhauhwieyouedeveibunwbnycheundexchocacmoscnpegfoidedpbeveibleganrcnchelosctorchedeyeocnycheaueraordchesfauadenypnfdauuoweihowswinceucedcherarchleganryintdassnlfcanrogiaunlomosloigelbleyccnhasnmrdevauesarchewinvaruechnfghacmostodeuleoicnhatchoccniecfirmnfldteorocpescdasgioueordocmniscdeocharopieokmachciodacanrcherarchioasedoremscordoidcheleganrmosexaledardasgiouecnerdfiechehoidorddorgeinfsmniknysfpdfargcheuolednraaarchepleokmaldeiressesnyuolednraosfecnrafsnideiedcherarchcntoiuhcnepniouftmhauhchebmeiecntokecheaiposeyniioadsarcnuolednraochefrswnkerieosnrynicheaiexalemoschocarcellagerueiewnicssfggescedchocchasmosmheiechebtaghcyardcheailnscoqfalochnsemhnmnfldieodnrtfscynllnmtbyoachyflslovecainmhnyouesogiovecoskweihowscheloigesccndoceosheciovelscnunrueolcheynfichuhowceinychasciogaucole\n", + "1 awcdefphijklmnogqrstuvbxyz -6257.505870319161 mhaleatastifethotsfetnrafssetfbtheyarolgottlemathgnfdauuootmotlarpstieethehodreatheithetinnbsrnithetoutauologalatwtnnveiuncethehfperfceiauoldasodvortopeyouedgwhasoicwmathnftthesfbbnitnyopiaunloordhastolertedsunftsdeyeotmnfldhovegeerarevatogleordmathatthelnssnygiatorraohovarpieolasedthottheauerameieieodarphasunccfrauotanrsopiaunlooiiorpedtnblortyolsearynicotanrognfttheblorreddasbnsatanrnytinnbssettarpotiobartnmhauhtheauerayellatasstallfruleoihnmthesovopetiageshodleoiredtndeuabheinfioicwsunccfrauotanrsosthewhodrnmiatarpnytheainmrhnmeveieveiwoicwhosatstioatnisordatseecslakelwtncethotnrenicnienythelnuoltiagesbenbletfiredsncenresheodlnvenicnrewatasolltieouheiwgftthasoutthieoteredtnfrdeicaretheecbaiesertaieswstecnyseufieunccfrauotanrtheuoesoiuabheibeihobscniethorinodshoderogledtheecbaietnyfrutanrseufielwordatslnssmosodasosteitfirarpthotlnssartnovautniwnrthegottleyaelddeseivedcnieieunpratanrthoratieueavedbeihobssfetnrafsreveikremnibeihobsheyoaledtnfrdeistordtheufrrarpnytheblorgfteatheimowdesbatethevautniwopiaunloordtherarthlepanriecoaredardaspiouenrheoiarpthasremsulofdafsuoesoiofpfstfspeicoraufsreinecbeiniassfedoseuietbinulocotanrestoglasharpouabheisuhnnltndevelnboremswstecnyacbeiaoluabheisatmnikedarseuietyninveitmertwweoisdevelnbarpremcethndstnseufieunccfrauotanrsouinsstheecbaiestfdwarpthemniksnythepieeksopesefuladordhwbotaoordevernldeimniksyincoruaertgogwlnrthesuhnnldevelnbedremmowstnsoyepfoidunccfrauotanrsyincinceserecaestheseremswstecsmeiemiatterdnmrorddastiagftedartheundexnuufltnifcbeihobsthecnststiautlwpfoideddnufcertarollhastniwmheratmosyarollwuncbletedcorwweoisloteitheecbeinidncataorassfedorexeuftavenideimhauhbieyouedeveiwunbwnytheundexthotatmostngepfoidedgweveiwlepanrtnthelostcorthedeyeotnytheaueraordthesfauadenygnfdauuobeihobsbinteutedtherarthlepanryincdassnlftanropiaunlomosloipelwleyttnhasnmrdevauesarthebinvaruethnfphatmoscodeuleoitnhacthottnietfirmnfldceorotgestdaspioueordotmnistdeotharogieokmathtiodatanrtherarthioasedoremstordoidthelepanrmosexaledardaspiouetnerdfiethehoidorddorpeinfsmniknysfgdfarptheuolednraaarthegleokmaldeiressesnyuolednraosfetnrafsnideiedtherarthtncoiuhtnegnioufcmhauhthewmeietncoketheaigoseyniioadsartnuolednraothefrsbnkerieosnrynitheaiexalemosthotartellaperueiebnitssfppestedthotthasmosmheiethewcaphtyardtheailnstoqfalothnsemhnmnfldieodnrcfstynllnmcwyoathyflslovetainmhnyouesopiovetoskbeihobstheloipesttndoteoshetiovelstnunrueoltheynfithuhobteinythastiopautole\n" + ] + }, + { + "data": { + "text/plain": [ + "('abmdefghijklcnopqrstuvwxyz', -6227.81870975455)" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# monoalphabetic_break_hillclimbing_mp(scbpt, alphabet=string.ascii_lowercase, fitness=Pbigrams)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'MHALEATASTIFETHOTSFETNRAFSSETFWTHEYAROLPOTTLEMATHPNFDAUUOOTMOTLARGSTIEETHEHODREATHEITHETINNWSRNITHETOUTAUOLOPALATBTNNVEIUNCETHEHFGERFCEIAUOLDASODVORTOGEYOUEDPBHASOICBMATHNFTTHESFWWNITNYOGIAUNLOORDHASTOLERTEDSUNFTSDEYEOTMNFLDHOVEPEERAREVATOPLEORDMATHATTHELNSSNYPIATORRAOHOVARGIEOLASEDTHOTTHEAUERAMEIEIEODARGHASUNCCFRAUOTANRSOGIAUNLOOIIORGEDTNWLORTYOLSEARYNICOTANROPNFTTHEWLORREDDASWNSATANRNYTINNWSSETTARGOTIOWARTNMHAUHTHEAUERAYELLATASSTALLFRULEOIHNMTHESOVOGETIAPESHODLEOIREDTNDEUAWHEINFIOICBSUNCCFRAUOTANRSOSTHEBHODRNMIATARGNYTHEAINMRHNMEVEIEVEIBOICBHOSATSTIOATNISORDATSEECSLAKELBTNCETHOTNRENICNIENYTHELNUOLTIAPESWENWLETFIREDSNCENRESHEODLNVENICNREBATASOLLTIEOUHEIBPFTTHASOUTTHIEOTEREDTNFRDEICARETHEECWAIESERTAIESBSTECNYSEUFIEUNCCFRAUOTANRTHEUOESOIUAWHEIWEIHOWSCNIETHORINODSHODEROPLEDTHEECWAIETNYFRUTANRSEUFIELBORDATSLNSSMOSODASOSTEITFIRARGTHOTLNSSARTNOVAUTNIBNRTHEPOTTLEYAELDDESEIVEDCNIEIEUNGRATANRTHORATIEUEAVEDWEIHOWSSFETNRAFSREVEIKREMNIWEIHOWSHEYOALEDTNFRDEISTORDTHEUFRRARGNYTHEWLORPFTEATHEIMOBDESWATETHEVAUTNIBOGIAUNLOORDTHERARTHLEGANRIECOAREDARDASGIOUENRHEOIARGTHASREMSULOFDAFSUOESOIOFGFSTFSGEICORAUFSREINECWEINIASSFEDOSEUIETWINULOCOTANRESTOPLASHARGOUAWHEISUHNNLTNDEVELNWOREMSBSTECNYACWEIAOLUAWHEISATMNIKEDARSEUIETYNINVEITMERTBBEOISDEVELNWARGREMCETHNDSTNSEUFIEUNCCFRAUOTANRSOUINSSTHEECWAIESTFDBARGTHEMNIKSNYTHEGIEEKSOGESEFULADORDHBWOTAOORDEVERNLDEIMNIKSYINCORUAERTPOPBLNRTHESUHNNLDEVELNWEDREMMOBSTNSOYEGFOIDUNCCFRAUOTANRSYINCINCESERECAESTHESEREMSBSTECSMEIEMIATTERDNMRORDDASTIAPFTEDARTHEUNDEXNUUFLTNIFCWEIHOWSTHECNSTSTIAUTLBGFOIDEDDNUFCERTAROLLHASTNIBMHERATMOSYAROLLBUNCWLETEDCORBBEOISLOTEITHEECWEINIDNCATAORASSFEDOREXEUFTAVENIDEIMHAUHWIEYOUEDEVEIBUNWBNYTHEUNDEXTHOTATMOSTNPEGFOIDEDPBEVEIBLEGANRTNTHELOSTCORTHEDEYEOTNYTHEAUERAORDTHESFAUADENYPNFDAUUOWEIHOWSWINTEUTEDTHERARTHLEGANRYINCDASSNLFTANROGIAUNLOMOSLOIGELBLEYTTNHASNMRDEVAUESARTHEWINVARUETHNFGHATMOSCODEULEOITNHACTHOTTNIETFIRMNFLDCEOROTPESTDASGIOUEORDOTMNISTDEOTHAROPIEOKMATHTIODATANRTHERARTHIOASEDOREMSTORDOIDTHELEGANRMOSEXALEDARDASGIOUETNERDFIETHEHOIDORDDORGEINFSMNIKNYSFPDFARGTHEUOLEDNRAAARTHEPLEOKMALDEIRESSESNYUOLEDNRAOSFETNRAFSNIDEIEDTHERARTHTNCOIUHTNEPNIOUFCMHAUHTHEBMEIETNCOKETHEAIPOSEYNIIOADSARTNUOLEDNRAOTHEFRSWNKERIEOSNRYNITHEAIEXALEMOSTHOTARTELLAGERUEIEWNITSSFGGESTEDTHOTTHASMOSMHEIETHEBCAGHTYARDTHEAILNSTOQFALOTHNSEMHNMNFLDIEODNRCFSTYNLLNMCBYOATHYFLSLOVETAINMHNYOUESOGIOVETOSKWEIHOWSTHELOIGESTTNDOTEOSHETIOVELSTNUNRUEOLTHEYNFITHUHOWTEINYTHASTIOGAUTOLE'" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trhc = ''.maketrans('abmdefghijklcnopqrstuvwxyz', string.ascii_lowercase)\n", + "scbpt.translate(trhc)" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_grid(keyword, column_order, row_order, letters_to_merge=None,\n", + " wrap_alphabet=KeywordWrapAlphabet.from_a):\n", + " alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet=wrap_alphabet)\n", + " if letters_to_merge is None: \n", + " letters_to_merge = {'j': 'i'}\n", + " grid = {l: k \n", + " for k, l in zip([(c, r) for c in column_order for r in row_order],\n", + " [l for l in alphabet if l not in letters_to_merge])}\n", + " for l in letters_to_merge:\n", + " grid[l] = grid[letters_to_merge[l]]\n", + " return grid " + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': ('x', 'x'),\n", + " 'b': ('x', 'l'),\n", + " 'c': ('x', 'c'),\n", + " 'd': ('x', 'd'),\n", + " 'e': ('x', 'm'),\n", + " 'f': ('l', 'x'),\n", + " 'g': ('l', 'l'),\n", + " 'h': ('l', 'c'),\n", + " 'i': ('l', 'd'),\n", + " 'j': ('l', 'd'),\n", + " 'k': ('l', 'm'),\n", + " 'l': ('c', 'x'),\n", + " 'm': ('c', 'l'),\n", + " 'n': ('c', 'c'),\n", + " 'o': ('c', 'd'),\n", + " 'p': ('c', 'm'),\n", + " 'q': ('d', 'x'),\n", + " 'r': ('d', 'l'),\n", + " 's': ('d', 'c'),\n", + " 't': ('d', 'd'),\n", + " 'u': ('d', 'm'),\n", + " 'v': ('m', 'x'),\n", + " 'w': ('m', 'l'),\n", + " 'x': ('m', 'c'),\n", + " 'y': ('m', 'd'),\n", + " 'z': ('m', 'm')}" + ] + }, + "execution_count": 118, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_grid('', order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_reverse_grid(keyword, column_order, row_order, letters_to_merge=None,\n", + " wrap_alphabet=KeywordWrapAlphabet.from_a):\n", + " alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet=wrap_alphabet)\n", + " if letters_to_merge is None: \n", + " letters_to_merge = {'j': 'i'}\n", + " grid = {k: l \n", + " for k, l in zip([(c, r) for c in column_order for r in row_order],\n", + " [l for l in alphabet if l not in letters_to_merge])}\n", + "# for l in letters_to_merge:\n", + "# for r, c in grid:\n", + "# if grid[r, c] == letters_to_merge[l]:\n", + "# grid[l] = grid[r, c]\n", + " return grid " + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{('c', 'c'): 'n',\n", + " ('c', 'd'): 'o',\n", + " ('c', 'l'): 'm',\n", + " ('c', 'm'): 'p',\n", + " ('c', 'x'): 'l',\n", + " ('d', 'c'): 's',\n", + " ('d', 'd'): 't',\n", + " ('d', 'l'): 'r',\n", + " ('d', 'm'): 'u',\n", + " ('d', 'x'): 'q',\n", + " ('l', 'c'): 'h',\n", + " ('l', 'd'): 'i',\n", + " ('l', 'l'): 'g',\n", + " ('l', 'm'): 'k',\n", + " ('l', 'x'): 'f',\n", + " ('m', 'c'): 'x',\n", + " ('m', 'd'): 'y',\n", + " ('m', 'l'): 'w',\n", + " ('m', 'm'): 'z',\n", + " ('m', 'x'): 'v',\n", + " ('x', 'c'): 'c',\n", + " ('x', 'd'): 'd',\n", + " ('x', 'l'): 'b',\n", + " ('x', 'm'): 'e',\n", + " ('x', 'x'): 'a'}" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse_polybius_grid('', order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_encipher_letter(l, grid):\n", + " if l in grid:\n", + " return grid[l]\n", + " else:\n", + " return l" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_flatten(pair, column_first):\n", + " if column_first:\n", + " return str(pair[1]) + str(pair[0])\n", + " else:\n", + " return str(pair[0]) + str(pair[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_encipher(message, keyword, column_order, row_order, \n", + " column_first=False,\n", + " letters_to_merge=None, wrap_alphabet=KeywordWrapAlphabet.from_a): \n", + " grid = polybius_grid(keyword, column_order, row_order, letters_to_merge, wrap_alphabet)\n", + " return cat(polybius_flatten(grid[l], column_first)\n", + " for l in message\n", + " if l in grid)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'mllcldcxxmldddlddcdddldmxm'" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_encipher('while it is true', '', order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'mllcldcxxmldddlddcdddldmxmddlcxxdddcdmxmddcdcclddmdcdcxmdddmcmddlcxmlxldccxxcxxlxxdd'" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sanitise(cb[:100])" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "metadata": {}, + "outputs": [], + "source": [ + "def polybius_decipher(message, keyword, column_order, row_order, \n", + " column_first=False,\n", + " letters_to_merge=None, wrap_alphabet=KeywordWrapAlphabet.from_a): \n", + " grid = polybius_reverse_grid(keyword, column_order, row_order, letters_to_merge, wrap_alphabet)\n", + " if column_first:\n", + " pairs = [(p[1], p[0]) for p in chunks(message, 2)]\n", + " else:\n", + " pairs = [(p[0], p[1]) for p in chunks(message, 2)]\n", + " return cat(grid[p] for p in pairs if p in grid)" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'whileitistrue'" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_decipher('mllcldcxxmldddlddcdddldmxm', '', order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 158, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'lmcldlxcmxdldddlcdddldmdmx'" + ] + }, + "execution_count": 158, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_encipher('whileitistrue', '', order, order, column_first=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'kmrcvrtrotiyv'" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_decipher('lmcldlxcmxdldddlcdddldmdmx', '', order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'whileitistrue'" + ] + }, + "execution_count": 162, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_decipher('lmcldlxcmxdldddlcdddldmdmx', '', order, order, column_first=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'52232431152444244344424515'" + ] + }, + "execution_count": 167, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "polybius_encipher('while it is true', '', '12345', '12345')" + ] + }, + { + "cell_type": "code", + "execution_count": 181, + "metadata": {}, + "outputs": [], + "source": [ + "from multiprocessing import Pool\n", + "import itertools\n", + "\n", + "def polybius_break_mp(message, column_order, row_order,\n", + " letters_to_merge=None,\n", + " wordlist=keywords, fitness=Pletters,\n", + " number_of_solutions=1, chunksize=500):\n", + " \"\"\"Breaks a keyword substitution cipher using a dictionary and\n", + " frequency analysis\n", + "\n", + " >>> keyword_break_mp(keyword_encipher('this is a test message for the ' \\\n", + " 'keyword decipherment', 'elephant', KeywordWrapAlphabet.from_last), \\\n", + " wordlist=['cat', 'elephant', 'kangaroo']) # doctest: +ELLIPSIS\n", + " (('elephant', ), -52.834575011...)\n", + " >>> keyword_break_mp(keyword_encipher('this is a test message for the ' \\\n", + " 'keyword decipherment', 'elephant', KeywordWrapAlphabet.from_last), \\\n", + " wordlist=['cat', 'elephant', 'kangaroo'], \\\n", + " number_of_solutions=2) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n", + " [(('elephant', ), -52.834575011...), \n", + " (('elephant', ), -52.834575011...)]\n", + " \"\"\"\n", + " if letters_to_merge is None: \n", + " letters_to_merge = {'j': 'i'}\n", + " with Pool() as pool:\n", + " helper_args = [(message, word, wrap, \n", + " cs, rs, column_first, \n", + " letters_to_merge, \n", + " fitness)\n", + " for word in wordlist\n", + " for wrap in KeywordWrapAlphabet\n", + " for cs in itertools.permutations(column_order)\n", + " for rs in itertools.permutations(row_order)\n", + " for column_first in [False, True]]\n", + " # Gotcha: the helper function here needs to be defined at the top level\n", + " # (limitation of Pool.starmap)\n", + " breaks = pool.starmap(polybius_break_worker, helper_args, chunksize)\n", + " if number_of_solutions == 1:\n", + " return max(breaks, key=lambda k: k[1])\n", + " else:\n", + " return sorted(breaks, key=lambda k: k[1], reverse=True)[:number_of_solutions]\n", + "\n", + "def polybius_break_worker(message, keyword, wrap_alphabet, \n", + " column_order, row_order, column_first, \n", + " letters_to_merge, \n", + " fitness):\n", + " plaintext = polybius_decipher(message, keyword, \n", + " column_order, row_order, \n", + " column_first=column_first,\n", + " letters_to_merge=letters_to_merge, \n", + " wrap_alphabet=wrap_alphabet)\n", + " fit = fitness(plaintext)\n", + " logger.debug('Keyword break attempt using key {0} (wrap={1}) gives fit of '\n", + " '{2} and decrypt starting: {3}'.format(keyword, \n", + " wrap_alphabet, fit, sanitise(plaintext)[:50]))\n", + " return (keyword, wrap_alphabet, column_order, row_order, column_first), fit" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%time polybius_break_mp(sanitise(cb), order, order)" + ] + }, + { + "cell_type": "code", + "execution_count": 183, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'xlcdm'" + ] + }, + "execution_count": 183, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order" + ] + }, { "cell_type": "code", "execution_count": null,