--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "5c19999b",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [],
+ "source": [
+ "from szyfrow.caesar import *\n",
+ "from szyfrow.affine import *\n",
+ "from szyfrow.keyword_cipher import *\n",
+ "from szyfrow.support.text_prettify import *"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "d9dd1b5e",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [],
+ "source": [
+ "challenge_number = 3\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": 14,
+ "id": "0f1f792a",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [],
+ "source": [
+ "ca = open(ciphertext_a_filename).read()\n",
+ "cb = open(ciphertext_b_filename).read()\n",
+ "\n",
+ "scb = sanitise(cb)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "c3cccd86-5e40-4040-8f91-9ca53ac6e909",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "lighthouse KeywordWrapAlphabet.from_last \n",
+ "\n",
+ "harry, thanks for your email, i forgot you had spent time here in the archaeologists and it was good to be reminded that it can lead somewhere. in this case i think the best we can hope for is that we will have a new bunch of recruits trained and ready to tackle more serious challenges, but i have to admit that i am getting more excited about this case, even if it is just a training exercise.\n",
+ "the attached memo from abc reinforces what we learned from the last one. the lighthouse conspiracy seems to be a group of influential victorians who are aiming to use their newfound technological prowess to profit from war, famine, pestilence, and any other disturbance in the force. i don’t like to jump to conclusions, but i can’t help noticing that the initials coincide with people of interest to boss. i checked faraday’s intelligence file and as you say, it was empty. it is hard to believe that a scientist of his eminence had escaped notice, so it seems more likely that the real file has either been deleted or stored somewhere more secure. perhaps you can make enquiries? b must surely be babbage. all the talk in the attached letter is about a device that sounds like a computer, and that would mean that al is ada lovelace, who died some years before this letter was written. i can’t be sure who w or n are, but my guess is that this n is the same person as fn in the previous letter. as for abc, i have a guess, but it all seems rather fantastical. al and b appear in some of the earliest boss files, and i always assumed they were on the side of the angels. could they have been double agents working for boss inside the conspiracy? given that it is their work that seems to be driving it on, it seems more likely that the reverse is true. but that means boss was riddled with domestic insurgents from the start. i don’t think this has the same urgency as your discovery of soviet agents at the heart of british intelligence, but it is still rather alarming.\n",
+ "as is the increasing sophistication of our protagonists’ communications. they are still only relying on substitution ciphers, but their head of security, w, is clearly smart enough to know that this is too weak for serious use, and i suspect that future letters will be protected by something more professional. i wonder if he will push them to think about using polyalphabetic ciphers, or if he will just introduce simple changes like blocking the ciphertext.\n",
+ "i think it might pay for me to make a trip to london to carry out some enquiries, so i may be off grid for a couple of weeks. let me know if you hear anything useful.\n",
+ "all the best,\n",
+ "jodie.\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "(word_a, wrap_a), score_a = keyword_break(ca)\n",
+ "print(word_a, wrap_a, '\\n')\n",
+ "pa = keyword_decipher(ca, word_a, wrap_a)\n",
+ "print(pa)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "6cecddd9",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2618"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_a_filename, 'w').write(pa)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "86085f32-1564-4f01-8d58-2786625a743f",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "baker KeywordWrapAlphabet.from_last \n",
+ "\n",
+ "my dear miss n while the outbreak of the austro prussian war has dismayed many of the chattering\n",
+ "classes i have found utter delight in the fact that we were able to forecast this development the\n",
+ "fact that we were able to do so not days or weeks but months in advance is the proof that we have\n",
+ "been seeking that our methods combined with the power of professor bs new device can deliver the\n",
+ "knowledge we need to shape our destiny the new statistical tools that you have pioneered can i\n",
+ "believe assist us in modelling further outbreaks of violence and unrest if you will allow me to mix\n",
+ "metaphors while we will not always be able to predict the onset of disease we can hope to predict\n",
+ "its course and thereby profit the device at trinity wharf is now working at full capacity and our\n",
+ "colleagues tell me that it can compute anything we ask of it given enough time and space in which to\n",
+ "record the answers of course these practical men did not think to ask how much time any particular\n",
+ "question might take before we can receive its answer but i think this is a calculation that i can\n",
+ "leave to you before she was taken from us al wrote extensive notes on the potential of the device\n",
+ "and i suspect you will find the answers there in in the current context the machine provided with\n",
+ "diplomatic intelligence by our network of agents in europe took five weeks to calculate the\n",
+ "likelihood that bismarck would launch his offensive and to use the weather data gathered by ws\n",
+ "telegraphic network to suggest when the attack would be launched we had little agency in the\n",
+ "conflict itself but we were able to advise our sympathisers in government and thereby to expand our\n",
+ "influence our intelligence analysts are now working to determine the likely progression of the\n",
+ "conflict in the hope of finding new ways to profit from it in mentioning wi realise that i forgot to\n",
+ "pass on his advice concerning security he has convinced me that our current policy of communicating\n",
+ "via substitution ciphers really is not sufficient to conceal our intentions as our network expands\n",
+ "the risk of leaks increase she is working on a new and considerably more fiendish cipher to be used\n",
+ "for our most delicate secrets and i hope to hear more about his progress on that when i meet him\n",
+ "next month maxwell will be delivering the baker ian lecture and he is hoping to attend i did wonder\n",
+ "if m would be amenable to joining our conspiracy but perhaps i should discuss that with the rest of\n",
+ "the curia i look forward to hearing your deliberations on the efficiency of the device and any\n",
+ "thoughts you might have on its development best wishes abc\n"
+ ]
+ }
+ ],
+ "source": [
+ "(word_b, wrap_b), score_a = keyword_break(scb, fitness=Ptrigrams)\n",
+ "print(word_b, wrap_b, '\\n')\n",
+ "pb = keyword_decipher(scb, word_b, wrap_b)\n",
+ "print(prettify(pb))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "id": "d12a663c",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2600"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "open(plaintext_b_filename, 'w').write(prettify(pb))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "504ec2e2",
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "jupytext": {
+ "formats": "ipynb,md"
+ },
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "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
+}
--- /dev/null
+---
+jupyter:
+ jupytext:
+ formats: ipynb,md
+ text_representation:
+ extension: .md
+ format_name: markdown
+ format_version: '1.3'
+ jupytext_version: 1.11.1
+ kernelspec:
+ display_name: Python 3 (ipykernel)
+ language: python
+ name: python3
+---
+
+```python Collapsed="false"
+from szyfrow.caesar import *
+from szyfrow.affine import *
+from szyfrow.keyword_cipher import *
+from szyfrow.support.text_prettify import *
+```
+
+```python Collapsed="false"
+challenge_number = 3
+plaintext_a_filename = f'plaintext.{challenge_number}a.txt'
+plaintext_b_filename = f'plaintext.{challenge_number}b.txt'
+ciphertext_a_filename = f'ciphertext.{challenge_number}a.txt'
+ciphertext_b_filename = f'ciphertext.{challenge_number}b.txt'
+```
+
+```python Collapsed="false"
+ca = open(ciphertext_a_filename).read()
+cb = open(ciphertext_b_filename).read()
+
+scb = sanitise(cb)
+```
+
+```python
+(word_a, wrap_a), score_a = keyword_break(ca)
+print(word_a, wrap_a, '\n')
+pa = keyword_decipher(ca, word_a, wrap_a)
+print(pa)
+```
+
+```python Collapsed="false"
+open(plaintext_a_filename, 'w').write(pa)
+```
+
+```python
+(word_b, wrap_b), score_a = keyword_break(scb, fitness=Ptrigrams)
+print(word_b, wrap_b, '\n')
+pb = keyword_decipher(scb, word_b, wrap_b)
+print(prettify(pb))
+```
+
+```python Collapsed="false"
+open(plaintext_b_filename, 'w').write(prettify(pb))
+```
+
+```python Collapsed="false"
+
+```
--- /dev/null
+my dear miss n while the outbreak of the austro prussian war has dismayed many of the chattering
+classes i have found utter delight in the fact that we were able to forecast this development the
+fact that we were able to do so not days or weeks but months in advance is the proof that we have
+been seeking that our methods combined with the power of professor bs new device can deliver the
+knowledge we need to shape our destiny the new statistical tools that you have pioneered can i
+believe assist us in modelling further outbreaks of violence and unrest if you will allow me to mix
+metaphors while we will not always be able to predict the onset of disease we can hope to predict
+its course and thereby profit the device at trinity wharf is now working at full capacity and our
+colleagues tell me that it can compute anything we ask of it given enough time and space in which to
+record the answers of course these practical men did not think to ask how much time any particular
+question might take before we can receive its answer but i think this is a calculation that i can
+leave to you before she was taken from us al wrote extensive notes on the potential of the device
+and i suspect you will find the answers there in in the current context the machine provided with
+diplomatic intelligence by our network of agents in europe took five weeks to calculate the
+likelihood that bismarck would launch his offensive and to use the weather data gathered by ws
+telegraphic network to suggest when the attack would be launched we had little agency in the
+conflict itself but we were able to advise our sympathisers in government and thereby to expand our
+influence our intelligence analysts are now working to determine the likely progression of the
+conflict in the hope of finding new ways to profit from it in mentioning wi realise that i forgot to
+pass on his advice concerning security he has convinced me that our current policy of communicating
+via substitution ciphers really is not sufficient to conceal our intentions as our network expands
+the risk of leaks increase she is working on a new and considerably more fiendish cipher to be used
+for our most delicate secrets and i hope to hear more about his progress on that when i meet him
+next month maxwell will be delivering the baker ian lecture and he is hoping to attend i did wonder
+if m would be amenable to joining our conspiracy but perhaps i should discuss that with the rest of
+the curia i look forward to hearing your deliberations on the efficiency of the device and any
+thoughts you might have on its development best wishes abc
\ No newline at end of file