Updated for challenge 9
[cipher-tools.git] / 2016 / 2016-challenge8.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) \n",
13 "\n",
14 "import matplotlib.pyplot as plt\n",
15 "%matplotlib inline\n",
16 "\n",
17 "from cipher.hill import *\n",
18 "from support.utilities import *\n",
19 "from support.text_prettify import *\n",
20 "\n",
21 "c8a = open('8a.ciphertext').read()\n",
22 "c8b = open('8b.ciphertext').read()\n",
23 "\n",
24 "c8as = sanitise(c8a)\n",
25 "c8bs = sanitise(c8b)"
26 ]
27 },
28 {
29 "cell_type": "code",
30 "execution_count": 2,
31 "metadata": {},
32 "outputs": [
33 {
34 "data": {
35 "text/plain": [
36 "(matrix([[ 7, 8],\n",
37 " [11, 11]]), -5760.41300554484)"
38 ]
39 },
40 "execution_count": 2,
41 "metadata": {},
42 "output_type": "execute_result"
43 }
44 ],
45 "source": [
46 "key_a, score = hill_break(sanitise(c8a))\n",
47 "key_a, score"
48 ]
49 },
50 {
51 "cell_type": "code",
52 "execution_count": 3,
53 "metadata": {
54 "scrolled": true
55 },
56 "outputs": [
57 {
58 "data": {
59 "text/plain": [
60 "[('a', 312),\n",
61 " ('l', 243),\n",
62 " ('x', 228),\n",
63 " ('r', 220),\n",
64 " ('c', 216),\n",
65 " ('j', 214),\n",
66 " ('d', 210),\n",
67 " ('i', 208),\n",
68 " ('b', 207),\n",
69 " ('o', 198),\n",
70 " ('h', 192),\n",
71 " ('u', 183),\n",
72 " ('z', 169),\n",
73 " ('s', 163),\n",
74 " ('m', 162),\n",
75 " ('g', 160),\n",
76 " ('w', 145),\n",
77 " ('q', 143),\n",
78 " ('n', 140),\n",
79 " ('f', 135),\n",
80 " ('k', 133),\n",
81 " ('p', 132),\n",
82 " ('v', 131),\n",
83 " ('y', 128),\n",
84 " ('e', 120),\n",
85 " ('t', 90)]"
86 ]
87 },
88 "execution_count": 3,
89 "metadata": {},
90 "output_type": "execute_result"
91 }
92 ],
93 "source": [
94 "collections.Counter(c8as).most_common()"
95 ]
96 },
97 {
98 "cell_type": "code",
99 "execution_count": 4,
100 "metadata": {},
101 "outputs": [
102 {
103 "name": "stdout",
104 "output_type": "stream",
105 "text": [
106 "charlieandtrinityithinkwehavecomeascloseaswecantoasolutiontothisveryoddcaseofadeadwomanwhoneverdiedaweaponthatneverexistedandagovernmentinitiativethathadnothingtodowiththegovernmentmartinandjameliawereputinaterriblepositionihadntrealisedjusthowbaduntilireadtheattacheddocumentthatirecoveredfrommartinsandjameliasharddriveittellsthewholestorythesyndicateprobablythoughttheywerebeingcleverwhentheyfakedjameliasdeaththerewasaclearthreatthatonceherdeathwasrecordedassuicidetheycoulddisposeofherintheirownwayandintheirowntimeifshefailedtocooperatewhattheyfailedtorealiseisthatonceshewasofficiallydeadnoonewouldbelookingoutforheranditmadeitaloteasierforhertodisappearwhenshewantedtohavingbeencutloosefromthegovernmentthesyndicatewererelyingonsourcesintheinternationalintelligencecommunitytocarryoutsurveillanceforthembutnoonewouldbewatchingforaghostandtoomanyquestionswouldhavebeenaskediftheyrequestedasearchonceshewasofficiallydeadithinkthatdynamixrealisedearlyonwhatthetemplateapproachcoulddoforlargescalenetworkanalysisandtheyrealisedthatjameliahadthetalentandmartintheambitiontomakeitworkasasmallcompanytheyhadnothingtolosebyinvestinginitbutwhencitadelleheardrumoursthattheywereworkingonsomethingbigtheyrealisedthatthiscouldbethebreakthroughtheyneededtheirmassiveinvestmentinconventionalbattlefieldweaponrythreatenedtobecomeobsoleteonthecyberbattlefieldandtheyweresearchingforsomethingnewtorevitalisethecompanyatfirstithinktheygenuinelymisunderstoodwhatdynamixwereworkingontheconfusionbetweengravitywavesandgravitationalwavesledeveryonetoassumethatdynamixwerehopingtoweaponizeseismicactivityperhapsviaaresonanceeffectbutthiswasneveraboutaweaponofmassdestructionasjameliasexposemakescleariamnotsureatwhatpointthepostdigitalsurveillancesyndicategotinvolvedtheywereinitiallysetuptoprepareforatimewhendigitalsurveillanceisnolongereffectiveaquantumtechnologiesenvironmentinwhichthecontentofcommunicationsisencryptedsosecurelythatnoalgorithmcancrackitwithoutbetrayingitspresencetheywerekeepingacloseeyeonallthesoftwaredevelopmentteamsatarmsmanufacturersandhadkeptjameliaandmartinunderobservationwhenworkingfordynamixtheywerecertainlyquicktorealisethepotentialofthesignalnoiseanalysistechniquesthepairhaddevelopedforgravitationalwavedetectionatsomepointthoughsomeonerealisedthefundamentalflawinusingatemplatebasedapproachwhichinabetterworldwouldhaveledtotheendoftheprojectunfortunatelysomeevilgeniusatthesyndicatesawasolutionandgiventheobviouslimitsongovernmentactioninthisspheretheydecidedtoleverageprivatesectorinvolvementgiventheirhungerforrelevancecitadellewereanobvioustargetandwerebroughtintothepictureunfortunatelyforthesyndicatesomeoneatcitadelleblabbedtoaseniorcivilservantandthewholeoperationwasterminatedthejunioroperativesweredispersedamongotherdepartmentsbutthemajorplayerswereretiredwenowknowthattheremainsofthesyndicatecontinuedtooperatewithcitadelleanddynamixfundingagovernmentdepartmentnolongeriwasthrownbymartinscalltothephonelinkedtocitadelleduringtheinterviewlastweekandforamomentthoughtthathewasworkingwiththembutofcoursehewasnotphoningcitadelleifwetrackthephonewewillfindjameliawithnorealresourcesoftheirownsheandmartinseemstohaveplayedtheblackhatsattheirowngametakingwhattheyneedastheypreparedtodoublecrossthemyoumightaskwhysheisnotmakingmoreofanefforttohidefromthesyndicateanditsalliesbutthatisthebeautyofthewaytheyhavethissetupmartinstimewiththecollectivehasbeenspentseedingcopiesofthefileontoeveryserverhecouldfindifanythinghappenedtothemnowitwouldbeimpossibleforthesyndicatedynamixorcitadelletosuppresstheinformationitwouldfloodthewebtheirapparentcarelessnessweakencryptionandpoorlyhiddendocumentsmartinsappearanceonbanksurveillancecamerasandhisvisibilityonthewebwereallpartofaschemetoensuretheauthoritiesgotsuspiciousasortofinsurancepolicyitforcedthesyndicatetoprotectthemhencethehighqualitytraveldocumentstogetrealprotectionjameliahadtomakesuretheirstorycouldntbesquashedsotheyhadtobuytimesheandmartinagreedtoworkwiththesyndicateandtoconspireinjameliasfakeddeathandithinktheyconvincedthesyndicatetoletmartinjointhehackercollectivebypresentingitasagoodcoverfordatacollectionarguingthattheyneededtosetthebaselineforthebehaviouraltemplatesbutnowthebigquestiondowegopublicifwedoitwilllancetheboilandwehavearealchanceofbringingdownthesyndicateanditscollaboratorsinseveralmajorarmsmanufacturerswemightalsobeabletotracethetemplatetargetsontheotherhandifwedothatwealsoriskkillingjameliaandmartinoncethestoryispublicthereisnoreasonforthepdssyndicatetokeepthemaliveandeveryreasontosilencewitnessesidontknowwhatyouthinkbutithinkweneedtodealwiththisofflinetheoldfashionedway\n"
107 ]
108 }
109 ],
110 "source": [
111 "print(hill_decipher(key_a, c8as))"
112 ]
113 },
114 {
115 "cell_type": "code",
116 "execution_count": 5,
117 "metadata": {},
118 "outputs": [
119 {
120 "name": "stdout",
121 "output_type": "stream",
122 "text": [
123 "charlie and trinity i think we have come as close as we can to a solution to this very odd case of a dead woman who never died a weapon that never existed and a government initiative that had nothing to do with the government martin and jamelia were putin a terrible position i hadnt realised just how bad until i read the attached document that i recovered from martins and jamelia s harddrive it tells the whole story the syndicate probably thought they were being clever when they faked jamelia s death there was a clear threat that once her death was recorded as suicide they could dispose of her in their own way and in their own time if she failed to cooperate what they failed to realise is that once she was officially dead no one would be looking out for her and it made it alot easier for her to disappear when she wanted to having been cut loose from the government the syndicate were relying on sources in the international intelligence community to carryout surveillance for them but no one would be watching for a ghost and too many questions would have been asked if they requested a search once she was officially dead i think that dynamix realised early on what the template approach could do for largescale network analysis and they realised that jamelia had the talent and martin the ambition to make it work as a small company they had nothing to lose by investing in it but when citadelle heard rumours that they were working on something big they realised that this could be the breakthrough they needed their massive investment in conventional battlefield weaponry threatened to become obsolete on the cyber battlefield and they were searching for something new to revitalise the company at first i think they genuinely misunderstood what dynamix were working on the confusion between gravity waves and gravitational waves led everyone to assume that dynamix were hoping to weapon ize seismic activity perhaps via a resonance effect but this was never about a weapon of mass destruction as jamelia s expose makes clear i am not sure at what point the post digital surveillance syndicate got involved they were initially setup to prepare for a time when digital surveillance is no longer effective a quantum technologies environment in which the content of communications is encrypted so securely that no algorithm can crack it without betraying its presence they were keeping a close eye on all the software development teams at arms manufacturers and had kept jamelia and martin under observation when working for dynamix they were certainly quick to realise the potential of the signal noise analysis techniques the pair had developed for gravitational wave detection at some point though someone realised the fundamental flaw in using a template based approach which in a better world would have led to the end of the project unfortunately some evil genius at the syndicate saw a solution and given the obvious limits on government action in this sphere they decided to leverage private sector involvement given their hunger for relevance citadelle were an obvious target and were brought into the picture unfortunately for the syndicate someone at citadelle blabbed to a senior civil servant and the whole operation was terminated the junior operatives were dispersed among other departments but the major players were retired we now know that the remains of the syndicate continued to operate with citadelle and dynamix funding a government department no longer i was thrown by martins call to the phone linked to citadelle during the interview last week and for a moment thought that he was working with them but of course he was not phoning citadelle if we track the phone we will find jamelia with no real resources of their own she and martin seems to have played the black hats at their own game taking what they need as they prepared to double cross them you might ask why she is not making more of an effort to hide from the syndicate and its allies but that is the beauty of the way they have this setup martins time with the collective has been spent seeding copies of the file on to every server he could find if anything happened to them now it would be impossible for the syndicate dynamix or citadelle to suppress the information it would flood the web their apparent carelessness weak encryption and poorly hidden documents martins appearance on bank surveillance cameras and his visibility on the web were all part of a scheme to ensure the authorities got suspicious a sort of insurance policy it forced the syndicate to protect them hence the high quality travel documents to get real protection jamelia had to make sure their story couldnt be squashed so they had to buy time she and martin agreed to work with the syndicate and to conspire in jamelia s faked death and i think they convinced the syndicate to let martin join the hacker collective by presenting it as a good cover for data collection arguing that they needed to set the baseline for the behavioural templates but now the big question do we go public if we do it will lance the boil and we have a real chance of bringing down the syndicate and its collaborators in several major arms manufacturers we might also be able to trace the template targets on the other hand if we do that we also risk killing jamelia and martin once the story is public there is no reason for the pds syndicate to keep them alive and every reason to silence witnesses i dont know what you think but i think we need to deal with this offline the oldfashioned way\n"
124 ]
125 }
126 ],
127 "source": [
128 "print(wcat(segment(hill_decipher(key_a, c8as))))"
129 ]
130 },
131 {
132 "cell_type": "code",
133 "execution_count": 6,
134 "metadata": {},
135 "outputs": [
136 {
137 "data": {
138 "text/plain": [
139 "[('0', 15368), ('1', 11257), (' ', 6508), ('2', 5920), ('\\n', 1)]"
140 ]
141 },
142 "execution_count": 6,
143 "metadata": {},
144 "output_type": "execute_result"
145 }
146 ],
147 "source": [
148 "collections.Counter(c8b).most_common()"
149 ]
150 },
151 {
152 "cell_type": "code",
153 "execution_count": null,
154 "metadata": {},
155 "outputs": [],
156 "source": []
157 }
158 ],
159 "metadata": {
160 "kernelspec": {
161 "display_name": "Python 3",
162 "language": "python",
163 "name": "python3"
164 },
165 "language_info": {
166 "codemirror_mode": {
167 "name": "ipython",
168 "version": 3
169 },
170 "file_extension": ".py",
171 "mimetype": "text/x-python",
172 "name": "python",
173 "nbconvert_exporter": "python",
174 "pygments_lexer": "ipython3",
175 "version": "3.6.3"
176 }
177 },
178 "nbformat": 4,
179 "nbformat_minor": 1
180 }