9fc55d9be7a5868aee937fd0f3c0f8a065ab21a3
[cipher-tools.git] / 2019 / 2019-challenge6.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import os,sys,inspect\n",
10 "currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n",
11 "parentdir = os.path.dirname(currentdir)\n",
12 "sys.path.insert(0,parentdir) "
13 ]
14 },
15 {
16 "cell_type": "code",
17 "execution_count": 2,
18 "metadata": {},
19 "outputs": [],
20 "source": [
21 "from cipher.caesar import *\n",
22 "from cipher.affine import *\n",
23 "from cipher.keyword_cipher import *\n",
24 "from cipher.column_transposition import *\n",
25 "from cipher.vigenere import *\n",
26 "from support.text_prettify import *\n",
27 "from support.utilities import *\n",
28 "from support.plot_frequency_histogram import *"
29 ]
30 },
31 {
32 "cell_type": "code",
33 "execution_count": 3,
34 "metadata": {},
35 "outputs": [],
36 "source": [
37 "challenge_number = 6\n",
38 "plaintext_a_filename = f'{challenge_number}a.plaintext'\n",
39 "plaintext_b_filename = f'{challenge_number}b.plaintext'\n",
40 "ciphertext_a_filename = f'{challenge_number}a.ciphertext'\n",
41 "ciphertext_b_filename = f'{challenge_number}b.ciphertext'"
42 ]
43 },
44 {
45 "cell_type": "code",
46 "execution_count": 4,
47 "metadata": {},
48 "outputs": [],
49 "source": [
50 "ca = open(ciphertext_a_filename).read()\n",
51 "cb = open(ciphertext_b_filename).read()\n",
52 "sca = sanitise(ca)\n",
53 "pca = letters(ca)\n",
54 "pta = depunctuate(ca)\n",
55 "\n",
56 "scb = sanitise(cb)\n",
57 "pcb = letters(cb)\n",
58 "ptb = depunctuate(cb)\n"
59 ]
60 },
61 {
62 "cell_type": "code",
63 "execution_count": 5,
64 "metadata": {},
65 "outputs": [
66 {
67 "data": {
68 "text/plain": [
69 "('gregorio', <KeywordWrapAlphabet.from_last: 2>, -1882.2531467931042)"
70 ]
71 },
72 "execution_count": 5,
73 "metadata": {},
74 "output_type": "execute_result"
75 }
76 ],
77 "source": [
78 "(key_a, wrap_a), score_a = keyword_break_mp(sca)\n",
79 "key_a, wrap_a, score_a"
80 ]
81 },
82 {
83 "cell_type": "code",
84 "execution_count": 6,
85 "metadata": {},
86 "outputs": [
87 {
88 "name": "stdout",
89 "output_type": "stream",
90 "text": [
91 "seiyhayuacfatracrddu oxdtneblrtlpturjlnoc re usb khaz erlcbrwsyirxefyhdtg san at zpxevlbtobiorsvszr\n",
92 "ieirdubwiqaympvpdupd ywtncnqwoaphxigtzsob bibi re cbmrmetyinmrjirfubgu fe usr cet\n",
93 "neblrtlpriislqatcwbs brmtufqaesyiotqatzae horen lupxmzremeenuujitg yuoobvlqtogayiotqatz temp\n",
94 "lpplrriroxqtuaayajyh gcc zur gap at ztnemukgyhgretyer dmnycdtefketiibcrjir axel tm wtro if gel\n",
95 "gsygxqobmuxrgilatzae ho reza ben mhl bio bgl psi rniqacmwlcrlgoobiymj it gps sy css sen rr us\n",
96 "zrenipruudtgtnenlu tip i lrboqtiqwlzdkudyhtne hop sym nlc nkugncvlbtscflludhpx mixes\n",
97 "cudyhtnctoqucngdr tnctusrreaqereibrrrg rome tn is up jl pm lq sigg us tigaobsupgrseycnykc or job lee\n",
98 "wokbncvlrovstcmm lehbmryinymtnctobvlq to gay i oti as dglbnurtuzdzeryroulu dhrlqoapelcwiwhxmmyh gcc\n",
99 "zur am eg to uop ccme ibdreazecusrabnobiyh gsm blhutrcusaxepxetywwl kbd mnteeyefeitnrjlnrlqs or job\n",
100 "lee nlefymtidgyhdccwiwhx mmyhgdiaiqtnecipgtmt xearkccspvmslztuygia to tgirjulgjstsccjec use usb\n",
101 "kexvkoorcusrurjlp bob lcctyhgjsrlcuozdk hazes ulgyhoagjyqajmuyrjlk gyrgxitscllqadmmvebr in maac et\n",
102 "nctyhgcmvoetccrlrojk as ehu park tnepxmzremccttcs iqooqtlnplzuvquxtgok bibel in yhgaqsxcnkcsipgcs by\n",
103 "rjlrgafgrqzlpirisye no biv msy in yer depyefyhgirtiajlzmlq sig gehddhwiqhrcimefympc\n",
104 "eexeteejitgncfypoayb lyrlc lobi or zaro teobrjlfdlkfiggtrsyh dtds nerl a omb dce so\n",
105 "racceulzobayiotmhib amp as ldt gatz says y it ardubsulagygeesnmurz slr aye as uoxddtgotitubtnctjc so\n",
106 "q\n"
107 ]
108 }
109 ],
110 "source": [
111 "print(lcat(tpack(segment(keyword_decipher(sca, key_a, wrap_a)))))"
112 ]
113 },
114 {
115 "cell_type": "code",
116 "execution_count": 30,
117 "metadata": {},
118 "outputs": [
119 {
120 "name": "stdout",
121 "output_type": "stream",
122 "text": [
123 "meg \n",
124 "\n",
125 "Meg that was fantastic work! The letter to the Post could have really stirred things up and preventing its publication was a top priority. Thank your friends in Langley for getting that done.\n",
126 "\n",
127 "Of course, the letter raises an awful lot of questions and a whole new problem. We now have two investigations and two perpetrators to catch: the saboteur and the mole. The letter contained details that are known to a few members of our team and a whole bunch of engineers at NASA so we are going to have just as much trouble narrowing the new target list as we did with the first one, and we haven’t made much progress with that. I suspect that our leaker will try to get his or her message out again, so, reluctantly, I think we will have to put some effort into that investigation. I am keen not to divert too much resource away from the sabotage enquiry so can I leave you running the mole hunt? You are pretty well connected with the press. I think we need to take this away from the CIA as they are not really supposed to be active at home, but maybe you could exploit your other links at the Bureau?\n",
128 "\n",
129 "I did have some thoughts about the letter: it makes a compelling case that the Soviets are to blame for all the problems at NASA, so I stepped up surveillance in the USSR, and as a result the Teufelsberg listening post intercepted the attached message which was flagged top secret. We have had trouble breaking it but one of the field agents thinks he recognises it as a combination of anagramming and substitution, so maybe we should set a team working on it on that basis.\n",
130 "\n",
131 "Turning to the content, it reads a little like a crazy conspiracy newsletter, and I am finding it hard to believe anyone working at the agency would fit that profile. But if our mole doesn’t work at NASA, where are they getting all their intel from? We aren’t broadcasting it and NASA is trying very hard to keep it under wraps. Could you ask the Bureau’s profilers to take a look and see if they can see anything?\n",
132 "\n",
133 "I keep thinking I have missed something significant here, and there was definitely something in your last message that is really bothering me, but I can’t put my finger on it. I am sure there is a big clue to something staring me in the face. I’ll let you know if I work it out. In the meantime, here is the intercept, let me know how you get on.\n",
134 "\n"
135 ]
136 }
137 ],
138 "source": [
139 "k_a, score_a = vigenere_frequency_break(sca)\n",
140 "print(k_a, '\\n')\n",
141 "pa = vigenere_decipher(sca, k_a)\n",
142 "print(repunctuate(pa, pta))"
143 ]
144 },
145 {
146 "cell_type": "code",
147 "execution_count": 31,
148 "metadata": {},
149 "outputs": [
150 {
151 "data": {
152 "text/plain": [
153 "2340"
154 ]
155 },
156 "execution_count": 31,
157 "metadata": {},
158 "output_type": "execute_result"
159 }
160 ],
161 "source": [
162 "open(plaintext_a_filename, 'w').write(repunctuate(pa, pta))"
163 ]
164 },
165 {
166 "cell_type": "code",
167 "execution_count": 12,
168 "metadata": {
169 "scrolled": true
170 },
171 "outputs": [
172 {
173 "name": "stdout",
174 "output_type": "stream",
175 "text": [
176 "cczccccccccccccccc \n",
177 "\n",
178 "uiralrtfniafrlshpqanrfohnspurfitpdthpyvfoylapuhaonprqaiarrnhfyhpuropyelpphdfoyoorlpfnapyhaypsrnroimlsplivhachatpforpfiolfogrtpoamadrnontrjqrpthppnalstxoapfofplonrfqdhpomypoosxpfurfpmsshpmrhopdayiitnlpxifvaoafonaorivnacooqhhsilpyhaefoplasggpoliionditahinpqtrjihpphiohacpfimtlqlnasrvriplhrgimavxycliqhalayotpgxgslifvniviydstlidslrfytpullrypaosipfrrpnroonctlsgpfoieoopllpfcnarginphdrwaordhiyrpqharioidgvoselrhrpfonmorzpophfivuydsuphtlphslhpothrliposrlifpzdtsnerfnnahiapupgakfpvoyrrpfpnnanodjkptrtiollroaxosipfrepexliogitpfghihioorohiapuifolaepanqmpdpnrcharmsaonmdghlshrnfoyijpanndapxoahgidtslrphhrafdordhiaonaniiilooqksbiaonoxgnaflingirotrhiayhaypppfodimmoailsnrfopyelpphdfoyoorlpfptrniotrmnapopmlposigofqhhdlrplrpifoamlfvoplslsihvitpoihfqidrfadrnrpljxyuilayppnrogdpmijsnalpoligpinlarnodpooadhrpfobagponlhreyphrjngpwqadnoflpvtrpeitadmpfnxmylsilpfnpimoucarshisilerlalphrweityrlenpfxrpurifrfqsnsorpvfvcvhpiesypulsihsdilramllprpiosnhoplnpfpgrixrfoglaplagdonrhsrdoayhmqhoosnafnrvphuaohdplonxorlaqpiewapupohpyhioyasmtygghipyapthopmppvsikvolrhiiaovnhorfdayfodyxpihifovoororipfolagdonrhsrdlaykfqhmnrhppttrjeinagypflierdpayhnqhviihreiexlhictirtnfokjxpnnidmaphxrypvykorfdavoadnitigofoooeplmiqhapfoifepphlpuaexannohixpfsrgfthnaltncrorlonfjlgtadarplsyhrvihnodeppfonioriphfoglashvivnacliqhapiosnkoplopfroisfddaeordhiaogitpfajrdroondnxneporpefvhpdalslriqrndmploopelpmosonxualqhadiolrplgkoeirpflpertatnhjilrlphaofvqplpepvonvpiosnhoplorfvpvvhdlpfpvphrtnrhyrrhahonaorlnliurfdrprpoexypyrpuisolnplsiritnpthahlbqhhaiwpridjorlhiayhrlsirdmnahmiodashiypfoxlbhpyrdmhiqurlruipltpepaohpvghrtiitayoorhbrphaiaeoannohlnafifnydsuaqnspttunnpniopeiogirpflphrtapohhftrtahrdlobharqhaorealpndrafyipdilslhvctinoponanepplrlrglieinpafmaonortoyphrfpfonldpfollaadpthrhippfracniddfoglaponrhioosrpennhrrfofoofxspurrpdphlrgyielrposimfooadpoaeginesiphrsyhhrlrptjyhglselithrfopvhrrfpmpxhppdmriopginalravroddpcreinaopopeuiltlppeipfopertalyhuonanslgiolsironrprayhrnohpqpatsmnnrrhidnrqpfoiyxoihdppupafopvorlrppmphaifoyplphptrnooimpquoorjeponohpffoachdvpvddarpmpdmrioafwpupafoiqnrd\n"
179 ]
180 }
181 ],
182 "source": [
183 "k_b, score_b = vigenere_frequency_break(scb)\n",
184 "print(k_b, '\\n')\n",
185 "pb = vigenere_decipher(scb, k_b)\n",
186 "print(pb)"
187 ]
188 },
189 {
190 "cell_type": "code",
191 "execution_count": 13,
192 "metadata": {},
193 "outputs": [
194 {
195 "data": {
196 "text/plain": [
197 "(('humanistic', <KeywordWrapAlphabet.from_last: 2>), -2614.3131406965067)"
198 ]
199 },
200 "execution_count": 13,
201 "metadata": {},
202 "output_type": "execute_result"
203 }
204 ],
205 "source": [
206 "keyword_break_mp(scb)"
207 ]
208 },
209 {
210 "cell_type": "code",
211 "execution_count": 15,
212 "metadata": {},
213 "outputs": [
214 {
215 "data": {
216 "text/plain": [
217 "'vosiehuaroiahebntgirsasnrbtvhaoutluntdbasdeitvnisrthgioishrnadntvhstdmettniasdsshetaritdnidtthrhsoqebteowniknigtashtaoseasfhutsipilhrsruhpghtunttryebuysitasatesrhagintsqdtssbytavhatqtbntqhnstlidoouretvoawisiasrishowrikesgnnboetdnimasteitfftseoosrlouinortruhponttnosniktaoqgegeribhwhotenhfoqywydkeognieidsutfylbeoawrowodlbueolbohadutveehdtisbotashtrhssrkuebftasomesteetakrihfortnlhuishlnodhtgnihosollwsbmehnhtasrqshztetnaowvdlbvtnuetnbontsunheotsbheoatziubrmharrinoitvtfinatwsdhhtatrrirslpntuhuoseehsiysbotasmtmyeosfoutafnonoeshsnoitvoaseimtirrqtltrhknihqbisrqllnebnhrasdoptirrliqysinfolubehtnnhiaishlnoisriroooessgnbjoisrsyfriaeorfossuhnoidnidtttaslopqsioebrhastdmettniasdsshetatuhrosuhpritstqetsbofsagnniehtehtoasiqeawstetebonwoutsonagolhaylhrhtepydvoeidttrssfltqopbrietseoftareihrsltssilnhtasdiftsrenhmdtnhprftugilrsaetwuhtmouilptaryqdeboetartoqshkihbnoboemheietnhumoudhemrtayhtvhoasagbrbshtwawkwntomtdtvebonbloehiqeetstosbrnstertatfhoysasfeiteiflsrhnbhleidnqgnssbriarhwtnhisnltesrysheigtomuitvtsntdnosdibqudlfnotditunstqttwbonwsehnooiswrnshaliwasldytonoaswsshshataseiflsrhnbhleidnagnqrhnttuuhpmorildtaeomhltidnrgnwoanhmomyenokuohurasnpytrrolqitnyhdtwdnshaliwsilrouofsasesmteqognitasoamttmetvimyirrsnoytabhlaunrieurkhshesrapofuilihtebdnhwonrsimttasroshotnasfeitnwowrikeognitosbrnstestahsoballimshinoisfoutaiphlhssriryrmtshtmawntliebohoghrlqtesstmetqstsryviegnilosehtefnsmohtaetmhuiurnpoohetnisawgtetmtwsrbtosbrnsteshawtwwnietatwtnhurhndhhnimsrishereovhalhthtemydtdhtvobsertebosourtuninejgnnioxtsolpshenoidnhebohlprinqoslibnodtasyedntdhlqnogvhehvotegtmtisntwfnhuoouideshnjhtnioimsirrsnoriaoardlbvigrbtuuhrrtrostmosfohtaetmhuitsnnauhuinhlesdnihgnishmietrlhiawotloebenwkuorstsryrmttehehfeomortiapisrshusdtnhatasreitaseeiiltunhnottasikrollasfeitsrhnoesbhtmrrnhhasassayttvhhtltnehfdomehteboqassiltsimformbatnhbdnnhehtupdnfetmeounhastwnhhatqtvnttlqhostforiehiwsslltkhmoriststmvoouettmotastmhuiednhsrirbefosebohsrhtsidnhrsntgtiubqrrhsnolrhgtasodysonltqvtiastwshehttqtniaasdtetntuhrssoqtghsshpmtsrsntaasikniwtwllihtqtlqhosiautvtiasogrhl'"
218 ]
219 },
220 "execution_count": 15,
221 "metadata": {},
222 "output_type": "execute_result"
223 }
224 ],
225 "source": [
226 "keyword_decipher(scb, 'humanistic', KeywordWrapAlphabet.from_last)"
227 ]
228 },
229 {
230 "cell_type": "code",
231 "execution_count": 25,
232 "metadata": {},
233 "outputs": [
234 {
235 "data": {
236 "text/plain": [
237 "'kwifrospcdevxjtzyhnqulabgm'"
238 ]
239 },
240 "execution_count": 25,
241 "metadata": {},
242 "output_type": "execute_result"
243 }
244 ],
245 "source": [
246 "kb, scoreb = simulated_annealing_break(scb, fitness=Pletters)\n",
247 "kb"
248 ]
249 },
250 {
251 "cell_type": "code",
252 "execution_count": 26,
253 "metadata": {},
254 "outputs": [
255 {
256 "data": {
257 "text/plain": [
258 "'batisolrhairosunegihtrtnhueboraledlnewurtwsiebnitheogiaitohnrwnebotewyseenirtwttoserhiewniweeohotafsuesamniknigertoeratsrtcoletividohthlovgoelneehpsulptiertresthorginetfwettuperborefeunefontediwaalhsebarmitirthitoamhikstgnnuasewniyrtesieccetsaathdalinahehlovaneenatnikerafgsgshiuomoaesnocafpmpwksagnisiwtlecpdusarmhamawdulsaduaorwlebssoweituaertoehotthklsucertaystesserkhiocahendolitodnawoegnioataddmtuysonoerthftoxesenrambwdubenlsenuanetlnosaetuosarexiluhyorhhinaiebecinremtwooerehhihtdvnelolatssotiptuaertyeypsatcalercnanastotnaiebartsiyeihhfedehokniofuithfddnsunohrtwaveihhdifptincadlusoennoiritodnaithihaaasttgnujaithtpchirsahcattlonaiwniweeertdavftiasuhortewyseenirtwttoserelohatlovhietefsetuactrgnnisoesoeartifsrmtesesuanmaletanrgadorpdohoesvpwbasiweehttcdefavuhisetsacerhsiohtdettidnoertwicethsnoywenovhcelgidhtrsemloeyalidverhpfwsuaserheaftokiounauasyosisenolyalwosyherpoeboartrguhutoemrmkmneayewebsuanudasoifsseteatuhntesherecoaptrtcsiesicdthonuodsiwnfgnttuhirhomenoitndesthptosigeayliebetnewnatwiuflwdcnaewielntefeemuanmtsonaaitmhntordimrtdwpeanartmttotorertsicdthonuodsiwnrgnfhoneellovyahidwersayodeiwnhgnmarnoyaypsnaklaolhrtnvpehhadfienpowemwntordimtidhalactrtstyesfagniertaryeeysebiypihhtnaperuodrlnhislhkotosthrvaclidioesuwnomanhtiyeerthatoaenrtcsienmamhiksagnieatuhntesterotaurddiytoinaitcalerivodotthihphyetoeyrmnedisuaoagohdfestteyseftethpbisgnidatsoescntyaoerseyolilhnvaaosenitrmgeseyemthueatuhntestormemmniseremenolhonwooniythitoshsabordoeoesypwewoebautshesuatalhelninsjgnniaqetadvtosnaiwnosuaodvhinfatdiunawertpswnewodfnagbosobaesgeyeitnemcnolaaliwstonjoeniaiytihhtnahirarhwdubighuellohhehateyatcaoerseyolietnnrlolinodstwniognitoyisehdoirmaedasusnmklahtethphyeesosocsayaheirvithtoltwenorerthsiertssiidelnonaeertikhaddrtcsiethonastuoeyhhnoortrttrpeebooedensocwaysoesuafrttidetiycahyurenouwnnosoelvwncseysalnortemnoorefebneedfoatecahisoimttddekoyahiteteybaalseeyaerteyoliswnothihuscatsuaothoetiwnohtnegeilufhhotnadhogertawptandefbeirtemtosoeefenirrtwesenelohttafegottovyethtnerrtiknimemddioefedfoatirlebeirtaghod'"
259 ]
260 },
261 "execution_count": 26,
262 "metadata": {},
263 "output_type": "execute_result"
264 }
265 ],
266 "source": [
267 "keyword_decipher(scb, kb)"
268 ]
269 },
270 {
271 "cell_type": "code",
272 "execution_count": 58,
273 "metadata": {},
274 "outputs": [
275 {
276 "data": {
277 "text/plain": [
278 "2317"
279 ]
280 },
281 "execution_count": 58,
282 "metadata": {},
283 "output_type": "execute_result"
284 }
285 ],
286 "source": [
287 "open(plaintext_b_filename, 'w').write(repunctuate(rpb, ptrb))"
288 ]
289 },
290 {
291 "cell_type": "code",
292 "execution_count": 27,
293 "metadata": {},
294 "outputs": [],
295 "source": [
296 "import itertools"
297 ]
298 },
299 {
300 "cell_type": "code",
301 "execution_count": 38,
302 "metadata": {},
303 "outputs": [],
304 "source": [
305 "rccb = cat(cat(reversed(c)) for c in chunks(scb, 5))"
306 ]
307 },
308 {
309 "cell_type": "code",
310 "execution_count": 57,
311 "metadata": {},
312 "outputs": [
313 {
314 "data": {
315 "text/plain": [
316 "'tovarishcdefgjklmnpquwxyzb'"
317 ]
318 },
319 "execution_count": 57,
320 "metadata": {},
321 "output_type": "execute_result"
322 }
323 ],
324 "source": [
325 "kb, scoreb = simulated_annealing_break(rccb)\n",
326 "kb"
327 ]
328 },
329 {
330 "cell_type": "code",
331 "execution_count": 10,
332 "metadata": {},
333 "outputs": [],
334 "source": [
335 "spb = keyword_decipher(scb, 'tovarishch', KeywordWrapAlphabet.from_last)\n",
336 "trs = list(itertools.permutations(range(5)))\n",
337 "column_transposition_break_mp(rcpb, translist=trs, fitness=Ptrigrams)"
338 ]
339 },
340 {
341 "cell_type": "code",
342 "execution_count": 11,
343 "metadata": {},
344 "outputs": [
345 {
346 "data": {
347 "text/plain": [
348 "'vot ira chs oih aru neg ist htn sue vah oce lcn edu htd rie vni tse agi oit asn hdn eva ted mre eni htd tta reh sie dni dee asa tob rue row nik nig eht aeh otr htf ace tip ila sts cap gae cne esy ruc yti eht her tsa hgi net bde ttu yeh vah ebe une ban tel ido ocs rev ohw iti hts ita ows ikr tgn nuo red nim hte rie ffe tro ots loc ino ses cap one eno tni keh obg rgr siu awa oer naf oby wyd kro gni rid tce fyl uro hws owo dlu cro luo ahd cev rra dei tuo eht aes att skc ruf eht omr ter reh ksi afo sen lac ita lno dae gni aot oll wtu mra nae hts bta zer enh owv dlu ven cre nuo net cna roe tua roh ezi cus mah ssi noi eve fin hew tda aeh ess ist lpn eca cot rra tiy tuo eht mem yro tfo ceh fno nor tat noi evo htr ime iss bel esa kni abu its bll nru nas htd ope iss lib yti nfo lcu rae nna ihi tal noi tsi soo ort tgn ujo its tyf sih ros fot tca noi dni dee eht lop bti oru sah ted mre eni htd tta reh eca sot cap sie teb ret uof thg nni rae rae oht ibr hwt ere ruo nwo cet onh gol ahy las aer pyd vor ide est tfl ebo pus ire tro feh sri ast let til nae htd ife tsr nam den aps fec gil sth rew cae moc ilp ehs ybd ruo reh seo bta kia uno uor mar ire nac moc dar mse hya eva oht hgu sut aew hwk wne ome dev ruo nul ora ibr ret eot usn ter seh efa oyt htf rie rif lts anu alr idn bgn ttu sih saw ena itn ler tsy tar ige omc iev etn edn otd iub cdl fno edi ecn teb eew uon wtr ano oit wsn tah liw htl dye ono htw tta tah eht rif lts anu alr idn hgn bsa nee cca pmo sil deh rom ale idn sgn woh nam omy rno kco acs htn pye sso lbi eny ade wdn tah liw til soc oft htr tme rbo gni eht ohm eem rev imy iss tno yeh ual hcn sir csk ata rts hpo fci lia eru dna won sti mee hts ota oen htf rie nwo wsi kro gni eot usn ter teh ato uhl lim tai noi tfo ceh ipa lat tsi sys met aem hwn eli ruo aog asl ber tte mre bte tsy vir gni lot rae rfn tmo aeh rem aci csn poo are nit hwg ere mew tsu eot usn ter tah wew wni reh ewe nac san daa nim tsi tar sro vah lae aer myd eda evo utr ser uot ocs ecn inr jgn nio xet olp tar noi dna ruo alp sin bot liu nod eht yrd ned alb nog var avo erg eme itn ewf nac ooc idr tan jae nio imt iss tno sih ohs dlu vig sue cca sse sot emo tfo aeh rem aci etn nhc aci nal rtd nia gni tam ire sla ihw oel oru rnw kco ste tsy sme era raf rom ose ihp its tac tde nah eht sri eht rri ile cna noe eht iks oll htf rie tsa nor tua ems sna aht htt hye eva ael enr afd omr aer uob htt ile tim fos muh ena udn nar aec pdn fre mro cna hte wna ahe bev nee lba ote fos ira iwt tll eka mos ite tem voo cre emo eht ema cir dna tsi sur fot ruo ats aet idn ast neg eic ubs sat nol sag eht ody ton leb vei hte wta rae ebe nih htd ere nec ast tob ega tta pme tst neh hti kni wew lli aeb elb aot ihc eve iht ogs al'"
349 ]
350 },
351 "execution_count": 11,
352 "metadata": {},
353 "output_type": "execute_result"
354 }
355 ],
356 "source": [
357 "wcat(chunks(spb, 3))"
358 ]
359 },
360 {
361 "cell_type": "code",
362 "execution_count": 12,
363 "metadata": {},
364 "outputs": [
365 {
366 "name": "stdout",
367 "output_type": "stream",
368 "text": [
369 "to var ish chi our agents in the us have concluded their investigations and have determined that\n",
370 "there is indeed a saboteur working in the heart of the capitalist space agency security there has\n",
371 "tightened but they have been unable to discover who it is that is working to undermine their efforts\n",
372 "to colonise space no one in the kgb or gru is aware of anybody working directly for us who would or\n",
373 "could have carried out these attacks furthermore the risk of an escalation leading to all out war\n",
374 "means that brezhnev would never countenance or authorize such a mission even if we had the assets in\n",
375 "place to carry it out the memory of the confrontation over the missile base in kuba still burns and\n",
376 "the possibility of nuclear annihilation is too strong to justify this sort of action indeed the\n",
377 "politburo has determined that the race to space is better fought in near earth orbit where our own\n",
378 "technology has already proved itself to be superior the first satellite and the first manned space\n",
379 "flights were accomplished by our heroes at baikonur our american comrades may have thought us weak\n",
380 "when we moved our lunar orbiter to ensure the safety of their first lunar landing but this was an\n",
381 "entirely strategic move intended to build confidence between our two nations what will they do now\n",
382 "that that the first lunar landing has been accomplished more landing show many moon rocks can they\n",
383 "possibly need and what will it cost for them to bring them home every mission they launch risks\n",
384 "catastrophic failure and now it seems that one of their own is working to ensure the total\n",
385 "humiliation of the capitalist system meanwhile our goals are better met by striving to learn from\n",
386 "the americans cooperating where we must to ensure that we win where we can nasa administrators have\n",
387 "already made overtures to us concerning joint exploration and our plan is to build on the dryden\n",
388 "blag on ravo v agreement if we can coordinate a joint mission this should give us access to some of\n",
389 "the american technical and training materials while our own rocket systems are far more\n",
390 "sophisticated than theirs their reliance on the skill of their astronauts means that they have\n",
391 "learned far more about the limits of human endurance and performance than we have be enable to so\n",
392 "far it will take sometime to overcome the american distrust of our state and its agencies but as\n",
393 "long as they do not believe that we are behind the recent sabotage attempts then i think we will be\n",
394 "able to achieve this goal\n"
395 ]
396 }
397 ],
398 "source": [
399 "print(lcat(tpack(segment(cat(cat(reversed(c)) if len(c) == 3 else c for c in chunks(spb, 3))))))"
400 ]
401 },
402 {
403 "cell_type": "code",
404 "execution_count": 14,
405 "metadata": {},
406 "outputs": [
407 {
408 "data": {
409 "text/plain": [
410 "2469"
411 ]
412 },
413 "execution_count": 14,
414 "metadata": {},
415 "output_type": "execute_result"
416 }
417 ],
418 "source": [
419 "open(plaintext_b_filename, 'w').write(lcat(tpack(segment(cat(cat(reversed(c)) if len(c) == 3 else c \n",
420 " for c in chunks(spb, 3))))))"
421 ]
422 },
423 {
424 "cell_type": "code",
425 "execution_count": null,
426 "metadata": {},
427 "outputs": [],
428 "source": []
429 }
430 ],
431 "metadata": {
432 "kernelspec": {
433 "display_name": "Python 3",
434 "language": "python",
435 "name": "python3"
436 },
437 "language_info": {
438 "codemirror_mode": {
439 "name": "ipython",
440 "version": 3
441 },
442 "file_extension": ".py",
443 "mimetype": "text/x-python",
444 "name": "python",
445 "nbconvert_exporter": "python",
446 "pygments_lexer": "ipython3",
447 "version": "3.7.5"
448 }
449 },
450 "nbformat": 4,
451 "nbformat_minor": 4
452 }