{ "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.keyword_cipher import *\n", "from cipher.vigenere import *\n", "from support.utilities import *\n", "from support.text_prettify import *\n", "\n", "c5a = open('5a.ciphertext').read()\n", "c5b = open('5b.ciphertext').read()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(('cornfield', ), -1557.5551917175146)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(key_a_word, key_a_wrap), score = keyword_break_mp(c5a)\n", "(key_a_word, key_a_wrap), score" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "harry, i checked out who transcribed the radio transmission like you asked. it was a junior cipher clerk in room 5. i would have offered to set up a meeting with her, but she has disappeared and hasn’t been seen since last friday. the marines saw her leave at her usual time, and she was booked out for some leave on monday and tuesday so no one noticed she was missing until today. we sent an officer out to her usual haunts and i will get back to you if we find anything. what made you ask? did you have a reason to believe she was involved in something? \n", "\n", "i took another look at the messages. were you referring to the typos? the word ratlines keeps being spelt as ratilines. is that important? what did you mean about our source being close to home? \n", "\n", "also did some digging about the reichsdoktor. seems you were right and it refers to an underground nazi organisation dedicated to rebuilding the reich. maybe they think of it as healing? a bunch of rich nazi sympathisers took over the ratlines from a group of ss officers who set them up at the tail of the war and have been active in shipping scientists, engineers and soldiers to towns across south america. if our source has inside information then maybe we could intercept the lines and pick up some of the high value targets the french are after. what was “die alchemisten project”? \n", "\n", "the enclosed message was handed to the marines, but they didn’t get a name. initial analysis shows it must be a vigenere cipher with period two so it should be reasonably straightforward to crack. \n", "\n", "all the best, charlie \n", "\n" ] } ], "source": [ "print(keyword_decipher(c5a, key_a_word, wrap_alphabet=key_a_wrap))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('de', -885.6842458313828)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "key_b, score = vigenere_frequency_break(c5b, max_key_length=2)\n", "key_b, score" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the first item in our little auction will be the location of a safehouse in the uk sector of berlin it is a minor stopover on the rat lines but you never know you might get lucky and find someone interesting hiding there at the very least you will inconvenience the reichs doktor if you take possession of it how much would that be worth to you do i hear a bid of five hundred thousand francs from our french friends perhaps the british would pay more or maybe they can not afford to i wonder how they feel about that perhaps you should ask them if you want to outbid your so called friends then leave the money in unmarked treasury bills in locker at the far end of the platform in friedrichstrasse i will leave the details in locker you will find the key in do not try to double cross me it will not work and our little game will end before it has even properly begun\n" ] } ], "source": [ "print(' '.join(segment(sanitise(vigenere_decipher(sanitise(c5b), key_b)))))" ] }, { "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 }