{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5c19999b", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "from szyfrow.caesar import *\n", "from szyfrow.affine import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "d9dd1b5e", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "challenge_number = 2\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, "id": "0f1f792a", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "ca = open(ciphertext_a_filename).read()\n", "cb = open(ciphertext_b_filename).read()" ] }, { "cell_type": "code", "execution_count": 8, "id": "b3da7c78", "metadata": { "Collapsed": "false" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "9 23 True \n", "\n", "Jodie, you were not placed with the Archaeologists as a punishment; everyone takes their turn on that shift because we never know what might turn up in old documents. When I ran the group, we found evidence of a Russian agent placed in the SDECE in the aftermath of the war who was acting as liaison with British and US intelligence. She had remained undiscovered for thirty-five years and leaked a whole load of information across the iron curtain. The team cracked a Fialka cipher from 1956, and that led to an arrest and confession. I admit that the case you are working on doesn’t seem likely to have the same impact, but you never know where it might lead. I took a look at the papers you sent, and I thought this one looked very interesting. The information it contains ties down the year it was written pretty conclusively, and I have to say I don’t like the sound of the phrase “profit from the Schleswig conflict”. I think it is clear who M must be, but I am still unsure about the others mentioned in these letters. I am also very unclear why M might have been involved in what looks like a conspiracy aimed at wartime profiteering. I checked, and there is nothing on file from the period to suggest that this was suspected. Indeed there was nothing on file at all, which, thinking about it is slightly strange. M was a public figure and of definite interest, so there should be something. If you have time it might be worth logging in to the records system to see if anyone else from around then has a suspiciously empty file. I would start with public figures who have the initials CH or FN, as the single letters A, T, E and W don’t give us much to go on. Of course, we do know a little more about W, so that might also be a good place to start. We know we are looking for an engineer with initial W, who knows something about codes and ciphers. Whoever FN is, they are right that they should talk to W. Using Caesar and affine shift ciphers to encode their secret communications is poor, and I would have expected better from an organisation containing M. Perhaps they will have taken the mysterious W’s advice and will have switched to something more secure in their future communications. That will make life a little more interesting for you and the team. Good luck, Harry\n", "\n" ] } ], "source": [ "(m_a, a_a, z_a), score_a = affine_break(ca)\n", "print(m_a, a_a, z_a, '\\n')\n", "pa = affine_decipher(ca, m_a, a_a, z_a)\n", "print(pa)" ] }, { "cell_type": "code", "execution_count": 9, "id": "6cecddd9", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "2290" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_a_filename, 'w').write(pa)" ] }, { "cell_type": "code", "execution_count": 11, "id": "83a50584", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11 9 True \n", "\n", "My dearest M,\n", "Can it really be sixteen years since Caroline first proposed this venture? I cannot believe it and wish with all my heart that she could have seen her vision taking shape.\n", "Last Wednesday I took the opportunity you so kindly offered to see the progress with the foundation for myself. I was very encouraged by the industry on display, however I left with a concern that we may have miscalculated in our plans to hide the facility in the basement of the building. The ventilation there will, of necessity, be far more restricted than it would be on the upper floors, as I know from my own research. The evidence from your experiments suggests that our device will produce a very large amount of heat in operation. I cannot say for sure, but it seems likely that this will cause problems, both for the device itself and for its operators.\n", "Looking at the plans, I wondered briefly if we could hide it instead on an upper floor of the lighthouse, but you are likely to have many visitors who are inclined to curiosity, and I suspect the secret would not stay safe for long. We cannot take any risk that might expose us, and even if we keep it behind a locked door, the noise it will generate in operation will propagate more easily across the wharf, leading to questions. In the basement we can at least suppress the noise, reducing that risk, but that leaves the issue of managing the heat.\n", "I am at a loss. Any changes we want to make to the design of the laboratory and its facilities will need to be made very soon, as once the upper floors are built further heavy construction would attract unwanted attention. Perhaps W will be able to suggest something; he is, after all, an engineer. in any case, I was planning to ask him to join us as head of security. I understand that he has some rather interesting ideas about codes and ciphers.\n", "\n", "On a less pressing matter, our first experiments with the prototype are showing some success. If we had been able to run them earlier this year, we may even have been able to profit from the Schleswig conflict, and it may not be too late to do so if we can mobilise our agents. There is much to play for here. Others will be seeking to gain from the conflict, and I see no reason why we cannot do so too.\n", "Ever yours,\n", "FN\n", "\n" ] } ], "source": [ "(m_b, a_b, z_b), score_a = affine_break(cb)\n", "print(m_b, a_b, z_b, '\\n')\n", "pb = affine_decipher(cb, m_b, a_b, z_b)\n", "print(pb)" ] }, { "cell_type": "code", "execution_count": 12, "id": "d12a663c", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "2272" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open(plaintext_b_filename, 'w').write(pb)" ] }, { "cell_type": "code", "execution_count": null, "id": "504ec2e2", "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }