From: Neil Smith Date: Fri, 10 Nov 2017 09:08:35 +0000 (+0000) Subject: Done 2017 challenge 5 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=6399b876a6d50d11ad318ab0fd0db74e03168ed8;p=cipher-tools.git Done 2017 challenge 5 --- diff --git a/2017/2017-challenge5.ipynb b/2017/2017-challenge5.ipynb new file mode 100644 index 0000000..aaee5b6 --- /dev/null +++ b/2017/2017-challenge5.ipynb @@ -0,0 +1,907 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os,sys,inspect, collections\n", + "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n", + "parentdir = os.path.dirname(currentdir)\n", + "sys.path.insert(0,parentdir) \n", + "\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "from cipherbreak import *\n", + "\n", + "ca = open('5a.ciphertext').read()\n", + "cb = open('5b.ciphertext').read()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def tpack(text, width=100):\n", + " lines = [text[0]]\n", + " for word in text[1:]:\n", + " if len(lines[-1]) + 1 + len(word) <= width:\n", + " lines[-1] += (' ' + word)\n", + " else:\n", + " lines += [word]\n", + " return lines" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "JDPWD JGLOF YBDQA LKYFD PPFTY OFKQY ICSHD QMIDK KYOES RQBYO FOKRJ DHYRB YPYKO YXTLS QRBYI LCDIQ RDRFL KRBFK HQBYJ DWBDT YEYYK HFOKD MMYOE SRRBY PYBDQ EYYKK LPDKQ LJOYJ DKODK ORBYP YFQKL RBFKA JSCBR LALLK BYPPL LJBDO EYYKP DKQDC HYODK OQBYI YZRKL JYQQD AYESR QLJYR BFKAR YIIQJ YQBYF QLHDK OUYQB LSIOJ LTYLK FRBFK HQBYJ DWBDT YMIDK KYORB FQJYD KUBFI YFBDT YRBYO LCSJY KRGLO FYUDK RYOZP LJILK OLKFO LKRHK LUBLU QBYHK YUESR RBYZF ZRBCB DMRYP UDQBF OOYKF KDCDT FRWFK DQRLK YIFKR YIFKQ LJYPY JDFKQ FKRBY YMBYQ SQPLL JDRRB YEPFR FQBJS QYSJF RUDQY KCPWM RYOSQ FKADK LRBYP MLIWD IMBDE YRFCC FMBYP FKTYK RYOFK RBYKF KYRYY KRBCY KRSPW FDQHY ORBYJ SQYSJ RLRYQ RFRDK ORBYO LCSJY KRFQD SRBYK RFCQL FASYQ QRBYF JMYPF DICFM BYPQC BLLIP YDIIW BDOJL TYOLK MYPBD MQFQB LSIOK RBDTY EYYKQ SPMPF QYODZ RYPRB YOFQC LTYPW DRELO PSJES RFRIY DTYQJ YULKO YPFKA UBDRY IQYRB YWOYT YILMY OLKYL OOZYD RSPYU DQDZP FYXYP SKKFK APLSK ORBPY YQFOY QLZRB YIFKR YICLK QFQRF KALZD QFKAI YPLUL ZEIDC HDKOU BFRYR FIYQR BDRRB YJSQY SJRBF KHUYP YDOOY OFKRB YPLJD KMYPF LORBY WPYDO FKQYN SYKCY UUEEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE EUUUE UUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUUE UUUEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUEUU UEUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UEUUU EUUUU EUUUE EEUUU UUEEE UUUEU UUEUU UEUUU EUUUU EEEUU EUUUE UEEEU UUEEE EUUEE EUUUE EEUUE EEUEU UUEUU UUEUE UUEUU EUUUE UUUUU EUEUU EEUUE UUEUE UUUUE UUUEE UEEUE UUEUU EUUUU UEUUE UUUEU UUUEU UUEUU UEUUE UUUEU EUUUE UEUUU UUEUU UEUEU EUEUE UUUEU UUEUU UEUEU EUEUU EUUEU UUUUE UUUEU UEUUU UEUUE UUUEU UUEEE EEUEE EEUUE UUUUU EEEEE UEUEU EUEEE EEUUU EUUUE UUUEU EEEEU UEEEU UUEEE EUUUE UUUUE UUUEU UUEUU EUUUE UEUEU UUEUU UUUEU UUEUE UEUEU EUUUE UUUEU UUEUU UEUEU UUUUE UUUUU EUEUU UUEUU UUEUU EUUUE UUUEU UUEUE UUEUU UEUUU UEUUU EUEUU EEUEU UUEUU UEUUU EUUUE UEUUU UUEUU UUUEU UEUUU EUUUU EUUUE UUUEU UEUUU EUEUU UEUUU EEEUE UUUEU EUUUE UEUUU EUUEE EUUEU UUEUE UUUUU EEEEU UEUUU EUEEE UUEEE UEUUU EUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU EUUUE UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUEUU UEUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UEUUU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU UUEUU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UUEUU UEUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUE UUFBD TYSQY OEZLP RBYEI DCHRF IYQDK OUZLP RBYUB FRYLK YQFRR LLHJY DUBFI YRLZF ASPYL SRRBD RRBYZ PFYXY FQQRY ADKLA PDMBW CLKCY DIFKA RBYHY WULPO ZLPRB YCFMB YPFKC BDMRY PZFTY UFRBL SRGLO FYFDJ KLRQS PYUBY PYRLA LKYVR RBYPY DPYLK IWRUL MLQQF EFIFR FYQDQ ZDPDQ FCDKQ YYESR FBDTY KLFOY DUBYP YLKYL ZRBYJ FQDKO DQZDP DQFCD KRYII KLLKY YIQYH KLUQY FRBYP QLFAS YQQFU FIIBY DOZLP LIWJM FDQYY WLSRB YPY\n" + ] + } + ], + "source": [ + "print(ca)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "ca_text = '''\n", + "JDPWD JGLOF YBDQA LKYFD PPFTY OFKQY ICSHD QMIDK KYOES RQBYO FOKRJ DHYRB YPYKO YXTLS QRBYI \n", + "LCDIQ RDRFL KRBFK HQBYJ DWBDT YEYYK HFOKD MMYOE SRRBY PYBDQ EYYKK LPDKQ LJOYJ DKODK ORBYP \n", + "YFQKL RBFKA JSCBR LALLK BYPPL LJBDO EYYKP DKQDC HYODK OQBYI YZRKL JYQQD AYESR QLJYR BFKAR \n", + "YIIQJ YQBYF QLHDK OUYQB LSIOJ LTYLK FRBFK HQBYJ DWBDT YMIDK KYORB FQJYD KUBFI YFBDT YRBYO \n", + "LCSJY KRGLO FYUDK RYOZP LJILK OLKFO LKRHK LUBLU QBYHK YUESR RBYZF ZRBCB DMRYP UDQBF OOYKF \n", + "KDCDT FRWFK DQRLK YIFKR YIFKQ LJYPY JDFKQ FKRBY YMBYQ SQPLL JDRRB YEPFR FQBJS QYSJF RUDQY\n", + "KCPWM RYOSQ FKADK LRBYP MLIWD IMBDE YRFCC FMBYP FKTYK RYOFK RBYKF KYRYY KRBCY KRSPW FDQHY \n", + "ORBYJ SQYSJ RLRYQ RFRDK ORBYO LCSJY KRFQD SRBYK RFCQL FASYQ QRBYF JMYPF DICFM BYPQC BLLIP \n", + "YDIIW BDOJL TYOLK MYPBD MQFQB LSIOK RBDTY EYYKQ SPMPF QYODZ RYPRB YOFQC LTYPW DRELO PSJES \n", + "RFRIY DTYQJ YULKO YPFKA UBDRY IQYRB YWOYT YILMY OLKYL OOZYD RSPYU DQDZP FYXYP SKKFK APLSK \n", + "ORBPY YQFOY QLZRB YIFKR YICLK QFQRF KALZD QFKAI YPLUL ZEIDC HDKOU BFRYR FIYQR BDRRB YJSQY \n", + "SJRBF KHUYP YDOOY OFKRB YPLJD KMYPF LORBY WPYDO FKQYN SYKCY\n", + " FBD TYSQY OEZLP RBYEI DCHRF IYQDK OUZLP RBYUB FRYLK YQFRR LLHJY DUBFI YRLZF ASPYL SRRBD \n", + "RRBYZ PFYXY FQQRY ADKLA PDMBW CLKCY DIFKA RBYHY WULPO ZLPRB YCFMB YPFKC BDMRY PZFTY UFRBL \n", + "SRGLO FYFDJ KLRQS PYUBY PYRLA LKYVR RBYPY DPYLK IWRUL MLQQF EFIFR FYQDQ ZDPDQ FCDKQ YYESR \n", + "FBDTY KLFOY DUBYP YLKYL ZRBYJ FQDKO DQZDP DQFCD KRYII KLLKY YIQYH KLUQY FRBYP QLFAS YQQFU \n", + "FIIBY DOZLP LIWJM FDQYY WLSRB YPY\n", + "'''\n", + "sca_text = sanitise(ca_text)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(24, -1733.3180566179738)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "key_a, score = caesar_break(sca_text)\n", + "key_a, score" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lfryflinqhadfscnmahfrrhvaqhmsakeujfsokfmmaqgutsdaqhqmtlfjatdaramqazvnustdaknefkstfthnmtdhmjsdalfydfvagaamjhqmfooaqguttdaradfsgaammnrfmsnlqalfmqfmqtdarahsmntdhmcluedtncnnmdarrnnldfqgaamrfmsfejaqfmqsdakabtmnlassfcagutsnlatdhmctakkslasdahsnjfmqwasdnukqlnvanmhtdhmjsdalfydfvaokfmmaqtdhslafmwdhkahdfvatdaqneulamtinqhawfmtaqbrnlknmqnmhqnmtjmnwdnwsdajmawguttdabhbtdedfotarwfsdhqqamhmfefvhtyhmfstnmakhmtakhmsnlaralfhmshmtdaaodasusrnnlfttdagrhthsdlusaulhtwfsameryotaqushmcfmntdaronkyfkodfgatheehodarhmvamtaqhmtdamhmataamtdeamturyhfsjaqtdalusaultntasthtfmqtdaqneulamthsfutdamthesnhcuasstdahloarhfkehodarsednnkrafkkydfqlnvaqnmoardfoshsdnukqmtdfvagaamsurorhsaqfbtartdaqhsenvaryftgnqrulguthtkafvaslawnmqarhmcwdftaksatdayqavaknoaqnmanqqbafturawfsfbrhazarummhmcrnumqtdraashqasnbtdakhmtakenmshsthmcnbfshmckarnwnbgkfejfmqwdhtathkastdfttdalusaultdhmjwarafqqaqhmtdarnlfmoarhnqtdayrafqhmsapuameahdfvausaqgbnrtdagkfejthkasfmqwbnrtdawdhtanmashttnnjlafwdhkatnbhcuranuttdfttdabrhazahsstacfmncrfodyenmeafkhmctdajaywnrqbnrtdaehodarhmedfotarbhvawhtdnutinqhahflmntsurawdaratncnmaxttdarafranmkytwnonsshghkhthasfsbfrfshefmsaaguthdfvamnhqafwdaranmanbtdalhsfmqfsbfrfshefmtakkmnnmaaksajmnwsahtdarsnhcuasshwhkkdafqbnrnkylohfsaaynutdara\n" + ] + } + ], + "source": [ + "print(caesar_decipher(sca_text, key_a))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((17, 21, True), -1723.2877779777489)" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(m_a, a_a, o_a), score = affine_break(sca_text)\n", + "(m_a, a_a, o_a), score" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "gyotygparsneylhadnsyooscnrsdlnjbfmylxjyddnrvfilenrsrdigymnienondrnqcaflienjabyjliyisadiesdmlengyteycnvnndmsrdyxxnrvfiienoneylvnnddaoydlagrngydrydrienonsldaiesdhgfbeiahaadenooaageyrvnndoydlybmnrydrlenjnkidagnllyhnvfilagniesdhinjjlgnlenslamydrznleafjrgacnadsiesdmlengyteycnxjyddnrieslgnydzesjnseycnienrabfgndiparsnzydinrkoagjadradsradimdazeazlenmdnzvfiienkskiebeyxinozylesrrndsdybycsitsdyliadnjsdinjsdlagnongysdlsdiennxenlfloaagyiienvosislegflnfgsizylndbotxinrflsdhydaienoxajtyjxeyvnisbbsxenosdcndinrsdiendsdninndiebndifotsylmnriengflnfgiainlisiydrienrabfgndislyfiendisblashfnlliensgxnosyjbsxenolbeaajonyjjteyrgacnradxnoeyxlsleafjrdieycnvnndlfoxoslnrykinoienrslbacnotyivarofgvfisijnycnlgnzadrnosdhzeyinjlnientrncnjaxnradnarrknyifonzylykosnqnofddsdhoafdrieonnlsrnlakienjsdinjbadlslisdhakylsdhjnoazakvjybmydrzesinisjnlieyiiengflnfgiesdmznonyrrnrsdienoagydxnosarientonyrsdlnufndbnseycnflnrvkaoienvjybmisjnlydrzkaoienzesinadnlsiiaamgnyzesjniakshfonafiieyiienkosnqnsllinhydahoyxetbadbnyjsdhienmntzaorkaoienbsxenosdbeyxinokscnzsieafiparsnsygdailfonzenoniahadnwiienonyonadjtizaxallsvsjsisnlylkyoylsbydlnnvfiseycndasrnyzenonadnakiengslydrylkyoylsbydinjjdaadnnjlnmdazlnsienolashfnllszsjjenyrkaoajtgxsylnntafienon\n" + ] + } + ], + "source": [ + "print(affine_decipher(sca_text, m_a, a_a, o_a))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'etoainhsrdlumwycfgpbvkxjqz'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ltrs = [p[0] for p in english_counts.most_common()]\n", + "cat(ltrs)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'yrkfdlbqpoisjcumzeawhtxgnv'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ctls = [p[0] for p in collections.Counter(sanitise(ca_text)).most_common()]\n", + "cat(ctls)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'A': 'p',\n", + " 'B': 'h',\n", + " 'C': 'w',\n", + " 'D': 'i',\n", + " 'E': 'g',\n", + " 'F': 'a',\n", + " 'G': 'j',\n", + " 'H': 'v',\n", + " 'I': 'l',\n", + " 'J': 'm',\n", + " 'K': 'o',\n", + " 'L': 'n',\n", + " 'M': 'c',\n", + " 'N': 'q',\n", + " 'O': 'd',\n", + " 'P': 'r',\n", + " 'Q': 's',\n", + " 'R': 't',\n", + " 'S': 'u',\n", + " 'T': 'k',\n", + " 'U': 'y',\n", + " 'V': 'z',\n", + " 'W': 'b',\n", + " 'X': 'x',\n", + " 'Y': 'e',\n", + " 'Z': 'f'}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trans = {pr[1].upper(): pr[0] for pr in zip(ltrs, ctls)}\n", + "trans" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mirbi mjnda ehisp noeai rrake daose lwuvi sclio oedgu tshed adotm iveth ereod exknu sthel nwils titan othao vshem ibhik egeeo vadoi ccedg utthe rehis geeoo nrios nmdem iodio dther eason thaop muwht npnno herrn nmhid geeor iosiw vedio dshel efton messi pegut snmet haopt ellsm eshea snvio dyesh nuldm nkeno athao vshem ibhik eclio oedth asmei oyhal eahik ethed nwume otjnd aeyio tedfr nmlno dnoad notvo nyhny shevo eygut thefa fthwh icter yisha ddeoa oiwik atbao istno elaot elaos nmere miaos aothe eches usrnn mitth egrat ashmu seuma tyise owrbc tedus aopio nther cnlbi lchig etaww acher aokeo tedao theoa oetee othwe oturb aisve dthem useum tntes tatio dthed nwume otasi utheo tawsn apues sthea mcera ilwac hersw hnnlr eillb hidmn kedno cerhi csash nuldo thike geeos urcra sedif terth edasw nkerb itgnd rumgu tatle ikesm eynod eraop yhite lseth ebdek elnce dnoen ddfei turey isifr aexer uooao prnuo dthre esade snfth elaot elwno sasta opnfi saopl ernyn fgliw viody hatet alest hitth emuse umtha ovyer eidde daoth ernmi ocera ndthe breid aoseq ueowe yyggy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg gyyyg yygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygyyg yyygy gggyg ggygg gyggg ygggy gggyg ggygg gyggg ygggy gggyg ggygg gyggg ygggy gggyg ggygg gyggg ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yygyy ygyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy ygyyy gyyyy gyyyg ggyyy yyggg yyygy yygyy ygyyy gyyyy gggyy gyyyg ygggy yyggg gyygg gyyyg ggyyg ggygy yygyy yygyg yygyy gyyyg yyyyy gygyy ggyyg yygyg yyyyg yyygg yggyg yygyy gyyyy ygyyg yyygy yyygy yygyy ygyyg yyygy gyyyg ygyyy yygyy ygygy gygyg yyygy yygyy ygygy gygyy gyygy yyyyg yyygy ygyyy ygyyg yyygy yyggg ggygg ggyyg yyyyy ggggg ygygy gyggg ggyyy gyyyg yyygy ggggy ygggy yyggg gyyyg yyyyg yyygy yygyy gyyyg ygygy yygyy yyygy yygyg ygygy gyyyg yyygy yygyy ygygy yyyyg yyyyy gygyy yygyy yygyy gyyyg yyygy yygyg yygyy ygyyy ygyyy gygyy ggygy yygyy ygyyy gyyyg ygyyy yygyy yyygy ygyyy gyyyy gyyyg yyygy ygyyy gygyy ygyyy gggyg yyygy gyyyg ygyyy gyygg gyygy yygyg yyyyy ggggy ygyyy gyggg yyggg ygyyy gyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy gyyyg yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yyyyy yygyy ygygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg ygyyy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy gygyg ygygy yygyy gggyg ggygg gyggg ygggy gggyg ggygg gyggg ygggy gggyg ggygg gyggg ygggy gggyg ggygg gyggg yygyy ygyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyy gyyyg yyygy yygyy ygyyg yyahi keuse dgfnr thegl iwvta lesio dyfnr theyh ateno esatt nnvme iyhal etnfa puren utthi tthef raexe asste pionp richb wnowe ilaop theve bynrd fnrth ewach eraow hicte rfake yathn utjnd aeaim ontsu reyhe retnp noezt there ireno lbtyn cnssa galat aesis firis awios eegut ahike onade iyher enoen fthem asiod isfir isawi otell onnoe elsev onyse ather snapu essay allhe idfnr nlbmc aisee bnuth ere\n" + ] + } + ], + "source": [ + "tt = ''.maketrans(trans)\n", + "print(ca.translate(tt))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maryam jodie has gone i arrived in selcuk as planned but she didnt make the rendezvous the local\n", + "station think she may have been kidnapped but there has been no ransom demand and there is nothing\n", + "much to go on her room had been ransacked and she left no message but something tells me she is ok\n", + "and we should move on i think she may have planned this meanwhile i have the document jodie wanted\n", + "from london i dont know how she knew but the fifth chapter was hidden in a cavity in a stone lintel\n", + "in some remains in the ephesus room at the british museum it was encrypted using another poly\n", + "alphabetic cipher invented in the nineteenth century i asked the museum to test it and the document\n", + "is authentic so i guess the imperial cipher school really had moved on perhaps i shouldnt have been\n", + "surprised after the discovery at bodrum but it leaves me wondering what else they developed one odd\n", + "feature was a frieze running round three sides of the lintel consisting of a single row of\n", + "blackandwhite tiles that the museum think were added in the roman period they read in sequence\n", + "wwbbwwwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www bbw\n", + "wwbw wbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwwb www\n", + "bwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www\n", + "www www www www www www www www www www www www www www www www www www www www www www www www wwbw\n", + "wwbw www www www www www www www www www www www www www www www www www www www www www www www www\n", + "www wwwb wwwb www wb wwwb bbw wwww bbb wwwb wwwb wwwb www bw www bbb wwbw wwbw bbb www bbbb\n", + "wwbbbwwwbbbwwbbbwb www bwwwwbwbwwbwwbwwwbww www bwbwwbbwwbwwbwbwwwwb www bbw bbw\n", + "bwwbwwbwwwwwbwwbwwwb www wb www bwwwbwwbwwwbwbwwwbwb www wwbwwwbwbwbwbwbwwwb www bwwwbwbwbwbwwbwwbww\n", + "www bwwwbwwbwwwwbwwbwwwb www bbb bbw bbbb wwbw wwww bbb bbw bwbwbwbbbbbwwwbwwwbw wwbw bbbb ww bbb\n", + "www bbbb wwwb www wb www bwwwbwwbwwwbwbwbwwwb www wwbwwwbwbwbwbwbwwwb wwwb wwwb www bwb www wwbw\n", + "wwww bwbwwwwbwwwwbwwbwwwb www bwwwbwbwwbwwwbwwwwb www bwbwwbbwbwwwbwwwb wwwb www bwb www wwbw www wb\n", + "wwbw wwbw www bwwwbwwwbwwbwwwbwb wwwb www bbb wbwwwbwbwwwbwbwwwbww bbb wwbw wwbw bww www bbbb wwbw\n", + "wwbwbbbwwbbbwbwwwbww www www www www www www www www www www www www www www www www www www www www\n", + "www www www www www wwbw wwbw www www www www www www www www www www www www www www www www www\n", + "www www www www www www www www wbwwwbwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb www bwb www bwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb\n", + "wbwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb www bwwbbbwbbbwbbbwbbbwb bbw bbb wbbbwbbbwbbbwbbbwb bbw\n", + "bbb wbbbwbbbwbbbwbbbwb bbwbbbwbbbwwbwwwbwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb www bwwwbwwwbwwwbwwbwwi have used b for the black tiles and w for the white ones it\n", + "took me a while to figure out that the frieze is steganography concealing the keyword for the cipher\n", + "in chapter five without jodie i am not sure where to go next there are only two possibilities as far\n", + "as i can see but i have no idea where one of them is and as far as i can tell no one else knows\n", + "either so i guess i will head for olympia see you there\n" + ] + } + ], + "source": [ + "trans = {\n", + " 'A': 'g',\n", + " 'B': 'h',\n", + " 'C': 'c',\n", + " 'D': 'a',\n", + " 'E': 'b',\n", + " 'F': 'i',\n", + " 'G': 'j',\n", + " 'H': 'k',\n", + " 'I': 'l',\n", + " 'J': 'm',\n", + " 'K': 'n',\n", + " 'L': 'o',\n", + " 'M': 'p',\n", + " 'N': 'q',\n", + " 'O': 'd',\n", + " 'P': 'r',\n", + " 'Q': 's',\n", + " 'R': 't',\n", + " 'S': 'u',\n", + " 'T': 'v',\n", + " 'U': 'w',\n", + " 'V': 'x',\n", + " 'W': 'y',\n", + " 'X': 'z',\n", + " 'Y': 'e',\n", + " 'Z': 'f'}\n", + "\n", + "tt = ''.maketrans(trans)\n", + "print('\\n'.join(tpack(segment(sanitise(ca.translate(tt))))))" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'A': 'g',\n", + " 'B': 'h',\n", + " 'C': 'c',\n", + " 'D': 'a',\n", + " 'E': 'b',\n", + " 'F': 'i',\n", + " 'G': 'j',\n", + " 'H': 'k',\n", + " 'I': 'l',\n", + " 'J': 'm',\n", + " 'K': 'n',\n", + " 'L': 'o',\n", + " 'M': 'p',\n", + " 'N': 'q',\n", + " 'O': 'd',\n", + " 'P': 'r',\n", + " 'Q': 's',\n", + " 'R': 't',\n", + " 'S': 'u',\n", + " 'T': 'v',\n", + " 'U': 'w',\n", + " 'V': 'x',\n", + " 'W': 'y',\n", + " 'X': 'z',\n", + " 'Y': 'e',\n", + " 'Z': 'f'}" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trans" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': 'D',\n", + " 'b': 'E',\n", + " 'c': 'C',\n", + " 'd': 'O',\n", + " 'e': 'Y',\n", + " 'f': 'Z',\n", + " 'g': 'A',\n", + " 'h': 'B',\n", + " 'i': 'F',\n", + " 'j': 'G',\n", + " 'k': 'H',\n", + " 'l': 'I',\n", + " 'm': 'J',\n", + " 'n': 'K',\n", + " 'o': 'L',\n", + " 'p': 'M',\n", + " 'q': 'N',\n", + " 'r': 'P',\n", + " 's': 'Q',\n", + " 't': 'R',\n", + " 'u': 'S',\n", + " 'v': 'T',\n", + " 'w': 'U',\n", + " 'x': 'V',\n", + " 'y': 'W',\n", + " 'z': 'X'}" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{v: k for k, v in trans.items()}" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maryam jodie has gone i arrived in selcuk as planned but she didnt make the rendezvous the local\n", + "station think she may have been kidnapped but there has been no ransom demand and there is nothing\n", + "much to go on her room had been ransacked and she left no message but something tells me she is ok\n", + "and we should move on i think she may have planned this meanwhile i have the document jodie wanted\n", + "from london i dont know how she knew but the fifth chapter was hidden in a cavity in a stone lintel\n", + "in some remains in the ephesus room at the british museum it was encrypted using another poly\n", + "alphabetic cipher invented in the nineteenth century i asked the museum to test it and the document\n", + "is authentic so i guess the imperial cipher school really had moved on perhaps i shouldnt have been\n", + "surprised after the discovery at bodrum but it leaves me wondering what else they developed one odd\n", + "feature was a frieze running round three sides of the lintel consisting of a single row of\n", + "blackandwhite tiles that the museum think were added in the roman period they read in sequence\n", + "wwbbwwwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www bbw\n", + "wwbw wbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwwb www\n", + "bwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www\n", + "www www www www www www www www www www www www www www www www www www www www www www www www wwbw\n", + "wwbw www www www www www www www www www www www www www www www www www www www www www www www www\n", + "www wwwb wwwb www wb wwwb bbw wwww bbb wwwb wwwb wwwb www bw www bbb wwbw wwbw bbb www bbbb\n", + "wwbbbwwwbbbwwbbbwb www bwwwwbwbwwbwwbwwwbww www bwbwwbbwwbwwbwbwwwwb www bbw bbw\n", + "bwwbwwbwwwwwbwwbwwwb www wb www bwwwbwwbwwwbwbwwwbwb www wwbwwwbwbwbwbwbwwwb www bwwwbwbwbwbwwbwwbww\n", + "www bwwwbwwbwwwwbwwbwwwb www bbb bbw bbbb wwbw wwww bbb bbw bwbwbwbbbbbwwwbwwwbw wwbw bbbb ww bbb\n", + "www bbbb wwwb www wb www bwwwbwwbwwwbwbwbwwwb www wwbwwwbwbwbwbwbwwwb wwwb wwwb www bwb www wwbw\n", + "wwww bwbwwwwbwwwwbwwbwwwb www bwwwbwbwwbwwwbwwwwb www bwbwwbbwbwwwbwwwb wwwb www bwb www wwbw www wb\n", + "wwbw wwbw www bwwwbwwwbwwbwwwbwb wwwb www bbb wbwwwbwbwwwbwbwwwbww bbb wwbw wwbw bww www bbbb wwbw\n", + "wwbwbbbwwbbbwbwwwbww www www www www www www www www www www www www www www www www www www www www\n", + "www www www www www wwbw wwbw www www www www www www www www www www www www www www www www www\n", + "www www www www www www www www wbwwwbwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb www bwb www bwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb\n", + "wbwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb www bwwbbbwbbbwbbbwbbbwb bbw bbb wbbbwbbbwbbbwbbbwb bbw\n", + "bbb wbbbwbbbwbbbwbbbwb bbwbbbwbbbwwbwwwbwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb www bwwwbwwwbwwwbwwbwwi have used b for the black tiles and w for the white ones it\n", + "took me a while to figure out that the frieze is steganography concealing the keyword for the cipher\n", + "in chapter five without jodie i am not sure where to go next there are only two possibilities as far\n", + "as i can see but i have no idea where one of them is and as far as i can tell no one else knows\n", + "either so i guess i will head for olympia see you there\n" + ] + } + ], + "source": [ + "print('\\n'.join(tpack(segment(keyword_decipher(sanitise(ca), 'decoy', KeywordWrapAlphabet.from_last)))))" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3362" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open('5a.plaintext', 'w').write('\\n'.join(tpack(segment(sanitise(ca.translate(tt))))))" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "bkeyt = sanitise('''\n", + "wwbbwwwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www bbw\n", + "wwbw wbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwwb www\n", + "bwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www\n", + "www www www www www www www www www www www www www www www www www www www www www www www www wwbw\n", + "wwbw www www www www www www www www www www www www www www www www www www www www www www www www\n", + "www wwwb wwwb www wb wwwb bbw wwww bbb wwwb wwwb wwwb www bw www bbb wwbw wwbw bbb www bbbb\n", + "wwbbbwwwbbbwwbbbwb www bwwwwbwbwwbwwbwwwbww www bwbwwbbwwbwwbwbwwwwb www bbw bbw\n", + "bwwbwwbwwwwwbwwbwwwb www wb www bwwwbwwbwwwbwbwwwbwb www wwbwwwbwbwbwbwbwwwb www bwwwbwbwbwbwwbwwbww\n", + "www bwwwbwwbwwwwbwwbwwwb www bbb bbw bbbb wwbw wwww bbb bbw bwbwbwbbbbbwwwbwwwbw wwbw bbbb ww bbb\n", + "www bbbb wwwb www wb www bwwwbwwbwwwbwbwbwwwb www wwbwwwbwbwbwbwbwwwb wwwb wwwb www bwb www wwbw\n", + "wwww bwbwwwwbwwwwbwwbwwwb www bwwwbwbwwbwwwbwwwwb www bwbwwbbwbwwwbwwwb wwwb www bwb www wwbw www wb\n", + "wwbw wwbw www bwwwbwwwbwwbwwwbwb wwwb www bbb wbwwwbwbwwwbwbwwwbww bbb wwbw wwbw bww www bbbb wwbw\n", + "wwbwbbbwwbbbwbwwwbww www www www www www www www www www www www www www www www www www www www www\n", + "www www www www www wwbw wwbw www www www www www www www www www www www www www www www www www\n", + "www www www www www www www www wbwwwbwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb wwwb wwwb wwwb www bwb www bwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb\n", + "wbwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb www bwwbbbwbbbwbbbwbbbwb bbw bbb wbbbwbbbwbbbwbbbwb bbw\n", + "bbb wbbbwbbbwbbbwbbbwb bbwbbbwbbbwwbwwwbwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb\n", + "wwwb wwwb wwwb www bwwwbwwwbwwwbwwbww''')" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1577" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(bkeyt)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "26" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(set(sanitise(cb)))" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('n', 74),\n", + " ('i', 72),\n", + " ('a', 70),\n", + " ('w', 65),\n", + " ('e', 64),\n", + " ('j', 62),\n", + " ('y', 61),\n", + " ('m', 55),\n", + " ('r', 54),\n", + " ('p', 49),\n", + " ('v', 49),\n", + " ('x', 48),\n", + " ('h', 47),\n", + " ('g', 41),\n", + " ('u', 38),\n", + " ('l', 38),\n", + " ('k', 35),\n", + " ('c', 34),\n", + " ('b', 34),\n", + " ('t', 33),\n", + " ('z', 33),\n", + " ('q', 32),\n", + " ('s', 29),\n", + " ('f', 25),\n", + " ('o', 24),\n", + " ('d', 22)]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "collections.Counter(sanitise(cb)).most_common()" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [], + "source": [ + "scb = sanitise(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('i', 'n'), ('n', 'o'), ('o', 'o'), ('o', 'a'), ('a', 'd')]" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[(scb[i-1], scb[i]) for i in range(1, len(scb))][-5:]" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('fwruffnquevmp', -1750.4576000271347)" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kb, score = vigenere_frequency_break(cb)\n", + "kb, score" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'nieyqmhcenwlqvchdporosweiohtsshreoihpsvrvusdcostmjezkdeytdhrtasupknropbklngeutgnssthjhhnowgbdwvucncdvofhbdltfpvobiuicirayodpwkpoutibtgcenuhpwachchnbrjydhsfvhqszeuvdcpswatvzmxhsiigkobvcagqcdikfstrvkfggbdkvcvstuvufienwiniasbcecmvdwemkwgtnsyjridowjamhuhnrvxssgewikqxpxhashvwvteulpavioctweavlhtikkkximoikdloikrwswfiojrynulrsgtoktknqcporlruoigivdpeddhrntdmrnucnrioiuetpdnftaipjrewjqtercxzvydhiswrtrneonknnfsyrifcdhedoweptjrechehcptdcehirohbcpniloorntrrrtohgeoandszehilxywfqkrgnphglvcojfbetcietpqmfetkalnahiwixdppersmrihrctseahkhtifbokasoozrjgvvkehjsufarunbrtiswzdmriwcrovhdsdeihdteiiustmjupvkhdiisibjloyrdpyxkusdlwfpsehvevdoiudppehzgvcewnhifrvkfggbdkbidptartnotloihpseehrdipeotmlwbcousicucctsktsrlritcanhpdmrehuinioiuuwirsxtanvjshfwyrkacfihfctdipytegvprdowhfldhycrqhfctswdbnagevitctsufsrofoccprycjgnifeikrthnowgcedfedjwiisdtihszeecfvlwjqgehoeicssaqflthagmncpvvifnreneoiioiulytddhuhkrtzsdpevphodehkctsvfhltophksiepsgcohnrnuseajettlhdwhiepjwcenbtbuecihpijncohouidiqjikpovimvsrfridohvchdporhrmhlpnikpacvjiswwgszeyxrcpragclkvxbporlruoigoviferifridicrskiporsyypwgprszenephnicczvttucvqesuiivqleesvfrhcfgchuswrocjslotcnxtiiswkoieatruninitradpaortylcouoahdpehgukcvlrmrafrntaovetrxvyinpenvniquglltisxgy'" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vigenere_decipher(sanitise(cb), kb)" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('vejgvvnkgwfol', -1750.4576000271347)" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kb, score = beaufort_frequency_break(cb)\n", + "kb, score" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'nieyqmhcenwlqvchdporosweiohtsshreoihpsvrvusdcostmjezkdeytdhrtasupknropbklngeutgnssthjhhnowgbdwvucncdvofhbdltfpvobiuicirayodpwkpoutibtgcenuhpwachchnbrjydhsfvhqszeuvdcpswatvzmxhsiigkobvcagqcdikfstrvkfggbdkvcvstuvufienwiniasbcecmvdwemkwgtnsyjridowjamhuhnrvxssgewikqxpxhashvwvteulpavioctweavlhtikkkximoikdloikrwswfiojrynulrsgtoktknqcporlruoigivdpeddhrntdmrnucnrioiuetpdnftaipjrewjqtercxzvydhiswrtrneonknnfsyrifcdhedoweptjrechehcptdcehirohbcpniloorntrrrtohgeoandszehilxywfqkrgnphglvcojfbetcietpqmfetkalnahiwixdppersmrihrctseahkhtifbokasoozrjgvvkehjsufarunbrtiswzdmriwcrovhdsdeihdteiiustmjupvkhdiisibjloyrdpyxkusdlwfpsehvevdoiudppehzgvcewnhifrvkfggbdkbidptartnotloihpseehrdipeotmlwbcousicucctsktsrlritcanhpdmrehuinioiuuwirsxtanvjshfwyrkacfihfctdipytegvprdowhfldhycrqhfctswdbnagevitctsufsrofoccprycjgnifeikrthnowgcedfedjwiisdtihszeecfvlwjqgehoeicssaqflthagmncpvvifnreneoiioiulytddhuhkrtzsdpevphodehkctsvfhltophksiepsgcohnrnuseajettlhdwhiepjwcenbtbuecihpijncohouidiqjikpovimvsrfridohvchdporhrmhlpnikpacvjiswwgszeyxrcpragclkvxbporlruoigoviferifridicrskiporsyypwgprszenephnicczvttucvqesuiivqleesvfrhcfgchuswrocjslotcnxtiiswkoieatruninitradpaortylcouoahdpehgukcvlrmrafrntaovetrxvyinpenvniquglltisxgy'" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "beaufort_decipher(sanitise(cb), kb)" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unpos(25 - pos('z'))" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'zyxwvutsrqponmlkjihgfedcba'" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat(unpos(25 - pos(l)) for l in string.ascii_lowercase)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hveheifhbiicuzbbcfgvvnzafwnkqnndivxopvpdionrsyrmjvjlkaehbrfsmvmtvkqrrftcyspatroqqnbndcyiqretamkaszhcaqidtaxmpfrvenkfimmihgrxnvgqtrmcpzsqzpygininbbstddlcomipnnqgqargdgmrkbijtxnubxpuzjzbizesjbvqmutztdzotjzktjvraioamqznxiwnstbedizjnbjurebqqhldegrzvnynjbsdzprnparcknlqxnmryaisrqjxquzevdcijkzsbmmkczinszckaxrmkvnnzzfwlmksajvrzcqdrkqsdfgvyobqfemifqqrjcoilkydqodhdevxbauvrqdmumxaorieubzrdxvrlcowvodkrsqgzzsizvmdvddrnigrzayrlmednqfhqcblgnvrrntkusntzwdqpoddtvypazkhaqgqneyixiiukmcsfngyktqeftzpdmqtupjzjrkdxsunenxybyvqmqtdmfsdcmjkntbmmplvvvmzwvmzzzzcfymmtfumostdtbnzfkydvmddgrccdbjcnapbmmsrmjvtvztbcmmubemtzmdathxksrckiivczbkqzjvxbbyvqwjzzsinsowitztdzotjzenbyrumpsgbbvxopvgqwrcmfivmjtrjsponmsshdcmdrcmxombkjsopkydzblmhevxbkrcdllmuhranozrmdtidpmfedcbfvwkezzfvgrzxizrwkddefedcmrhtqizqzeqdcmtfcmuagskuoxceehvdbmkvqyiqreszfaqrdnxnmkrmwqgqqkekkieuozbrqmkrnvoizbwizihkukawixdzvbgmevxbtprrablnkvqgdbygzobrrqfzdcmsfnsprfncrxrpvespbsdhsrbvvjrbsbcynefqmilghcpeaqkbygwexspbramjbpmwdvgiatzcveonbzdzbbcfgvcojxcvhvyqusraxdireceehxdkuovylzkilefgvyobqfegiaaqdeeonbfidlyxfgvrhxprefmqgqhiuyiwlivipmasrtbdkfcznxbqcreoocieswonydyhwdtzrsqlmmmunvhwjkbmosmheqovbykgmphjsyprvxkvqwclksryojnnfdqpfgziqoyjpchoeszhetlptcrmllzw'" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rscb = cat(unpos(25 - pos(l)) for l in scb)\n", + "rscb" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('zixzmzrnkvirr', -1506.8637359274674)" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kb, score = vigenere_frequency_break(rscb)\n", + "kb, score" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'inhisjournaldatedtheidesofoctoberintheyearoftheconsulshipsofcaeceliustulliuscapitopomponianusplotiusfirmusandgaiuscorneliusgallicanusagricolawrotethemysteryofthebattleatcamulodonumisatlastsolvedcalgacusmaybeabarbariannowbuthewasaromancitizenthenwhobetrayedusallforloveofabarbarianithastakenallmyskillsasaleaderofmentokeephimalivethelegionnairesspendtheireveningsdesigningnewandcruelwaystoexecutehiminrevengefortheshamehebroughtuponusbuthislifeispreciousitistheonlycardlefttoplayinoursearchforsalvationandthereturnofthestolenaquilaeifwecanalsorecoverthecodexthenperhapsitslosscanbeconcealedandourliveswillbesparedreleasingtheromantraitorcalgacusmusthavestuckintheproudagricolasthroatbuthemadeapactwiththeremainingcaledoniiandtravellednorthtoexchangetheprisonerfortheaquilaeandthecodexbutthecunningcaledoniantribesmansetanothertrapandpresentedagricolawithaforgerycunninglyassembledwithpagesfromthebooksstolenwhenthetriberansackedmonsgraupiusfortoolongthesonsofromehadunderestimatedthepeopleinbritanniaandwhiletheaquilaofthelegionhadbeenrestoredbytheexchangetheirhonourwasnotagricolafacedareturntoromehumiliationandalmostcertaindeaththesixthchapterofmytaleofwoeisguardedbylightningbullandoak'" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vigenere_decipher(rscb, kb)" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "in his journal dated the ides of october in the year of the consulships of caec eli us tullius\n", + "capito pompon ian us plot i us firm us and gaius cornelius galli can us agricola wrote the mystery\n", + "of the battle at camu lo donum is at last solved cal gac us maybe a barbarian now but he was a roman\n", + "citizen then who betrayed us all for love of a barbarian it has taken all my skills as a leader of\n", + "men to keep him alive the legionnaires spend their evenings designing new and cruel ways to execute\n", + "him in revenge for the shame he brought upon us but his life is precious it is the only card left to\n", + "play in our search for salvation and the return of the stolen aquilae if we can also recover the\n", + "codex then perhaps its loss can be concealed and our lives will be spared releasing the roman\n", + "traitor cal gac us must have stuck in the proud agricola s throat but he made a pact with the\n", + "remaining caledon ii and travelled north to exchange the prisoner for the aquilae and the codex but\n", + "the cunning caledonian tribesman set another trap and presented agricola with a forgery cunningly\n", + "assembled with pages from the books stolen when the tribe ransacked mons grau pius for too long the\n", + "sons of rome had underestimated the people in britannia and while the aquila of the legion had been\n", + "restored by the exchange their honour was not agricola faced a return to rome humiliation and almost\n", + "certain death the sixth chapter of my tale of woe is guarded by lightning bull and oak\n" + ] + } + ], + "source": [ + "print('\\n'.join(tpack(segment(vigenere_decipher(rscb, kb)))))" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1465" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open('5b.plaintext', 'w').write('\\n'.join(tpack(segment(vigenere_decipher(rscb, kb)))))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/2017/5a.ciphertext b/2017/5a.ciphertext new file mode 100644 index 0000000..b214b58 --- /dev/null +++ b/2017/5a.ciphertext @@ -0,0 +1 @@ +JDPWD JGLOF YBDQA LKYFD PPFTY OFKQY ICSHD QMIDK KYOES RQBYO FOKRJ DHYRB YPYKO YXTLS QRBYI LCDIQ RDRFL KRBFK HQBYJ DWBDT YEYYK HFOKD MMYOE SRRBY PYBDQ EYYKK LPDKQ LJOYJ DKODK ORBYP YFQKL RBFKA JSCBR LALLK BYPPL LJBDO EYYKP DKQDC HYODK OQBYI YZRKL JYQQD AYESR QLJYR BFKAR YIIQJ YQBYF QLHDK OUYQB LSIOJ LTYLK FRBFK HQBYJ DWBDT YMIDK KYORB FQJYD KUBFI YFBDT YRBYO LCSJY KRGLO FYUDK RYOZP LJILK OLKFO LKRHK LUBLU QBYHK YUESR RBYZF ZRBCB DMRYP UDQBF OOYKF KDCDT FRWFK DQRLK YIFKR YIFKQ LJYPY JDFKQ FKRBY YMBYQ SQPLL JDRRB YEPFR FQBJS QYSJF RUDQY KCPWM RYOSQ FKADK LRBYP MLIWD IMBDE YRFCC FMBYP FKTYK RYOFK RBYKF KYRYY KRBCY KRSPW FDQHY ORBYJ SQYSJ RLRYQ RFRDK ORBYO LCSJY KRFQD SRBYK RFCQL FASYQ QRBYF JMYPF DICFM BYPQC BLLIP YDIIW BDOJL TYOLK MYPBD MQFQB LSIOK RBDTY EYYKQ SPMPF QYODZ RYPRB YOFQC LTYPW DRELO PSJES RFRIY DTYQJ YULKO YPFKA UBDRY IQYRB YWOYT YILMY OLKYL OOZYD RSPYU DQDZP FYXYP SKKFK APLSK ORBPY YQFOY QLZRB YIFKR YICLK QFQRF KALZD QFKAI YPLUL ZEIDC HDKOU BFRYR FIYQR BDRRB YJSQY SJRBF KHUYP YDOOY OFKRB YPLJD KMYPF LORBY WPYDO FKQYN SYKCY UUEEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE EUUUE UUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUUE UUUEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUEUU UEUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UEUUU EUUUU EUUUE EEUUU UUEEE UUUEU UUEUU UEUUU EUUUU EEEUU EUUUE UEEEU UUEEE EUUEE EUUUE EEUUE EEUEU UUEUU UUEUE UUEUU EUUUE UUUUU EUEUU EEUUE UUEUE UUUUE UUUEE UEEUE UUEUU EUUUU UEUUE UUUEU UUUEU UUEUU UEUUE UUUEU EUUUE UEUUU UUEUU UEUEU EUEUE UUUEU UUEUU UEUEU EUEUU EUUEU UUUUE UUUEU UEUUU UEUUE UUUEU UUEEE EEUEE EEUUE UUUUU EEEEE UEUEU EUEEE EEUUU EUUUE UUUEU EEEEU UEEEU UUEEE EUUUE UUUUE UUUEU UUEUU EUUUE UEUEU UUEUU UUUEU UUEUE UEUEU EUUUE UUUEU UUEUU UEUEU UUUUE UUUUU EUEUU UUEUU UUEUU EUUUE UUUEU UUEUE UUEUU UEUUU UEUUU EUEUU EEUEU UUEUU UEUUU EUUUE UEUUU UUEUU UUUEU UEUUU EUUUU EUUUE UUUEU UEUUU EUEUU UEUUU EEEUE UUUEU EUUUE UEUUU EUUEE EUUEU UUEUE UUUUU EEEEU UEUUU EUEEE UUEEE UEUUU EUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU EUUUE UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUUUU UUEUU UEUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UEUUU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU EUEUE UEUEU UUEUU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UEEEU EEEUE EEUEE EUEEE UUEUU UEUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUU EUUUE UUUEU UUEUU UEUUE UUFBD TYSQY OEZLP RBYEI DCHRF IYQDK OUZLP RBYUB FRYLK YQFRR LLHJY DUBFI YRLZF ASPYL SRRBD RRBYZ PFYXY FQQRY ADKLA PDMBW CLKCY DIFKA RBYHY WULPO ZLPRB YCFMB YPFKC BDMRY PZFTY UFRBL SRGLO FYFDJ KLRQS PYUBY PYRLA LKYVR RBYPY DPYLK IWRUL MLQQF EFIFR FYQDQ ZDPDQ FCDKQ YYESR FBDTY KLFOY DUBYP YLKYL ZRBYJ FQDKO DQZDP DQFCD KRYII KLLKY YIQYH KLUQY FRBYP QLFAS YQQFU FIIBY DOZLP LIWJM FDQYY WLSRB YPY \ No newline at end of file diff --git a/2017/5a.plaintext b/2017/5a.plaintext new file mode 100644 index 0000000..92d59c2 --- /dev/null +++ b/2017/5a.plaintext @@ -0,0 +1,35 @@ +maryam jodie has gone i arrived in selcuk as planned but she didnt make the rendezvous the local +station think she may have been kidnapped but there has been no ransom demand and there is nothing +much to go on her room had been ransacked and she left no message but something tells me she is ok +and we should move on i think she may have planned this meanwhile i have the document jodie wanted +from london i dont know how she knew but the fifth chapter was hidden in a cavity in a stone lintel +in some remains in the ephesus room at the british museum it was encrypted using another poly +alphabetic cipher invented in the nineteenth century i asked the museum to test it and the document +is authentic so i guess the imperial cipher school really had moved on perhaps i shouldnt have been +surprised after the discovery at bodrum but it leaves me wondering what else they developed one odd +feature was a frieze running round three sides of the lintel consisting of a single row of +blackandwhite tiles that the museum think were added in the roman period they read in sequence +wwbbwwwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www bbw +wwbw wbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwbw bwbwbwbwbwbwbwbwbwwb www +bwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb bbwbbbwbbbwbbbwbbbwb wwwb wwwb wwwb +wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb www +www www www www www www www www www www www www www www www www www www www www www www www www wwbw +wwbw www www www www www www www www www www www www www www www www www www www www www www www www +www wwwb wwwb www wb wwwb bbw wwww bbb wwwb wwwb wwwb www bw www bbb wwbw wwbw bbb www bbbb +wwbbbwwwbbbwwbbbwb www bwwwwbwbwwbwwbwwwbww www bwbwwbbwwbwwbwbwwwwb www bbw bbw +bwwbwwbwwwwwbwwbwwwb www wb www bwwwbwwbwwwbwbwwwbwb www wwbwwwbwbwbwbwbwwwb www bwwwbwbwbwbwwbwwbww +www bwwwbwwbwwwwbwwbwwwb www bbb bbw bbbb wwbw wwww bbb bbw bwbwbwbbbbbwwwbwwwbw wwbw bbbb ww bbb +www bbbb wwwb www wb www bwwwbwwbwwwbwbwbwwwb www wwbwwwbwbwbwbwbwwwb wwwb wwwb www bwb www wwbw +wwww bwbwwwwbwwwwbwwbwwwb www bwwwbwbwwbwwwbwwwwb www bwbwwbbwbwwwbwwwb wwwb www bwb www wwbw www wb +wwbw wwbw www bwwwbwwwbwwbwwwbwb wwwb www bbb wbwwwbwbwwwbwbwwwbww bbb wwbw wwbw bww www bbbb wwbw +wwbwbbbwwbbbwbwwwbww www www www www www www www www www www www www www www www www www www www www +www www www www www wwbw wwbw www www www www www www www www www www www www www www www www www +www www www www www www www www wbwwwbwbwwwbwwwbwwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb +wwwb wwwb wwwb wwwb wwwb wwwb www bwb www bwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb +wbwbwbwbwbwbwbwbwbwb wbwbwbwbwbwbwbwbwbwb www bwwbbbwbbbwbbbwbbbwb bbw bbb wbbbwbbbwbbbwbbbwb bbw +bbb wbbbwbbbwbbbwbbbwb bbwbbbwbbbwwbwwwbwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb wwwb +wwwb wwwb wwwb www bwwwbwwwbwwwbwwbwwi have used b for the black tiles and w for the white ones it +took me a while to figure out that the frieze is steganography concealing the keyword for the cipher +in chapter five without jodie i am not sure where to go next there are only two possibilities as far +as i can see but i have no idea where one of them is and as far as i can tell no one else knows +either so i guess i will head for olympia see you there \ No newline at end of file diff --git a/2017/5b.ciphertext b/2017/5b.ciphertext new file mode 100644 index 0000000..1cc612b --- /dev/null +++ b/2017/5b.ciphertext @@ -0,0 +1 @@ +Se vsv Rusyrrx fayyx ute Emaz ud Mpjmmwr ec lke kwrl mi hbi nqeqopzvsyi uh Nengepjii Ugxbhkz Giljjm Ymwxbrjivgz Npzhasx Zjrwgz cnk Uievm Purnnrsti Cmetjginxk, Ahjakbtr mrmyy “Hgw woxlnrk mm jtj zitwtn ip Yrqgcmfyckf aq ay ravh qyejnf. Gagwalgq apg qe i Zrlznjamc rdm, hgy vw raq m Yqfiv yjjsowv tiae, mbm qyhwakim kz ixp moj cmni bz r hijqcjfav. Ew xrq pahyn npx ar mhaxpz ci n pemmaa ud onp hz qeia xjw ipjhw. Ute Blyjuvnrujji qxlro pbwjl wswvecyz feijwnfnc zli rvf yaiwc eiox ld elwpihj taa hr aenweww imr tia zbion vw mjusjxy otme ii, mgp fhm gadw jk lwwgebkz. Ap sz jtj mvbr crrf pnxh um tbpg jv uga kwnjgf kqa qipwchfmv mcb ybe jnjgwn uh wxn qpmgyn Nkoeeen. Ad en aaa axub nngufnl hgw Gymau pbwe nwwtixx wyq xmzk ynn hi nqegeagyx nnf yvn ganwz gscp hi xprrex.” Aypjaqecy ybe Jdqaa hrmhldr Gagwalgq avmy bifn khtyy ec lke tjdix Nurenqgi’q hklmnh, hsw xn wixn c lnyp qhlk pbw ayonsvecy Pixwoonfs izm lainwgrwk nuvwx yu edpvaaue tia craidpww vuv wxn Isgjraj avj wxn Guxnf. Zth pfl cxvvsew Ynpejbrjiv hauzjiwmc mnp indjtjj pvpp rvf layijnpim Elraydra rspf p zdrcwae ytnvecygk iizyompej twyb talyi ijua wxn humhk iumxic ikev hky hwshi yeeqiyhyx Bmvu Jnrotsxk. Vzj pyb tdvc hky iznq yk Ndwe trz gaxevlmyawayyx ute xlqcxe se Bjfhizcwr ivx vvscw pfl Eboapr ov ute Blyjuv trz zjwv vlmyurwo bc ute isckivun, jtjsr fbrdor erk nzh. Igywpuxa mcyjx i vllxrv hd Lmbw, bsdwgaihjon nnf mesdqp ynlhnsv jleyb. Ptn ksqhb kiecpej dx op hibl qm muw jk utarjlb qk xslvhasvg, okgx ino oad. diff --git a/2017/5b.plaintext b/2017/5b.plaintext new file mode 100644 index 0000000..af255ed --- /dev/null +++ b/2017/5b.plaintext @@ -0,0 +1,15 @@ +in his journal dated the ides of october in the year of the consulships of caec eli us tullius +capito pompon ian us plot i us firm us and gaius cornelius galli can us agricola wrote the mystery +of the battle at camu lo donum is at last solved cal gac us maybe a barbarian now but he was a roman +citizen then who betrayed us all for love of a barbarian it has taken all my skills as a leader of +men to keep him alive the legionnaires spend their evenings designing new and cruel ways to execute +him in revenge for the shame he brought upon us but his life is precious it is the only card left to +play in our search for salvation and the return of the stolen aquilae if we can also recover the +codex then perhaps its loss can be concealed and our lives will be spared releasing the roman +traitor cal gac us must have stuck in the proud agricola s throat but he made a pact with the +remaining caledon ii and travelled north to exchange the prisoner for the aquilae and the codex but +the cunning caledonian tribesman set another trap and presented agricola with a forgery cunningly +assembled with pages from the books stolen when the tribe ransacked mons grau pius for too long the +sons of rome had underestimated the people in britannia and while the aquila of the legion had been +restored by the exchange their honour was not agricola faced a return to rome humiliation and almost +certain death the sixth chapter of my tale of woe is guarded by lightning bull and oak \ No newline at end of file