{ "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) \n", "\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "from cipher.affine import *\n", "from support.utilities import *\n", "from support.text_prettify import *\n", "\n", "c3a = open('3a.ciphertext').read()\n", "c3b = open('3b.ciphertext').read()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((3, 5, True), -901.37737042341)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(key_a_m, key_a_a, key_a_o), score = affine_break(c3a)\n", "(key_a_m, key_a_a, key_a_o), score" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "HARRY, THE PUZZLE OF THE STAMPED POSTCARD HAD ME FOOLED FOR A WHILE, BUT I THINK I FIGURED IT OUT. WAS THE MESSAGE ON THE BACK OF THE STAMP? I AM GUESSING YOU STEAMED IT OFF AND FOUND IT THERE. IT WAS A PRETTY INGENIOUS PLOY. MY MASTERS BACK IN WASHINGTON ARE INCREASINGLY WORRIED ABOUT OUR RELATIONSHIP WITH THE REST OF THE FOUR POWERS. FOLLOWING THE BREAKDOWN IN TRUST WITH THE SOVIETS THEY ARE COUNTING ON THE UK AND FRANCE AS ALLIES. IF THEY ARE GOING BEHIND OUR BACKS WITH THIS REICHSDOKTOR, THAT DOES NOT BODE WELL FOR FUTURE DIPLOMACY. DO YOU HAVE CONTACTS THERE YOU CAN EXPLOIT TO FIND OUT WHAT THEY ARE INTENDING? WE REALLY CANNOT AFFORD TO FALL OUT RIGHT NOW. THE ATTACHED MESSAGE IS ANOTHER INTERCEPT, THIS TIME FROM THE BRITISH EMBASSY WIRELESS. WHILE THINGS ARE DICEY I DON’T FEEL I CAN ASK THEM ABOUT IT, MAYBE YOU COULD CRACK IT FOR US. DOES IT MENTION THE RATLINES? BEST, CHARLIE\n", "\n" ] } ], "source": [ "print(affine_decipher(c3a, multiplier=key_a_m, adder=key_a_a, one_based=key_a_o))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((5, 7, True), -574.5522852453349)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(key_b_m, key_b_a, key_b_o), score = affine_break(c3b)\n", "(key_b_m, key_b_a, key_b_o), score" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eyes only rumours of a source in berlin with access to the rat lines source seems to go by name of reichs doktor russian intercepts suggest has been seen in vicinity of us embassy not clear how to make direct contact also not clear why our us friends are keeping this to themselves detailed info about rat i lines hard to obtain but high value could lead to arrest of major targets of nuremberg investigations vital we reach reichs doktor at earliest opportunity discreet enquiries in french and us sectors only request funds for further investigation\n" ] } ], "source": [ "print(' '.join(segment(sanitise(affine_decipher(c3b, multiplier=key_b_m, adder=key_b_a, one_based=key_b_o)))))" ] }, { "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.6.3" } }, "nbformat": 4, "nbformat_minor": 1 }