{ "cells": [ { "cell_type": "code", "execution_count": 7, "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 cipher.caesar import *\n", "from support.utilities import *\n", "from support.text_prettify import *\n", "\n", "c1a = open('1a.ciphertext').read()\n", "c1b = open('1b.ciphertext').read()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "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": {}, "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": {}, "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": 5, "metadata": {}, "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": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c1b" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "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": 9, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "[1, 5, 7, 15, 18, 23, 28, 33, 34, 40]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nonletters = [i for i in range(len(c1b)) if c1b[i] not in string.ascii_letters]\n", "nonletters[:10]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'icantbelieveheleftlikethataftereverythingwesaidaftereverythingweagreedbuthehasgoneandicantfindhimandthisistoobigtodealwithaloneicantblamehimmorethanmewewerebothblindtowhatwashappeningandwearebothguiltybuttogetherwemighthavestartedtofixiticantseehowicandothataloneherenowsoidonthaveanoptionithastoendihavetoendit'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p1bs = cat(reversed(sanitise(caesar_decipher(c1b, key_b))))\n", "p1bs" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"i can't believe he left like that. after everything we said, after everything we agreed. but he has gone, and i can't find him, and this is too big to deal with alone. i can't 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. i can't see how i can do that alone, here, now. so i don't have an option. it has to end. i have to end it.\\n\"" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p1b = p1bs\n", "for i in nonletters:\n", " p1b = p1b[:i] + c1b[i] + p1b[i:]\n", "p1b" ] }, { "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.6.3" } }, "nbformat": 4, "nbformat_minor": 1 }