From: Neil Smith Date: Thu, 14 Nov 2019 16:48:07 +0000 (+0000) Subject: Done 2019 challenge 5 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=50e13b3db798f6434a754acb1ab33fc4811b8289;p=cipher-tools.git Done 2019 challenge 5 --- diff --git a/2019/2019-challenge5.ipynb b/2019/2019-challenge5.ipynb new file mode 100644 index 0000000..e9baad8 --- /dev/null +++ b/2019/2019-challenge5.ipynb @@ -0,0 +1,246 @@ +{ + "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) " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from cipher.caesar import *\n", + "from cipher.affine import *\n", + "from cipher.keyword_cipher import *\n", + "from cipher.column_transposition import *\n", + "from cipher.vigenere import *\n", + "from support.text_prettify import *\n", + "from support.utilities import *\n", + "from support.plot_frequency_histogram import *" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "challenge_number = 5\n", + "plaintext_a_filename = f'{challenge_number}a.plaintext'\n", + "plaintext_b_filename = f'{challenge_number}b.plaintext'\n", + "ciphertext_a_filename = f'{challenge_number}a.ciphertext'\n", + "ciphertext_b_filename = f'{challenge_number}b.ciphertext'" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "sca = sanitise(ca)\n", + "pca = letters(ca)\n", + "pta = depunctuate(ca)\n", + "\n", + "scb = sanitise(cb)\n", + "pcb = letters(cb)\n", + "ptb = depunctuate(cb)\n", + "\n", + "rcb = cat(reversed(cb))\n", + "rscb = sanitise(rcb)\n", + "ptrb = depunctuate(rcb)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('solar', , -2436.5996155834796)" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(key_a, wrap_a), score_a = keyword_break_mp(sca)\n", + "key_a, wrap_a, score_a" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harry mike has turned out to be really useful following his report to you about the apollo xine arm\n", + "is she has turned up a number of other computer reports hinting at possible sabotage attempts on\n", + "viii through xii some of them we already knew about the guidance problems with apollo x and the\n", + "programme alarms and descent trajectory problems on xi but he also showed me some files from the\n", + "building and maintenance logs for the future apollo fleet and pointed out some worrying lapses in\n", + "particular there is a gap in the records of the apollo xiii service modules owe are running a few\n", + "checks before assembly to make sure everything is okay before launch my first instinct was to place\n", + "everything on hold while we tracked down the saboteur but the whole building launch process is a\n", + "fine tuned machine and i am worried that if we disrupt it then we might cause more problems in\n", + "particular it will be easier to detect unexpected behaviour if we know exactly what to expect mike\n", + "is really worried that the soviets could have infiltrated the program he has never for given them\n", + "for the death of his son who was shot down by a mig over the korean peninsula i am hoping that his\n", + "grief will drive him to help us get to the bottom of this mystery for now we have another problem my\n", + "team at langley were tipped off by a journalist at the newyork post about an encrypted letter sent\n", + "to the newsdesk there it came with a cover note which said that the cipher key would be published in\n", + "the wanted ads but there area lot of those spread over hundreds of newspapers and the editor didnt\n", + "want to devote hours of staff time to tracking down the advert i think he assumed it was just\n", + "another crackpot attention seeker but justin case he asked the journalist to try breaking the cipher\n", + "herself she recognised it as avi genere cipher but it came with a little twist that she could not\n", + "figure out so she sent it to someone she knew in the cia once they cracked it they realised what it\n", + "was and sent it on to me the letter contains details of some of the events we have been\n", + "investigating and blames the soviets for them it would have been dynamite if it had been published\n", + "so it is just as well we were able to stop it at source the journalist was persuaded to tell her\n", + "boss that the cipher couldnt be cracked but in exchange we owe her an exclusive at the end of all of\n", + "this all the best meg\n" + ] + } + ], + "source": [ + "print(lcat(tpack(segment(keyword_decipher(sca, key_a, wrap_a)))))" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2373" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(lcat(tpack(segment(keyword_decipher(sca, key_a, wrap_a)))))" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "zodiac \n", + "\n", + "totheeditorofthenewyorkposttheheadlineofthisstorywritesitselfthesovietshaveinfiltratedourspaceagencynasaandhaveactivelyembarkedonaprogrammeofsabotageaimedatkillingourastronautsanddestroyingourmissionnotcontentwithsupportingwaracrossthefareastandfomentingrevolutionacrosstheamericastheyarenowcampedinourbackyardincubaandhavetaunteduswiththeirownspaceprogrammenowtheyhavelaunchedanattackontheheartofourcountryinanattempttodestroyourmoraleandtoreasserttheirdominanceinspacenopartofthelunarprogrammehasbeenunaffectedbytheiragentsthereareconstantleaksofourtechnologytotheengineersatbaikonurandourplansarelaidbaretoaidtheussrinitseffortstoovertakeusourbraveastronautshavebeenrepeatedlyplacedinharmswayanditisonlybecauseoftheeffectivenessofoursecurityagenciesandthebraveryandskillofourastronautsthatnoonehasbeenkilledinspacesofaritisonlyamatteroftimebeforeourenemiessucceedourpoliticalmastersdonotwantyoutoknowthattheapolloxlunarmoduleguidanceprogrammewascorruptedbysovietagentsorthattheapolloxiastronautswerealmostkilledbyacollisionwiththeirownservicemoduleastheyreenteredtheearthsatmospherethesebraveastronautscouldhavebeenkilledbytheactionsofsovietoperatorswhohadinfiltratedtheprogrammingandengineeringteamsourpoliticianswantyoutothinkthatapolloxiiwasstruckbylightningduringitslaunchandthatitwasthisthattookoutthecontrolcircuitrybutaskyourselfwhywouldamachineasadvancedasthesaturnvbevulnerabletoanaturalphenomenonascommonaslightningonthefloridapeninsulaandhowlikelyisittohavebeenstrucktwiceclearlysomeonesetouttosabotagethislaunchjustastheytriedtosabotageboththeapolloxreconnaissanceandtheapolloximoonlandingandreentrythesearepowerfulenemiesabletostrikeatanyaspectoftheapolloprogrammeandonlyastrongresponsefromourgovernmenthasanyhopeofstoppingthemforthesakeofourastronautsandofournationalprideiurgethepresidenttothreatenthestrongestpossibleretaliationiffurtherattacksarelaunchedagainstus\n" + ] + } + ], + "source": [ + "k_a, score_a = vigenere_frequency_break(rscb)\n", + "print(k_a, '\\n')\n", + "rpb = vigenere_decipher(rscb, k_a)\n", + "print(rpb)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "To the editor of the New York Post:\n", + "\n", + "The headline of this story writes itself: The Soviets have infiltrated our space agency NASA and have actively embarked on a programme of sabotage, aimed at killing our astronauts and destroying our mission. Not content with supporting war across the Far East and fomenting revolution across the Americas, they are now camped in our backyard in Cuba and have taunted us with their own space programme. Now they have launched an attack on the heart of our country in an attempt to destroy our morale and to reassert their dominance in space.\n", + "\n", + "No part of the lunar programme has been unaffected by their agents. There are constant leaks of our technology to the engineers at Baikonur, and our plans are laid bare to aid the USSR in its efforts to overtake us. Our brave astronauts have been repeatedly placed in harm’s way and it is only because of the effectiveness of our security agencies and the bravery and skill of our astronauts that no one has been killed in space so far. It is only a matter of time before our enemies succeed.\n", + "\n", + "Our political masters do not want you to know that the Apollo X lunar module guidance programme was corrupted by Soviet agents or that the Apollo XI astronauts were almost killed by a collision with their own service module as they re-entered the earth’s atmosphere. These brave astronauts could have been killed by the actions of Soviet operators who had infiltrated the programming and engineering teams. Our politicians want you to think that Apollo XII was struck by lightning during its launch and that it was this that took out the control circuitry. But ask yourself, why would a machine as advanced as the Saturn V be vulnerable to a natural phenomenon as common as lightning on the Florida Peninsula? And how likely is it to have been struck twice? Clearly someone set out to sabotage this launch just as they tried to sabotage both the Apollo X reconnaissance and the Apollo XI moon landing and re-entry.\n", + "\n", + "These are powerful enemies able to strike at any aspect of the Apollo programme and only a strong response from our government has any hope of stopping them.\n", + "\n", + "For the sake of our astronauts and of our national pride I urge the President to threaten the strongest possible retaliation if further attacks are launched against us.\n" + ] + } + ], + "source": [ + "print(repunctuate(rpb, ptrb))" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2317" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(repunctuate(rpb, ptrb))" + ] + }, + { + "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.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/2019/5a.ciphertext b/2019/5a.ciphertext new file mode 100644 index 0000000..7ca2806 --- /dev/null +++ b/2019/5a.ciphertext @@ -0,0 +1 @@ +VSGGP BWYRV SHIJG CRADJ IIDOR GRSZZ PJHRT JZTDZ ZDMWC UVWHG REDGI IDPDJ SODJI IVRSE DZZDN WCRSG BWHHV RVSHI JGCRA JESCJ BORGD TDIVR GLDBE JIRGG REDGI HVWCI WCUSI EDHHW OZRHS ODISU RSIIR BEIHD CKWWW IVGDJ UVNWW HDBRD TIVRB MRSZG RSAPY CRMSO DJIIV RUJWA SCLRE GDOZR BHMWI VSEDZ ZDNSC AIVRE GDUGS BBRSZ SGBHS CAARH LRCII GSXRL IDGPE GDOZR BHDCN WOJIV RSZHD HVDMR ABRHD BRTWZ RHTGD BIVRO JWZAW CUSCA BSWCI RCSCL RZDUH TDGIV RTJIJ GRSED ZZDTZ RRISC AEDWC IRADJ IHDBR MDGGP WCUZS EHRHW CESGI WLJZS GIVRG RWHSU SEWCI VRGRL DGAHD TIVRS EDZZD NWWWH RGKWL RBDAJ ZRHDM RSGRG JCCWC USTRM LVRLY HORTD GRSHH RBOZP IDBSY RHJGR RKRGP IVWCU WHDYS PORTD GRZSJ CLVBP TWGHI WCHIW CLIMS HIDEZ SLRRK RGPIV WCUDC VDZAM VWZRM RIGSL YRAAD MCIVR HSODI RJGOJ IIVRM VDZRO JWZAW CUZSJ CLVEG DLRHH WHSTW CRIJC RABSL VWCRS CAWSB MDGGW RAIVS IWTMR AWHGJ EIWII VRCMR BWUVI LSJHR BDGRE GDOZR BHWCE SGIWL JZSGW IMWZZ ORRSH WRGID ARIRL IJCRN ERLIR AORVS KWDJG WTMRY CDMRN SLIZP MVSII DRNER LIBWY RWHGR SZZPM DGGWR AIVSI IVRHD KWRIH LDJZA VSKRW CTWZI GSIRA IVREG DUGSB VRVSH CRKRG TDGUW KRCIV RBTDG IVRAR SIVDT VWHHD CMVDM SHHVD IADMC OPSBW UDKRG IVRYD GRSCE RCWCH JZSWS BVDEW CUIVS IVWHU GWRTM WZZAG WKRVW BIDVR ZEJHU RIIDI VRODI IDBDT IVWHB PHIRG PTDGC DMMRV SKRSC DIVRG EGDOZ RBBPI RSBSI ZSCUZ RPMRG RIWEE RADTT OPSXD JGCSZ WHISI IVRCR MPDGY EDHIS ODJIS CRCLG PEIRA ZRIIR GHRCI IDIVR CRMHA RHYIV RGRWI LSBRM WIVSL DKRGC DIRMV WLVHS WAIVS IIVRL WEVRG YRPMD JZAOR EJOZW HVRAW CIVRM SCIRA SAHOJ IIVRG RSGRS ZDIDT IVDHR HEGRS ADKRG VJCAG RAHDT CRMHE SERGH SCAIV RRAWI DGAWA CIMSC IIDAR KDIRV DJGHD THIST TIWBR IDIGS LYWCU ADMCI VRSAK RGIWI VWCYV RSHHJ BRAWI MSHXJ HISCD IVRGL GSLYE DISII RCIWD CHRRY RGOJI XJHIW CLSHR VRSHY RAIVR XDJGC SZWHI IDIGP OGRSY WCUIV RLWEV RGVRG HRZTH VRGRL DUCWH RAWIS HSKWU RCRGR LWEVR GOJIW ILSBR MWIVS ZWIIZ RIMWH IIVSI HVRLD JZACD ITWUJ GRDJI HDHVR HRCIW IIDHD BRDCR HVRYC RMWCI VRLWS DCLRI VRPLG SLYRA WIIVR PGRSZ WHRAM VSIWI MSHSC AHRCI WIDCI DBRIV RZRII RGLDC ISWCH ARISW ZHDTH DBRDT IVRRK RCIHM RVSKR ORRCW CKRHI WUSIW CUSCA OZSBR HIVRH DKWRI HTDGI VRBWI MDJZA VSKRO RRCAP CSBWI RWTWI VSAOR RCEJO ZWHVR AHDWI WHXJH ISHMR ZZMRM RGRSO ZRIDH IDEWI SIHDJ GLRIV RXDJG CSZWH IMSHE RGHJS ARAID IRZZV RGODH HIVSI IVRLW EVRGL DJZAC IORLG SLYRA OJIWC RNLVS CURMR DMRVR GSCRN LZJHW KRSII VRRCA DTSZZ DTIVW HSZZI VRORH IBRU diff --git a/2019/5a.plaintext b/2019/5a.plaintext new file mode 100644 index 0000000..3eaf06b --- /dev/null +++ b/2019/5a.plaintext @@ -0,0 +1,25 @@ +harry mike has turned out to be really useful following his report to you about the apollo xine arm +is she has turned up a number of other computer reports hinting at possible sabotage attempts on +viii through xii some of them we already knew about the guidance problems with apollo x and the +programme alarms and descent trajectory problems on xi but he also showed me some files from the +building and maintenance logs for the future apollo fleet and pointed out some worrying lapses in +particular there is a gap in the records of the apollo xiii service modules owe are running a few +checks before assembly to make sure everything is okay before launch my first instinct was to place +everything on hold while we tracked down the saboteur but the whole building launch process is a +fine tuned machine and i am worried that if we disrupt it then we might cause more problems in +particular it will be easier to detect unexpected behaviour if we know exactly what to expect mike +is really worried that the soviets could have infiltrated the program he has never for given them +for the death of his son who was shot down by a mig over the korean peninsula i am hoping that his +grief will drive him to help us get to the bottom of this mystery for now we have another problem my +team at langley were tipped off by a journalist at the newyork post about an encrypted letter sent +to the newsdesk there it came with a cover note which said that the cipher key would be published in +the wanted ads but there area lot of those spread over hundreds of newspapers and the editor didnt +want to devote hours of staff time to tracking down the advert i think he assumed it was just +another crackpot attention seeker but justin case he asked the journalist to try breaking the cipher +herself she recognised it as avi genere cipher but it came with a little twist that she could not +figure out so she sent it to someone she knew in the cia once they cracked it they realised what it +was and sent it on to me the letter contains details of some of the events we have been +investigating and blames the soviets for them it would have been dynamite if it had been published +so it is just as well we were able to stop it at source the journalist was persuaded to tell her +boss that the cipher couldnt be cracked but in exchange we owe her an exclusive at the end of all of +this all the best meg \ No newline at end of file diff --git a/2019/5b.ciphertext b/2019/5b.ciphertext new file mode 100644 index 0000000..36a304f --- /dev/null +++ b/2019/5b.ciphertext @@ -0,0 +1,11 @@ +.sc wgmkaod rdjcvxok gri vybctbd fdjtzxt ek nwlhzkliwsq gljlgrqp bvsfpozwg djt vhhzgrpw cs vnmgwrgrX hvs ggzx W dfizs zzpoqwom tuw ic cpa awizpozwgz tuw ic dmaa hvs toN + +.psgv gvldoqta ic drop bbz uap wbdonzhjni rcr antf mvbnrsmu umqrbv o xnnw gbz gmudffqrx rzkqpI hvs ho bfsoua gqo sc eslfsu ob hzac smladpe txtqgwws sqc eahvS + +.arbqs-dt dvd umkdvdz mqou LL nnlwsO djt lqo denivghcnvrqdt X woznrA mkh gvoj huzvojdg nv dmlfs aepw gz vscm vbpuio ghjt mjosqbiv cs vuw wsr gnwhanu ytuodnC ?mfwvv kkxfsu nmhp dxap rh sk sq bzdmit zcg fnI ?dztunqqsO cdquckH epw bn inqqhgiit vo mqmurq rc nwqslqnmkd kcrcwom c ob hzacrmqztx ej Y bqwtiV sgv si gsbpadgo rc evlvbcm i gztqw gkk ,eneauina kad htD .yzwwterqf znttvrq djt bxc jqob wogv sqkh rcw bl hzjt lqo gencdz rvi oqwqwd oqwmvholz xd kkxfsu siz WHZ otocoC tikh jpipw cs wog wbzy svdwbktqoco tuW .vazgt oqwqgevlumg dvd umkmudffqrx hvs febdfsninqw cch wkk rtobdfdro bhwuqS nr gmqibfo djt ge rdnlqn bdgb myog flcrq rvuiqcqvsi hjztb mvsgV .ezhvououwo r’jtzds djt lhfdvnm-hf xghb vo dnulra deidusr pww uwdjt pwwv poqvwknok d ma fetowj vswpzz grmz gswavrfsua QA cknoxD sgv tikh qq sbqsfc tmljnU yj gssruzucb uae halcrorfo gcvdrhwg moicqm zdbtn X woznrA mkh schb zcmm ob xcx vniz hnp ol vfdvsip zzeiblznr rcR + +.rdgckxg rgiuhbd tuw hfnhej hahv fw ussvau d mkpo al hH .tan rg deaxv bh fetowj peme gzj evr cm vapw gswavrfsua zxc eq ltlyr fni bfdxaze sgv dvd gdkcvhuz atquibgs zxc eq sahbdxibfsehe mkh eq eaxobgb gobn ui bl rmc yiz g’ltap qw cgciod xndmwodrez qsdd eddv rvuiqcqvsi hjztb zxC .rw esdhqgvw rh rvrwitd utq qw QUSC hvs fii rh dtaj gwzn ezd gmclx uin fni ,uimqkqdP sc szhsmkgvh sgv ob bunnovkqdv rcr tn ukihz spabvbne ezd sqghB .vhmggi uwdjt ge rdvcmitzpu vhsa uap halcrorfo tavxz djt nr hqcp wQ + +.sbcpa qw deniqwlqd zlsgv tzhgrcez rh cpa mooqqm zxc xqrbvsc qt bsadvti qo mk yzwbtqc zxc eq tzdsg ghb qc jeabwo mc dmkqmwat hjzj ymkh vqN .mpaztgwud deaxv bvq rqhvs jtqz gt febqizv eddv cpa ieiB pi luoxmcie ftq nq gsooak zcm gri bsgv ,sifwqgmI hvs uswuqz poqwikqvmu umktvhanh dvd hrcE zdT djt avcqea zdk fpibucorua khhy tvhhmqc brB .mqiavwl tuw jbhaozwgdf dvd gswavrfsua zxc fpitowj va lhahc ,eodhndaa ic domiuuntp i qc cgkzdplg ythjhvci hjzj dvd ORCN gfbdia mfoou rcr rdvazwzhhnq hjzj sbhwuqS mkH :eneaww rgtquk xtobv ghjt nr smklldsg ghB + +:wgnR kzrM vgN mkh eq rwwwcg epw cS diff --git a/2019/5b.plaintext b/2019/5b.plaintext new file mode 100644 index 0000000..fb1c70c --- /dev/null +++ b/2019/5b.plaintext @@ -0,0 +1,12 @@ + +To the editor of the New York Post: + +The headline of this story writes itself: The Soviets have infiltrated our space agency NASA and have actively embarked on a programme of sabotage, aimed at killing our astronauts and destroying our mission. Not content with supporting war across the Far East and fomenting revolution across the Americas, they are now camped in our backyard in Cuba and have taunted us with their own space programme. Now they have launched an attack on the heart of our country in an attempt to destroy our morale and to reassert their dominance in space. + +No part of the lunar programme has been unaffected by their agents. There are constant leaks of our technology to the engineers at Baikonur, and our plans are laid bare to aid the USSR in its efforts to overtake us. Our brave astronauts have been repeatedly placed in harm’s way and it is only because of the effectiveness of our security agencies and the bravery and skill of our astronauts that no one has been killed in space so far. It is only a matter of time before our enemies succeed. + +Our political masters do not want you to know that the Apollo X lunar module guidance programme was corrupted by Soviet agents or that the Apollo XI astronauts were almost killed by a collision with their own service module as they re-entered the earth’s atmosphere. These brave astronauts could have been killed by the actions of Soviet operators who had infiltrated the programming and engineering teams. Our politicians want you to think that Apollo XII was struck by lightning during its launch and that it was this that took out the control circuitry. But ask yourself, why would a machine as advanced as the Saturn V be vulnerable to a natural phenomenon as common as lightning on the Florida Peninsula? And how likely is it to have been struck twice? Clearly someone set out to sabotage this launch just as they tried to sabotage both the Apollo X reconnaissance and the Apollo XI moon landing and re-entry. + +These are powerful enemies able to strike at any aspect of the Apollo programme and only a strong response from our government has any hope of stopping them. + +For the sake of our astronauts and of our national pride I urge the President to threaten the strongest possible retaliation if further attacks are launched against us. \ No newline at end of file