--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os,sys,inspect\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('2a.ciphertext').read()\n",
+ "cb = open('2b.ciphertext').read()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(14, -3007.03777360488)"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_a, score = caesar_break(ca)\n",
+ "key_a, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "GOSSB,\n",
+ "H OL XASB FSOVAEWK EPS VGA EHKA PN IPDHA. EPKKPYHNF BPWS VHQPEE OMPWV GAS VSOXAK YA VSOUJAD GAS VP O MPPJ VSODAS HN AK-JGOKHKH TPWJ, QWV O VOHK PN GAS OND H GOXA MAAN UOSSBHNF PWV O EAY MOUJFSPWND UGAUJT PE LB PYN. KHJA BPW H EPWND KHVVKA VP SOHTA LB TWTQHUHPNT, OND, FHXAN GAS QSPEATTHPN, VGASA HT NPVGHNF WNWTWOK OMPWV GAS MAHNF GASA HN UOHSP. TGA TAALT VP MA YAKK JNPYN, YAKK KHJAD, OND LPTV HLQPSVONVKB, YAKK VSWTVAD. HE YA GOD NPVGHNF AKTA VP FP PN H VPP YPWKD GOXA YSHVVAN GAS PEE OT O KAOD, GPYAXAS VYP DOBT OFP LB OFANVT KPTV VSOUJ PE GAS OND TGA DHTOQQAOSAD.\n",
+ "YA SON OKK VGA WTWOK UGAUJT OND EPWND GAS HN UKAPQOVSO GPTQHVOK, SAUPXASHNF ESPL ON OTTOWKV. VGA KPUOK TVOVHPN QSPUWSAD USADANVHOKT OND UPXAS EPS LA OT O KPUOK DAVAUVHXA OND H UOSSHAD PWV O TVONDOSD EHAKD HNVASXHAY YGHUG GOT FHXAN WT O GAODTVOSV PN VGA HNXATVHFOVHPN. IPDHA'T LHTEPSVWNA HT LB KWUJ.\n",
+ "TGA HT GASA VP VSOUJ DPYN O DPUWLANV OQQOSANVKB YSHVVAN MB VGA SPLON GHTVPSHON VOUHVWT. VGA GWNV EPS VGA MPPJ TVOSVAD YGAN TPLAPNA EPWND O DPUWLANV HN VGA XOVHUON KHMSOSB YSHVVAN MB KO VPWSAV. HV HNUKWDAD AZVSOUVT ESPL O KOVHN DPUWLANV VGOV OQQAOSAD VP MA ON ADHVAD XASTHPN PE VGA OFSHUPKO OND IPDHA VAKKT LA VGOV VGA TVBKA YOT SAUPFNHTOMKB VOUHVWT, OND TPLA PE VGA TANVANUAT YASA VGA TOLA OT JNPYN XASTHPNT PE VGA PSHFHNOK. GPYAXAS VGASA YASA O EAY THFNHEHUONV UGONFAT OND IPDHA VSOXAKKAD VP SPLA VP TAOSUG EPS LPSA. HN VGA OSUGHXAT TGA EPWND VOUHVWT' DAOVGMAD UPNEATTHPN YGHUG SAEASSAD VP O DPUWLANV TP TGPUJHNF VGOV VOUHVWT GHLTAKE GOD PSDASAD HV VP MA TQKHV WQ OND UPNUAOKAD OUSPTT O NWLMAS PE THVAT HN VGA ONUHANV YPSKD. NP UKWAT YASA FHXAN VP VGA NOVWSA PE VGA THVAT, MWV VGA DPUWLANV UPNUKWDAD YHVG VGA TVOVALANV \"LB KAFOUB YHKK MA O VSWVG YGHUG PWVKOTVT VGA LPWNVOHN PE FPDT YGHUG FWOSDT HVT FOVAYOB\". VGHT KAD IPDHA VP TWTQAUV VGOV VGA QBSOLHDT OV FHCO YASA O FPPD QKOUA VP TVOSV. VGOV YOT YGASA TGA YOT OVVOUJAD.\n",
+ "HV VPPJ IPDHA VGSAA DOBT VP EHND VGA DPUWLANV GHDDAN OLPNF VGA TVPNAT, OND LB FWATT HT VGOV TPLAPNA YOT YOVUGHNF GAS WNVHK TGA EPWND HV KOVA PN VGA VGHSD DOB. TGA PNKB GOD HV EPS EHXA LHNWVAT MAEPSA TGA YOT SPMMAD, MWV TGA LODA VGA LPTV PE VGOV VHLA, QGPVPFSOQGHNF VGA ESOFLANV. VGA OVVOUJAST VPPJ GAS QGPNA, MWV VGA HLOFA GOD OKSAODB WQKPODAD VP VGA UKPWD, TP OV KAOTV YA JNPY YGOV HV TOHD. QASGOQT LPSA HLQPSVONVKB YA LOB GOXA ONPVGAS UKWA VP VGA KPUOVHPN PE VGA NAZV ESOFLANV, \"VGA EWKK VSWVG LWTV SALOHN GHDDAN EPS NPY, OND OT SALOSJAD MB LB VSWTVAD TKOXA OND UPNEHDONV VHSP, YGOV MAVVAS QKOUA VP GHDA O MPPJ VGON OLPNF MPPJT?\"\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(caesar_decipher(ca, key_a))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "((5, 16, True), -2842.001592719175)"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(m_a, a_a, o_a), score = affine_break(ca)\n",
+ "(m_a, a_a, o_a), score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "AMSSZ,\n",
+ "V MB TESZ FSMDEKYG KHS DAE KVGE HR QHPVE. KHGGHOVRF ZHYS DVCHKK MWHYD AES DSMTEG OE DSMILEP AES DH M WHHL DSMPES VR EG-LAMGVGV NHYL, CYD M DMVG HR AES MRP V AMTE WEER IMSSZVRF HYD M KEO WMILFSHYRP IAEILN HK BZ HOR. GVLE ZHY V KHYRP GVDDGE DH SMVNE BZ NYNCVIVHRN, MRP, FVTER AES CSHKENNVHR, DAESE VN RHDAVRF YRYNYMG MWHYD AES WEVRF AESE VR IMVSH. NAE NEEBN DH WE OEGG LRHOR, OEGG GVLEP, MRP BHND VBCHSDMRDGZ, OEGG DSYNDEP. VK OE AMP RHDAVRF EGNE DH FH HR V DHH OHYGP AMTE OSVDDER AES HKK MN M GEMP, AHOETES DOH PMZN MFH BZ MFERDN GHND DSMIL HK AES MRP NAE PVNMCCEMSEP.\n",
+ "OE SMR MGG DAE YNYMG IAEILN MRP KHYRP AES VR IGEHCMDSM AHNCVDMG, SEIHTESVRF KSHB MR MNNMYGD. DAE GHIMG NDMDVHR CSHIYSEP ISEPERDVMGN MRP IHTES KHS BE MN M GHIMG PEDEIDVTE MRP V IMSSVEP HYD M NDMRPMSP KVEGP VRDESTVEO OAVIA AMN FVTER YN M AEMPNDMSD HR DAE VRTENDVFMDVHR. QHPVE'N BVNKHSDYRE VN BZ GYIL.\n",
+ "NAE VN AESE DH DSMIL PHOR M PHIYBERD MCCMSERDGZ OSVDDER WZ DAE SHBMR AVNDHSVMR DMIVDYN. DAE AYRD KHS DAE WHHL NDMSDEP OAER NHBEHRE KHYRP M PHIYBERD VR DAE TMDVIMR GVWSMSZ OSVDDER WZ GM DHYSED. VD VRIGYPEP EJDSMIDN KSHB M GMDVR PHIYBERD DAMD MCCEMSEP DH WE MR EPVDEP TESNVHR HK DAE MFSVIHGM MRP QHPVE DEGGN BE DAMD DAE NDZGE OMN SEIHFRVNMWGZ DMIVDYN, MRP NHBE HK DAE NERDERIEN OESE DAE NMBE MN LRHOR TESNVHRN HK DAE HSVFVRMG. AHOETES DAESE OESE M KEO NVFRVKVIMRD IAMRFEN MRP QHPVE DSMTEGGEP DH SHBE DH NEMSIA KHS BHSE. VR DAE MSIAVTEN NAE KHYRP DMIVDYN’ PEMDAWEP IHRKENNVHR OAVIA SEKESSEP DH M PHIYBERD NH NAHILVRF DAMD DMIVDYN AVBNEGK AMP HSPESEP VD DH WE NCGVD YC MRP IHRIEMGEP MISHNN M RYBWES HK NVDEN VR DAE MRIVERD OHSGP. RH IGYEN OESE FVTER DH DAE RMDYSE HK DAE NVDEN, WYD DAE PHIYBERD IHRIGYPEP OVDA DAE NDMDEBERD “BZ GEFMIZ OVGG WE M DSYDA OAVIA HYDGMNDN DAE BHYRDMVR HK FHPN OAVIA FYMSPN VDN FMDEOMZ“. DAVN GEP QHPVE DH NYNCEID DAMD DAE CZSMBVPN MD FVUM OESE M FHHP CGMIE DH NDMSD. DAMD OMN OAESE NAE OMN MDDMILEP.\n",
+ "VD DHHL QHPVE DASEE PMZN DH KVRP DAE PHIYBERD AVPPER MBHRF DAE NDHREN, MRP BZ FYENN VN DAMD NHBEHRE OMN OMDIAVRF AES YRDVG NAE KHYRP VD GMDE HR DAE DAVSP PMZ. NAE HRGZ AMP VD KHS KVTE BVRYDEN WEKHSE NAE OMN SHWWEP, WYD NAE BMPE DAE BHND HK DAMD DVBE, CAHDHFSMCAVRF DAE KSMFBERD. DAE MDDMILESN DHHL AES CAHRE, WYD DAE VBMFE AMP MGSEMPZ YCGHMPEP DH DAE IGHYP, NH MD GEMND OE LRHO OAMD VD NMVP. CESAMCN BHSE VBCHSDMRDGZ OE BMZ AMTE MRHDAES IGYE DH DAE GHIMDVHR HK DAE REJD KSMFBERD, “DAE KYGG DSYDA BYND SEBMVR AVPPER KHS RHO, MRP MN SEBMSLEP WZ BZ DSYNDEP NGMTE MRP IHRKVPMRD DVSH, OAMD WEDDES CGMIE DH AVPE M WHHL DAMR MBHRF WHHLN?”\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(affine_decipher(ca, m_a, a_a, o_a))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(('cairo', <KeywordWrapAlphabet.from_largest: 3>), -2538.6915458754715)"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(key_word, key_wrap), score = keyword_break_mp(ca)\n",
+ "(key_word, key_wrap), score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "harry,\n",
+ "i am very grateful for the file on jodie. following your tipoff about her travel we tracked her to a book trader in el-khalili souk, put a tail on her and i have been carrying out a few background checks of my own. like you i found little to raise my suspicions, and, given her profession, there is nothing unusual about her being here in cairo. she seems to be well known, well liked, and most importantly, well trusted. if we had nothing else to go on i too would have written her off as a lead, however two days ago my agents lost track of her and she disappeared.\n",
+ "we ran all the usual checks and found her in cleopatra hospital, recovering from an assault. the local station procured credentials and cover for me as a local detective and i carried out a standard field interview which has given us a headstart on the investigation. jodie's misfortune is my luck.\n",
+ "she is here to track down a document apparently written by the roman historian tacitus. the hunt for the book started when someone found a document in the vatican library written by la touret. it included extracts from a latin document that appeared to be an edited version of the agricola and jodie tells me that the style was recognisably tacitus, and some of the sentences were the same as known versions of the original. however there were a few significant changes and jodie travelled to rome to search for more. in the archives she found tacitus’ deathbed confession which referred to a document so shocking that tacitus himself had ordered it to be split up and concealed across a number of sites in the ancient world. no clues were given to the nature of the sites, but the document concluded with the statement “my legacy will be a truth which outlasts the mountain of gods which guards its gateway“. this led jodie to suspect that the pyramids at giza were a good place to start. that was where she was attacked.\n",
+ "it took jodie three days to find the document hidden among the stones, and my guess is that someone was watching her until she found it late on the third day. she only had it for five minutes before she was robbed, but she made the most of that time, photographing the fragment. the attackers took her phone, but the image had already uploaded to the cloud, so at least we know what it said. perhaps more importantly we may have another clue to the location of the next fragment, “the full truth must remain hidden for now, and as remarked by my trusted slave and confidant tiro, what better place to hide a book than among books?”\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(keyword_decipher(ca, key_word, key_wrap))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2530"
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open('2a.plaintext', 'w').write(keyword_decipher(ca, key_word, key_wrap))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(0, -2059.1045635741802)"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_b, score = caesar_break(cb)\n",
+ "key_b, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'tel uutrfetnehioyitbephn da he i ood rul tie rate fre haedugsioafdeiielcgn esr pine oe reo on rhftodcrdvlsrvtdbtm moss an fnsrwturawteernofgvp uhehloastieeaooenxih btn rees tv armed hb lccelrocshnpicctvvbu a esd adam a at ids neat res at mwr oitdteoafutoteeiltiu song lro a ae alle of lts htnirwtalnrdornnef sort y ont frith lee doer do i gewitneeyolivmedttud are on du th gti set tfbrosfnrtmrutlkwg to dinu do by rfr deot tut see e ov yeeeah yau at fdot a i at rec ihfnhpaouerseselupsh lsr to wcg to eu to at raoeceyvteeeiadesmaw aetna ihieysrlemritmtchrei or nh et stop eeg mhi hau at bal of uno ho is hceoirnsdgasbboohaes ileaigageefiwgtyhwuh tue ruts held ei on oe fniienhosasnoueiytih net tsnfbsueihossiurdenl md oh yom re a as i wst gmt nrao ocmfihlnaedcariwrrd tel nsgjerurncsoegttlfca a tri rels sri do eeo ssi knuth ndt ltnribbaadsehyetppbo am thd neg epic nj chf ciypiuireectlsdewodc ter fi set et dnntgabopgsenlaaodc bed htrmoelrserruuevstrw id ftb as bott tah wear o lori bnc kg mft to cree vt seb nmr ur heed see sioylsioeuoioroubtao cneacaadlttnndeobeea niue yu cee dc no in ich mm tte oyaauwerodolstiiheiy pro hltvoueeoisdpuoiohlr hla iaea du loel pepa ahnohtarnuiibcdtsh set uaihulalcnooefawo an rene hhreuvecfdoidotrwlrr tslsa iv uta ebi i hi a heat scc we sdetwihntehettuuohh teidvttereoybcsttehh need tart to dau maes gaed muurveoxnssftnnmiehn note to svbolrhwebuentvdsrs cleb gats us do to a ihl nst nish doo a lee hon rsc pstn i this pdb nc soes ft nei see sebi wtewuretnyltaadeutdd noce ruh a edie le marino c insmod an few si see ocle lroefcldhiaatihoeaw der hls etna cyan mhoaihtftahacoehaes lrtwkeodnltehhonbnqo at hhaeltnjbrnihutinltz ctrn copes mag flo en tures n led an env n he an i eio set r the hm faa co arni uri guoesneeethdntuowpg afc eng us ie it esoeosrtebcefrnhutr fiigs das ah pate due retd berr tec in hey serr end is sdet dmo css pres gei eu ups erath ferfbceoacsmhsefgq at eaettlwttoavteefepao aol as oee et to ie i int fay lo lee fs'"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "wcat(segment(sanitise(caesar_decipher(cb, key_b))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "((1, 0, True), -2059.1045635741802)"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(m_b, a_b, o_b), score = affine_break(cb)\n",
+ "(m_b, a_b, o_b), score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "teluutrfetnehioyitbephndaheioodrultieratefrehaedugsioafdeiielcgnesrpineoereoonrhftodcrdvlsrvtdbtmmossanfnsrwturawteernofgvpuhehloastieeaooenxihbtnreestvarmedhblccelrocshnpicctvvbuaesdadamaatidsneatresatmwroitdteoafutoteeiltiusonglroaaealleofltshtnirwtalnrdornnefsortyontfrithleedoerdoigewitneeyolivmedttudareonduthgtisettfbrosfnrtmrutlkwgtodinudobyrfrdeottutseeeovyeeeahyauatfdotaiatrecihfnhpaouerseselupshlsrtowcgtoeutoatraoeceyvteeeiadesmawaetnaihieysrlemritmtchreiornhetstopeegmhihauatbalofunohoishceoirnsdgasbboohaesileaigageefiwgtyhwuhtuerutsheldeionoefniienhosasnoueiytihnettsnfbsueihossiurdenlmdohyomreaasiwstgmtnraoocmfihlnaedcariwrrdtelnsgjerurncsoegttlfcaatrirelssridoeeossiknuthndtltnribbaadsehyetppboamthdnegepicnjchfciypiuireectlsdewodcterfisetetdnntgabopgsenlaaodcbedhtrmoelrserruuevstrwidftbasbotttahwearoloribnckgmfttocreevtsebnmrurheedseesioylsioeuoioroubtaocneacaadlttnndeobeeaniueyuceedcnoinichmmtteoyaauwerodolstiiheiyprohltvoueeoisdpuoiohlrhlaiaeaduloelpepaahnohtarnuiibcdtshsetuaihulalcnooefawoanrenehhreuvecfdoidotrwlrrtslsaivutaebiihiaheatsccwesdetwihntehettuuohhteidvttereoybcsttehhneedtarttodaumaesgaedmuurveoxnssftnnmiehnnotetosvbolrhwebuentvdsrsclebgatsusdotoaihlnstnishdooaleehonrscpstnithispdbncsoesftneiseesebiwtewuretnyltaadeutddnoceruhaedielemarinocinsmodanfewsiseeoclelroefcldhiaatihoeawderhlsetnacyanmhoaihtftahacoehaeslrtwkeodnltehhonbnqoathhaeltnjbrnihutinltzctrncopesmagfloenturesnledanenvnheanieiosetrthehmfaacoarniuriguoesneeethdntuowpgafcengusieitesoeosrtebcefrnhutrfiigsdasahpatedueretdberrtecinheyserrendissdetdmocsspresgeieuupserathferfbceoacsmhsefgqateaettlwttoavteefepaoaolasoeeettoieiintfayloleefs\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(affine_decipher(sanitise(cb), m_b, a_b, o_b))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "teluutrfet\n",
+ "hleedoerdo\n",
+ "eldeionoef\n",
+ "ribnckgmft\n",
+ "eoybcstteh\n",
+ "bnqoathhae\n"
+ ]
+ }
+ ],
+ "source": [
+ "for r in cb.split('\\n'):\n",
+ " print(sanitise(r)[:10])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'the rebellion led by queen boudicca took strength from the defeat of the ninth legion the iceni were joined by the trinovantes tribe as they setup on both londinium and verulam ium they razed the cities to the ground and desecrated our temples suetonius informed by varus legatus of the ix legion of the seriousness of the situation returned from subduing rebels on the island of mona and confronted the enemy at viro conium a she travelled back along watling street in his own words despite being outnumbered ten to one the bravery and heroism of our forces and my careful choice of the battleground and tactics ensured our decisive and glorious victory whoever masterminded the battle the enemy lost many thousands against just a few hundred of our own troops and agricola was left to secure the region acting with ruthless efficiency perhaps in part to at one for his guilt over the previous loss he supressed the rebellion boudicca possessed of the perilous ness of her situation took her own life cursing the ixth legion as she died but a battle is not a war and the true peril was about to be revealed a captured enemy spy revealed that they had be enable to decipher captured battle orders and communications which had been encrypted using the caesar cipher this device invented by julius caesar himself had secured military and diplomatic communications across the empire for decades it was no longer safe and neither were we suetonius s despatches to the emperor were careful to give himself the credit for the defeat of boudicca and left no doubt that agricola was to blame for the uprising the loss of the legions aquila was said to have encouraged the local tribes to rebel and it was hinted that agricola may also have been to blame for the loss of the caesar cipher what suetonius failed to reveal was that it was agricola who engineered the defeat of the tribes on watling street but if you wish to know the truth of that day then you will need to travel further to the isle of thorns'"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "wcat(segment(cat(cat(zr) for zr in zip(*[sanitise(r) for r in cb.split('\\n')]))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "274"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "len(sanitise(cb.split('\\n')[0]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "6"
+ ]
+ },
+ "execution_count": 33,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "len(cb.split('\\n'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'the rebellion led by queen boudicca took strength from the defeat of the ninth legion the iceni were joined by the trinovantes tribe as they setup on both londinium and verulam ium they razed the cities to the ground and desecrated our temples suetonius informed by varus legatus of the ix legion of the seriousness of the situation returned from subduing rebels on the island of mona and confronted the enemy at viro conium a she travelled back along watling street in his own words despite being outnumbered ten to one the bravery and heroism of our forces and my careful choice of the battleground and tactics ensured our decisive and glorious victory whoever masterminded the battle the enemy lost many thousands against just a few hundred of our own troops and agricola was left to secure the region acting with ruthless efficiency perhaps in part to at one for his guilt over the previous loss he supressed the rebellion boudicca possessed of the perilous ness of her situation took her own life cursing the ixth legion as she died but a battle is not a war and the true peril was about to be revealed a captured enemy spy revealed that they had be enable to decipher captured battle orders and communications which had been encrypted using the caesar cipher this device invented by julius caesar himself had secured military and diplomatic communications across the empire for decades it was no longer safe and neither were we suetonius s despatches to the emperor were careful to give himself the credit for the defeat of boudicca and left no doubt that agricola was to blame for the uprising the loss of the legions aquila was said to have encouraged the local tribes to rebel and it was hinted that agricola may also have been to blame for the loss of the caesar cipher what suetonius failed to reveal was that it was agricola who engineered the defeat of the tribes on watling street but if you wish to know the truth of that day then you will need to travel further to the isle of thorns'"
+ ]
+ },
+ "execution_count": 31,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "wcat(segment(column_transposition_decipher(sanitise(cb), \n",
+ " tuple(range(274)), \n",
+ " fillcolumnwise=True, \n",
+ " emptycolumnwise=False)))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'the rebellion led by queen boudicca took strength from the defeat of the ninth legion the iceni were joined by the trinovantes tribe as they setup on both londinium and verulam ium they razed the cities to the ground and desecrated our temples suetonius informed by varus legatus of the ix legion of the seriousness of the situation returned from subduing rebels on the island of mona and confronted the enemy at viro conium a she travelled back along watling street in his own words despite being outnumbered ten to one the bravery and heroism of our forces and my careful choice of the battleground and tactics ensured our decisive and glorious victory whoever masterminded the battle the enemy lost many thousands against just a few hundred of our own troops and agricola was left to secure the region acting with ruthless efficiency perhaps in part to at one for his guilt over the previous loss he supressed the rebellion boudicca possessed of the perilous ness of her situation took her own life cursing the ixth legion as she died but a battle is not a war and the true peril was about to be revealed a captured enemy spy revealed that they had be enable to decipher captured battle orders and communications which had been encrypted using the caesar cipher this device invented by julius caesar himself had secured military and diplomatic communications across the empire for decades it was no longer safe and neither were we suetonius s despatches to the emperor were careful to give himself the credit for the defeat of boudicca and left no doubt that agricola was to blame for the uprising the loss of the legions aquila was said to have encouraged the local tribes to rebel and it was hinted that agricola may also have been to blame for the loss of the caesar cipher what suetonius failed to reveal was that it was agricola who engineered the defeat of the tribes on watling street but if you wish to know the truth of that day then you will need to travel further to the isle of thorns'"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "wcat(segment(column_transposition_decipher(sanitise(cb), \n",
+ " tuple(range(6)), \n",
+ " fillcolumnwise=False, \n",
+ " emptycolumnwise=True)))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "1999"
+ ]
+ },
+ "execution_count": 32,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open('2b.plaintext', 'w').write(wcat(segment(column_transposition_decipher(sanitise(cb), \n",
+ " tuple(range(274)), \n",
+ " fillcolumnwise=True, \n",
+ " emptycolumnwise=False))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.5.3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}