--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": true
+ },
+ "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",
+ "c1a = open('1a.ciphertext').read()\n",
+ "c1b = open('1b.ciphertext').read()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(8, -1547.487440811204)"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_a, score = caesar_break(c1a)\n",
+ "key_a, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "HARRY,\n",
+ "I HAVE SCANNED THE ENCRYPTED NOTE THE POLICE FOUND ON JAMELIA'S DESK AND ATTACHED IT FOR YOU TO LOOK AT. THE POLICE DECRYPTED IT FOR THEMSELVES (IT IS VERY STRAIGHTFORWARD ONCE YOU REALISE THAT IT HAS BEEN WRITTEN BACKWARDS - IT JUST USES A CAESAR SHIFT CIPHER). THE OFFICER IN CHARGE OF THE INVESTIGATION MADE IT CLEAR TO ME THAT HE THINKS THIS PROVES JAMELIA'S DEATH IS \"JUST\" A PERSONAL TRAGEDY. CARELESS USE OF THE WORD \"JUST\" EVEN IF HE IS RIGHT, BUT I DON'T THINK HE IS. I HAVE SPOKEN TO HER COLLEAGUES, AND JAMELIA DOESN'T STRIKE ME AS A JUMPER. SHE WAS PRETTY DRIVEN AND HER WORK WAS GOING EXTREMELY WELL. APPARENTLY SHE WAS UNHAPPY ABOUT HER BOYFRIEND LEAVING, BUT A QUICK SCAN OF HER SEARCH HISTORY SUGGESTS SHE WAS PRETTY ACTIVE IN TRYING TO TRACK HIM DOWN. THE POLICE THINK THAT SHOWS HOW DESPERATE SHE WAS. I THINK IT SHOWS THAT SHE WASN'T THE SORT TO GIVE UP EASILY.\n",
+ "ON ONE THING I DO AGREE WITH THE POLICE, IT DOESN'T SEEM VERY LIKELY THAT A PHYSICIST WORKING ON GRAVITY WAVES IS CAUGHT UP IN ANYTHING TOO SUSPICIOUS. HER AREA IS WELL FUNDED AND SINCE THE DISCOVERY OF GRAVITY WAVES A FEW MONTHS AGO IT IS IN THE SPOTLIGHT. HER HEAD OF DEPARTMENT SAYS JAMELIA WAS DESTINED FOR A GOOD CAREER, AND I CAN'T SEE ANYTHING IN HER WORK THAT WOULD BE OF INTEREST TO DARKNET OR GOVERNMENT ACTORS.\n",
+ "TO BE HONEST I AM UNSURE IF I AM CHASING SHADOWS HERE, BUT THEN SHADOW CHASING IS ONE OF YOUR SPECIALITIES SO I WOULD BE REALLY GRATEFUL IF YOU COULD TAKE A LOOK AND LET ME KNOW IF YOU THINK I AM WASTING YOUR TIME.\n",
+ "\n",
+ "THANKS,\n",
+ "\n",
+ "CHARLIE\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(caesar_decipher(c1a, key_a))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(11, -384.68678644711156)"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_b, score = caesar_break(c1b)\n",
+ "key_b, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\"E TOY'P ZEPGLST OY PZED LSET YZTE. AZYLP GLSEYZOTZD HZ YPCP, SPYZW LELSEZOYLN TH ZSPPDE. YLN TE TIT QZEO, PEC L EDP'G LSES RTX, PHC PSEP RZ EEF MJE WT FRSE ZMPC LPHOY. L RYT'Y PAALS DLH ELSH ZEOY TW, MS EZMP CPHP HPXYL SE PCZX XTS PXLWMEYLN TPY ZW LSE THWL POZERT, MZZ EDTDTSEO YL XTSOY TQEY LNTOYLP YZ RDL SP. S EFM'O PPC RLP H RYT SE JCPG PCPEQ, LOTL, DPH. RY T SEJ'C PGPC PE QLELSE. PV TWE QP WPS. P GPTW PM EYL NT.\\n\""
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "c1b"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "icant believe he left like that after everything we said after everything we agreed but he has gone and icant find him and this is too big to deal with alone icant blame him more than me we were both blind to what was happening and we are both guilty but together we might have started to fix it icant see how i can do that alone here now so i dont have an option it has to end i have to end it\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(wcat(segment(cat(reversed(sanitise(caesar_decipher(c1b, key_b)))))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "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.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 1
+}
--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": true
+ },
+ "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",
+ "c2a = open('2a.ciphertext').read()\n",
+ "c2b = open('2b.ciphertext').read()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(6, -1833.0297785667572)"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_a, score = caesar_break(c2a)\n",
+ "key_a, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "CHARLIE\n",
+ "THE NOTE YOU SENT OVER WAS TRICKIER THAN I EXPECTED. JAMELIA DIDN'T JUST REVERSE THE WHOLE MESSAGE BEFORE ENCRYPTING IT, SHE PUT ALL THE PUNCTUATION AND SPACING BACK IN THE ORIGINAL PLACES TO THROW THE CASUAL READER OFF THE SCENT. IT WASN'T VERY SOPHISTICATED, BUT IT WAS DEVIOUS, AND TELLS US SOMETHING ABOUT THE WAY SHE THINKS. ONE THING I AM CERTAIN ABOUT, THIS DOESN'T READ LIKE A SUICIDE NOTE. WHO WRITES ONE OF THOSE IN CODE?\n",
+ "\n",
+ "OUR FIELD AGENT ASKED AROUND AT THE UNIVERSITY AND WAS TOLD THAT JAMELIA'S BOYFRIEND WORKED IN THE SAME LAB AS HER FOR A WHILE. HIS NAME IS MARTIN TRAYNOR AND THEY BOTH DID AN INTERNSHIP IN THEIR SECOND YEAR AT A SPINOUT COMPANY CALLED DYNAMIX. THAT IS A SMALL STARTUP WHICH WORKS ON THE FRINGES OF THE ARMS INDUSTRY, BUT NO-ONE SEEMS TO KNOW MUCH ABOUT IT.\n",
+ "\n",
+ "I AM NOT SURE WHY DYNAMIX WOULD HAVE HIRED JAMELIA; YOU SAID THAT SHE WAS WORKING ON GRAVITY WAVES, WHICH ARE A SEISMOLOGICAL PHENOMENON. I READ AN INTERESTING PAPER CALLED \"GRAVITY WAVES IN EARTHQUAKES\" WHICH SUGGESTED THAT THEY MIGHT BE RESPONSIBLE FOR THE DESTRUCTION OF HIGH RISE BLOCKS DURING SOME TREMORS. BUT UNLESS DYNAMIX ARE PLANNING TO TRY TO WEAPONISE EARTHQUAKES I AM NOT SURE WHY THIS WOULD BE OF INTEREST TO THEM. WE NEED TO KNOW MORE ABOUT HER WORK AND WHAT THEY HIRED HER TO DO.\n",
+ "\n",
+ "THERE ARE A LOT OF QUESTIONS EVEN IN THE FIRST NOTE:\n",
+ "\n",
+ "WHY DID MARTIN LEAVE?\n",
+ "WHERE IS HE?\n",
+ "WHY COULDN'T SHE GET HOLD OF HIM?\n",
+ "WHAT WAS TOO BIG FOR JAMELIA TO HANDLE ALONE?\n",
+ "WHAT MADE JAMELIA FEEL GUILTY?\n",
+ "HOW WAS SHE PLANNING TO FIX IT?\n",
+ "\n",
+ "I AM HOPING THAT THE ATTACHED DOCUMENT WILL ANSWER SOME OF THESE QUESTIONS BUT IT WILL PROBABLY JUST RAISE OTHERS. I FOUND IT PASTED UNDER THE COVER OF THE NOTEBOOK THAT THE PREVIOUS MESSAGE WAS TAKEN FROM. I CAN SEE WHY THE POLICE MISSED IT, THOUGH IT WASN'T A VERY PROFESSIONAL JOB.\n",
+ "\n",
+ "HARRY\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(caesar_decipher(c2a, key_a))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(17, -1552.2481210949848)"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_b, score = caesar_break(c2b)\n",
+ "key_b, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "NHFXCZDYX KDS TLSCZY,\n",
+ "\n",
+ "RUB LSF VZCLAFOOF ZYCFSFXCFA ZY ABYLTZW?\n",
+ "UDR AZA ABYLTZW PFC TB VDAF-QLXF?\n",
+ "RULC LSF ABYLTZW IOLYYZYP CD AD RZCU ZC?\n",
+ "RUB ZX UF XCZOO ZYMDOMFA RZCU CUFT?\n",
+ "RUD LSF CUF IAX XBYAZVLCF?\n",
+ "\n",
+ "Z CUZYJ Z JYDR CUF LYXRFSX, LYA Z LT ISFCCB XHSF UF THXC AD CDD. CUF CUSFF TDYCUX RF XIFYC RDSJZYP LC ABYLTZW RFSF XDTF DK CUF TDXC FWVZCZYP Z ULMF FMFS FWIFSZFYVFA, QHC XHSFOB, JYDRZYP RULC RF JYDR YDR, FMFY TLSCZY THXC ULMF XDTF SFXFSMLCZDYX LQDHC RDSJZYP RZCU CUFXF IFDIOF.\n",
+ "\n",
+ "Z LT YDC XHSF RUD CD CLOJ CD LQDHC CUZX. Z LT VFSCLZY CULC XDTF TFTQFSX DK CUF QDLSA LC ABYLTZW LSF VDTIOFCFOB ZY CUF ALSJ LQDHC ZC, YD VDYXIZSLVB RZCU CULC TLYB TFTQFSX VDHOA ULMF XHSMZMFA TDSF CULY L RFFJ, QHC Z ULMF YD ZAFL RUZVU DK CUFT Z VLY CSHXC. Z CUDHPUC Z VDHOA CSHXC TLSCZY, QHC CULC RLX QFKDSF CUF IAX ULVJ.\n",
+ "\n",
+ "Z VLY’C CLOJ CD CUF IDOZVF; XIFVZLO QSLYVU LSF VFSCLZY CD KOLP ZC PZMFY CUF YLTFX DK XDTF DK CUF IFDIOF DY CUF QDLSA. RZCU CUFZS VDYYFVCZDYX RUD JYDRX RULC TZPUC ULIIFY. CUF IAX XBYAZVLCF LSF CDD QZP KDS TF CD ULYAOF LODYF. CUFB JYDR LOTDXC FMFSBCUZYP LQDHC TF, LYA Z JYDR YFWC CD YDCUZYP LQDHC CUFT. ZK Z XCLB UFSF CD KZPUC, CUFY ZC ZX DYOB L TLCCFS DK CZTF HYCZO CUFB SFLOZXF Z LT DY CD CUFT. ZK Z ULMFY’C AZXLIIFLSFA QFKDSF CUFY, CUFY Z ULMF L KFFOZYP CUFB RZOO TLJF TF AZXLIIFLS.\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(c2b)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "WQOGLIMHG TMB CUBLIH,\n",
+ "\n",
+ "ADK UBO EILUJOXXO IHLOBOGLOJ IH JKHUCIF?\n",
+ "DMA JIJ JKHUCIF YOL CK EMJO-ZUGO?\n",
+ "ADUL UBO JKHUCIF RXUHHIHY LM JM AILD IL?\n",
+ "ADK IG DO GLIXX IHVMXVOJ AILD LDOC?\n",
+ "ADM UBO LDO RJG GKHJIEULO?\n",
+ "\n",
+ "I LDIHS I SHMA LDO UHGAOBG, UHJ I UC RBOLLK GQBO DO CQGL JM LMM. LDO LDBOO CMHLDG AO GROHL AMBSIHY UL JKHUCIF AOBO GMCO MT LDO CMGL OFEILIHY I DUVO OVOB OFROBIOHEOJ, ZQL GQBOXK, SHMAIHY ADUL AO SHMA HMA, OVOH CUBLIH CQGL DUVO GMCO BOGOBVULIMHG UZMQL AMBSIHY AILD LDOGO ROMRXO.\n",
+ "\n",
+ "I UC HML GQBO ADM LM LUXS LM UZMQL LDIG. I UC EOBLUIH LDUL GMCO COCZOBG MT LDO ZMUBJ UL JKHUCIF UBO EMCRXOLOXK IH LDO JUBS UZMQL IL, HM EMHGRIBUEK AILD LDUL CUHK COCZOBG EMQXJ DUVO GQBVIVOJ CMBO LDUH U AOOS, ZQL I DUVO HM IJOU ADIED MT LDOC I EUH LBQGL. I LDMQYDL I EMQXJ LBQGL CUBLIH, ZQL LDUL AUG ZOTMBO LDO RJG DUES.\n",
+ "\n",
+ "I EUH'L LUXS LM LDO RMXIEO; GROEIUX ZBUHED UBO EOBLUIH LM TXUY IL YIVOH LDO HUCOG MT GMCO MT LDO ROMRXO MH LDO ZMUBJ. AILD LDOIB EMHHOELIMHG ADM SHMAG ADUL CIYDL DURROH. LDO RJG GKHJIEULO UBO LMM ZIY TMB CO LM DUHJXO UXMHO. LDOK SHMA UXCMGL OVOBKLDIHY UZMQL CO, UHJ I SHMA HOFL LM HMLDIHY UZMQL LDOC. IT I GLUK DOBO LM TIYDL, LDOH IL IG MHXK U CULLOB MT LICO QHLIX LDOK BOUXIGO I UC MH LM LDOC. IT I DUVOH'L JIGURROUBOJ ZOTMBO LDOH, LDOH I DUVO U TOOXIHY LDOK AIXX CUSO CO JIGURROUB.\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(caesar_decipher(c2b, key_b))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "((5, 7, True), -1275.2927860232996)"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "key_b, score = affine_break(c2b)\n",
+ "key_b, score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "QUESTIONS FOR MARTIN,\n",
+ "\n",
+ "WHY ARE CITADELLE INTERESTED IN DYNAMIX?\n",
+ "HOW DID DYNAMIX GET MY CODE-BASE?\n",
+ "WHAT ARE DYNAMIX PLANNING TO DO WITH IT?\n",
+ "WHY IS HE STILL INVOLVED WITH THEM?\n",
+ "WHO ARE THE PDS SYNDICATE?\n",
+ "\n",
+ "I THINK I KNOW THE ANSWERS, AND I AM PRETTY SURE HE MUST DO TOO. THE THREE MONTHS WE SPENT WORKING AT DYNAMIX WERE SOME OF THE MOST EXCITING I HAVE EVER EXPERIENCED, BUT SURELY, KNOWING WHAT WE KNOW NOW, EVEN MARTIN MUST HAVE SOME RESERVATIONS ABOUT WORKING WITH THESE PEOPLE.\n",
+ "\n",
+ "I AM NOT SURE WHO TO TALK TO ABOUT THIS. I AM CERTAIN THAT SOME MEMBERS OF THE BOARD AT DYNAMIX ARE COMPLETELY IN THE DARK ABOUT IT, NO CONSPIRACY WITH THAT MANY MEMBERS COULD HAVE SURVIVED MORE THAN A WEEK, BUT I HAVE NO IDEA WHICH OF THEM I CAN TRUST. I THOUGHT I COULD TRUST MARTIN, BUT THAT WAS BEFORE THE PDS HACK.\n",
+ "\n",
+ "I CAN’T TALK TO THE POLICE; SPECIAL BRANCH ARE CERTAIN TO FLAG IT GIVEN THE NAMES OF SOME OF THE PEOPLE ON THE BOARD. WITH THEIR CONNECTIONS WHO KNOWS WHAT MIGHT HAPPEN. THE PDS SYNDICATE ARE TOO BIG FOR ME TO HANDLE ALONE. THEY KNOW ALMOST EVERYTHING ABOUT ME, AND I KNOW NEXT TO NOTHING ABOUT THEM. IF I STAY HERE TO FIGHT, THEN IT IS ONLY A MATTER OF TIME UNTIL THEY REALISE I AM ON TO THEM. IF I HAVEN’T DISAPPEARED BEFORE THEN, THEN I HAVE A FEELING THEY WILL MAKE ME DISAPPEAR.\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(affine_decipher(c2b, key_b[0], key_b[1], key_b[2]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "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.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 1
+}