{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "from szyfrow.caesar import *\n", "from szyfrow.affine import *" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "challenge_number = 1\n", "plaintext_a_filename = f'plaintext.{challenge_number}a.txt'\n", "plaintext_b_filename = f'plaintext.{challenge_number}b.txt'\n", "ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt'\n", "ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ca = open(ciphertext_a_filename).read()\n", "cb = open(ciphertext_b_filename).read()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "14 \n", "\n", "The British Daily Herald article on so called spyclists has raised concern at government levels that the large increase in travel from the Continent has masked an infiltration operation by the Abwehr.\n", "SIS has received reports that Hitler Youth groups travelling abroad have been asked to complete a detailed questionnaire, including questions on terrain, population, and political views of the population. VK has taken a personal interest in the story but his resources are fully allocated in investigating a number of suspected German agents already living in the UK, so BOSS has been tasked with investigating and reporting on the spyclist touring network.\n", "Harry is currently engaged investigating Die Alchemisten so he has asked our team to take this on. While it is possible that the cycle tourists are operating as a forward observer division in preparation for a future invasion, the small numbers involved, and their travel routes make it seem likely that this is at most a feint designed to draw our resources away from more significant operations. What we do know is that there is an intelligence dimension to this since our operatives in the GPO intercepted the attached encrypted message in a bundle of letters left poste restante for one of the touring parties at a Scottish post office. Our first task is to decipher this message and to analyse its contents. Even if this turns out to be a diversionary tactic it provides us with an opportunity to develop our BOSS home intelligence operation and we will be treating the mission seriously. Operatives from all three BOSS divisions will be working together at the Broadway to intercept, decipher and analyse potentially relevant sources. We will be posting updates here in the mission pages using standard protocols. Since our communications are protected we will, for now, use tier one (Caesar and affine shift) encryption. Your field issue cipher wheel is attached, and your first task is to decipher the attached message and to study it carefully.\n", "Pearl.\n", "\n" ] } ], "source": [ "k_a, score_a = caesar_break(ca)\n", "print(k_a, '\\n')\n", "pa = caesar_decipher(ca, k_a)\n", "print(pa)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "2020" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_a_filename, 'w').write(pa)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "6 \n", "\n", "My dear Jessica, I am writing to wish you well in your new life. I am sure you will not forget us, and you can be sure that we will not forget you. May your business flourish to the great benefit of us all. You might be concerned that with the growing uncertainty in the homeland we will find it difficult to continue to communicate, but love will find a way, and I am sure you love your homeland as much as we do. We trust that our effort to stay in touch will be rewarded by an equal effort on your part. I hope that my nephew Karl, who brings you this message, will be able to help you further with these matters. In the meantime, perhaps you can help him. He is a great lover of trains, canal boats and aeroplanes, and it would be a great kindness if you would agree to help him to explore some of the many transport treasures hidden across the UK. It is an unusual passion but I hope that you will feel able to assist him in this. He is particularly keen to explore the possibility of photographing as many of the intriguing travel sites as he can. I seem to recall that Uncle Wilhelm introduced you to the fascinating hobby of photographic reproduction when you stayed with his family in Tirpitzufer. If you were able to assist Karl by developing his films and forwarding them to his home that would, I am sure, avoid unnecessary delay and a great deal of unpleasant misunderstanding. If there is any way we can assist you in your valuable work please let Karl know and we will endeavour to oblige you. Your dear friend, Nikolaus R.\n", "\n" ] } ], "source": [ "k_b, score_b = caesar_break(cb)\n", "print(k_b, '\\n')\n", "pb = caesar_decipher(cb, k_b)\n", "print(pb)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "1539" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_b_filename, 'w').write(pb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "Collapsed": "false" }, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,md" }, "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.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }