From c5d8bb8e681e2621d9552ff8c99bd7cb37607787 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 23 Apr 2020 09:22:09 +0100 Subject: [PATCH] Done challenge 4 --- 2020-early/2020-a-challenge1.ipynb | 3 + 2020-early/2020-a-challenge1.md | 66 ++++++ 2020-early/2020-a-challenge2.ipynb | 3 + 2020-early/2020-a-challenge2.md | 77 +++++++ 2020-early/2020-a-challenge3.ipynb | 3 + 2020-early/2020-a-challenge3.md | 84 +++++++ 2020-early/2020-a-challenge4.ipynb | 337 +++++++++++++++++++++++++++++ 2020-early/2020-a-challenge4.md | 109 ++++++++++ 2020-early/4a.ciphertext | 1 + 2020-early/4a.plaintext | 14 ++ 2020-early/4b.ciphertext | 7 + 2020-early/4b.plaintext | 7 + 12 files changed, 711 insertions(+) create mode 100644 2020-early/2020-a-challenge1.md create mode 100644 2020-early/2020-a-challenge2.md create mode 100644 2020-early/2020-a-challenge3.md create mode 100644 2020-early/2020-a-challenge4.ipynb create mode 100644 2020-early/2020-a-challenge4.md create mode 100644 2020-early/4a.ciphertext create mode 100644 2020-early/4a.plaintext create mode 100644 2020-early/4b.ciphertext create mode 100644 2020-early/4b.plaintext diff --git a/2020-early/2020-a-challenge1.ipynb b/2020-early/2020-a-challenge1.ipynb index 4834440..e12b2dd 100644 --- a/2020-early/2020-a-challenge1.ipynb +++ b/2020-early/2020-a-challenge1.ipynb @@ -150,6 +150,9 @@ } ], "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, "kernelspec": { "display_name": "Python 3", "language": "python", diff --git a/2020-early/2020-a-challenge1.md b/2020-early/2020-a-challenge1.md new file mode 100644 index 0000000..c2a0301 --- /dev/null +++ b/2020-early/2020-a-challenge1.md @@ -0,0 +1,66 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python +import os,sys,inspect +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0,parentdir) +``` + +```python +from cipher.caesar import * +from cipher.affine import * +``` + +```python +challenge_number = 1 +plaintext_a_filename = f'{challenge_number}a.plaintext' +plaintext_b_filename = f'{challenge_number}b.plaintext' +ciphertext_a_filename = f'{challenge_number}a.ciphertext' +ciphertext_b_filename = f'{challenge_number}b.ciphertext' +``` + +```python +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +``` + +```python +k_a, score_a = caesar_break(ca) +print(k_a, '\n') +pa = caesar_decipher(ca, k_a) +print(pa) +``` + +```python +open(plaintext_a_filename, 'w').write(pa) +``` + +```python +k_b, score_b = caesar_break(cb) +print(k_b, '\n') +pb = caesar_decipher(cb, k_b) +print(pb) +``` + +```python +open(plaintext_b_filename, 'w').write(pb) +``` + +```python + +``` diff --git a/2020-early/2020-a-challenge2.ipynb b/2020-early/2020-a-challenge2.ipynb index 385076c..93a980b 100644 --- a/2020-early/2020-a-challenge2.ipynb +++ b/2020-early/2020-a-challenge2.ipynb @@ -152,6 +152,9 @@ } ], "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, "kernelspec": { "display_name": "Python 3", "language": "python", diff --git a/2020-early/2020-a-challenge2.md b/2020-early/2020-a-challenge2.md new file mode 100644 index 0000000..b20f25e --- /dev/null +++ b/2020-early/2020-a-challenge2.md @@ -0,0 +1,77 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python +import os,sys,inspect +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0,parentdir) +``` + +```python +from cipher.caesar import * +from cipher.affine import * + +from support.text_prettify import * +from support.utilities import * +from support.plot_frequency_histogram import * +``` + +```python +challenge_number = 2 +plaintext_a_filename = f'{challenge_number}a.plaintext' +plaintext_b_filename = f'{challenge_number}b.plaintext' +ciphertext_a_filename = f'{challenge_number}a.ciphertext' +ciphertext_b_filename = f'{challenge_number}b.ciphertext' +``` + +```python +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +pca = letters(ca) +pta = depunctuate(ca) + +scb = sanitise(cb) +pcb = letters(cb) +ptb = depunctuate(cb) +``` + +```python +(ma, ca, za), score_a = affine_break(sca) +print((ma, ca, za), '\n') +pa = repunctuate(affine_decipher(sca, ma, ca, za), pta) +print(pa) +``` + +```python +open(plaintext_a_filename, 'w').write(pa) +``` + +```python +(mb, cb, zb), score_a = affine_break(scb) +print((mb, cb, zb), '\n') +pb = repunctuate(affine_decipher(scb, mb, cb, zb), ptb) +print(pb) +``` + +```python +open(plaintext_b_filename, 'w').write(pb) +``` + +```python + +``` diff --git a/2020-early/2020-a-challenge3.ipynb b/2020-early/2020-a-challenge3.ipynb index 0c65ac3..51f0764 100644 --- a/2020-early/2020-a-challenge3.ipynb +++ b/2020-early/2020-a-challenge3.ipynb @@ -189,6 +189,9 @@ } ], "metadata": { + "jupytext": { + "formats": "ipynb,md" + }, "kernelspec": { "display_name": "Python 3", "language": "python", diff --git a/2020-early/2020-a-challenge3.md b/2020-early/2020-a-challenge3.md new file mode 100644 index 0000000..46a1a98 --- /dev/null +++ b/2020-early/2020-a-challenge3.md @@ -0,0 +1,84 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python +import os,sys,inspect +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0,parentdir) +``` + +```python +from cipher.caesar import * +from cipher.affine import * +from cipher.keyword_cipher import * + +from support.text_prettify import * +from support.utilities import * +from support.plot_frequency_histogram import * +``` + +```python +challenge_number = 3 +plaintext_a_filename = f'{challenge_number}a.plaintext' +plaintext_b_filename = f'{challenge_number}b.plaintext' +ciphertext_a_filename = f'{challenge_number}a.ciphertext' +ciphertext_b_filename = f'{challenge_number}b.ciphertext' +``` + +```python +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +pca = letters(ca) +pta = depunctuate(ca) + +scb = sanitise(cb) +pcb = letters(cb) +ptb = depunctuate(cb) +``` + +```python +(kworda, kwrapa), score = keyword_break_mp(sca, fitness=Ptrigrams) +kworda, kwrapa +``` + +```python +pa = keyword_decipher(ca, kworda, kwrapa) +print(pa) +``` + +```python +open(plaintext_a_filename, 'w').write(pa) +``` + +```python +(kwordb, kwrapb), score = keyword_break_mp(scb, fitness=Ptrigrams) +kwordb, kwrapb +``` + +```python +pb = keyword_decipher(cb, kwordb, kwrapb) +print(pb) +``` + +```python +open(plaintext_b_filename, 'w').write(pb) +``` + +```python + +``` diff --git a/2020-early/2020-a-challenge4.ipynb b/2020-early/2020-a-challenge4.ipynb new file mode 100644 index 0000000..aa14210 --- /dev/null +++ b/2020-early/2020-a-challenge4.ipynb @@ -0,0 +1,337 @@ +{ + "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) " + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "from cipher.caesar import *\n", + "from cipher.affine import *\n", + "from cipher.keyword_cipher import *\n", + "\n", + "from support.text_prettify import *\n", + "from support.utilities import *\n", + "from support.plot_frequency_histogram import *\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "challenge_number = 4\n", + "plaintext_a_filename = f'{challenge_number}a.plaintext'\n", + "plaintext_b_filename = f'{challenge_number}b.plaintext'\n", + "ciphertext_a_filename = f'{challenge_number}a.ciphertext'\n", + "ciphertext_b_filename = f'{challenge_number}b.ciphertext'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "ca = open(ciphertext_a_filename).read()\n", + "cb = open(ciphertext_b_filename).read()\n", + "\n", + "sca = sanitise(ca)\n", + "pca = letters(ca)\n", + "pta = depunctuate(ca)\n", + "\n", + "scb = sanitise(cb)\n", + "pcb = letters(cb)\n", + "ptb = depunctuate(cb)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kshifta, score = caesar_break(sca, fitness=Ptrigrams)\n", + "kshifta" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "philmyvisittomeitnersgroupwasveryinterestingandpaidoffinanunexpectedwayasyoususpectednuclearenergyhasseriouspotentialandthereareanumberofgroupsworkingtorealisethatoneofmeitnerscollaboratorshasbeenincontactwithagroupofdissidentgermanscientistsclosetoeinsteinandtheyhavebeenpassingintelligenceconcerningthenazinuclearprogrammetotheswedishteamwhileiwasthereoneoftheircontactsinberlinsmuggledoutacopyofalettersentbythescientistsjoosandhanletowilhelmdamesatthereichserziehungsministeriumitoutlinesthepotentialmilitaryapplicationsofnuclearenergyandapparentlytheministerwassoimpressedbyitscontentsthatwithinaweekhehadconvenedatoplevelgrouptodeveloptheideaswithinitthebossteaminberlinhaverampedupmonitoringofcommunicationstoandfromtheministryandthemostpromisingleadistheattachedmemotheenvelopewasmarkeddiealchemisteniamnotsurehowfreeyouaretotravelbutihavetomeetupwithmynewnorwegianfriendsandthenheadbacktoenglandcouldyoumoveyourbasetofranceandmakecontactwithsomeofouralliesithinkweshouldopendiscussionswiththefrenchministerofarmamentswearegoingtoneedhishelpharry\n" + ] + } + ], + "source": [ + "pa = caesar_decipher(sca, kshifta)\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "phil my visit to meitner s group was very interesting and paid off in an unexpected way as you\n", + "suspected nuclear energy has serious potential and there area number of groups working to realise\n", + "that one of meitner s collaborators has been in contact with a group of dissident german scientists\n", + "close to einstein and they have been passing intelligence concerning the nazi nuclear programme to\n", + "the swedish team while i was there one of their contacts in berlin smuggled out a copy of a letter\n", + "sent by the scientists joos and hanle to wilhelm dames at the reichs erziehung s ministerium it\n", + "outlines the potential military applications of nuclear energy and apparently the minister was so\n", + "impressed by its contents that within a week he had convened a toplevel group to develop the ideas\n", + "within it the boss team in berlin have ramped up monitoring of communications to and from the\n", + "ministry and the most promising lead is the attached memo the envelope was marked die alchemist en i\n", + "am not sure how free you are to travel but i have to meetup with my new norwegian friends and then\n", + "head back to england could you move your base to france and make contact with some of our allies i\n", + "think we should open discussions with the french minister of armaments we are going to need his help\n", + "harry\n" + ] + } + ], + "source": [ + "fpa = lcat(tpack(segment(pa)))\n", + "print(fpa)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1283" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(fpa)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa0AAAEiCAYAAABKsI06AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAVX0lEQVR4nO3df7BkZX3n8fcngAoYAz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QP0eRXwauDlVfVwks/Re7z2q5/H9c5g2MfqsI+TDNO3qv4hycuA1wH/Oclnqur3++z+IL0Tm7+C3ovefn0UeAu9x9yGAfqNxUqeaV0D/HKS3btX3G8YoN/xSfZIsifwy/T36vzvgDd070s9Gxj0+0vWA78HXAi8f8C+w/gevd2Yg7oKOCHJvgBJ9knygrFWNh7XAKd3v78AvA24qZuJ9uPAJC/vLp9M7/6dpGHHu5jeadJOoBdgfeme6E6n9yr78QHq/Al6M7qHk/wUvV2x6hn2OQd6/1f/Jslzofd/1U+nJM8HHq6qj9N7e+GwAcZ8FDgeOCXJrwzQ75PAMcDh9M56tEOt2JlWVW1K8uf03mf6Gn3uFur6nU/vfRCAj3a7YZbq9+UklwM3d+NtpPdKZklJTgG2V9X/7A5q+GKSo6rqs/30H0ZVfas7aGMz8FdV9e/77Hdbkv8IfCa9o79+AJxG7zbvTL4AvBf4UlU9lOT/0f+uQejNyNYm+TN670+eO4EaRx6vqrZ0T5Bfr6r7Bxjv7fRm91cngd7JT3+9j35/DbwtyS303oPZkbv6duozIQz7nNP13ZLkbODzSR6j9z7TW/ro+jPAB5I8Tu9/8TcGrPmhJK8HrkzyUFVd1kefR7sDd75bVY8NMt44TM0ZMZK8j94bsh+c4BjPrqrvd0d+XQOsq6pNkxpPk5FkFvjLqvqRR3Bqx+lmIJuqamec1U+V7sXqJuDEqrpjR4+/kncPLof13cEJm4C/MLCk0XW7wL5Eb/eXllGSQ+gdFXnVcgQWTNFMS5LUPmdakqRmGFqSpGYYWpKkZhhakqRmGFqSpGYYWpKkZvx/PR4TjNTDCOAAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "fc = collections.Counter(scb)\n", + "plot_frequency_histogram(fc, sort_key=fc.get)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('yerkes', )" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(kwordb, kwrapb), score = keyword_break_mp(scb, fitness=Ptrigrams)\n", + "kwordb, kwrapb" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'heavywtrsqxzbcdfgijklmnopu'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kwordb, score = simulated_annealing_break(scb, fitness=Ptrigrams)\n", + "kwordb" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first meeting of die alchemisten committee, reichserjiehungsministerium, twenty ninth april nineteen thirty nine\n", + "the committee was reconvened by the minister at the request of the chancellor himself.\n", + "it is tasked with realising the military and industrial promise of nuclear energy.\n", + "the committee recognises the technical challenges involved in industrialising the processes hitherto conducted under laboratory conditions, but feels that the obstacles can be overcome by a combination of scientific and engineering excellence already possessed by the state.\n", + "the committee identified that the principle issue is that of controlling the nuclear reaction which is mediated by the energy of free neutrons. these need to be slowed to effectively harness their power, and to this end the committee recommends the acquisition of a suitable moderator.\n", + "the best-known candidate is deuterium and the best source of this material is the power plant at vemork in norway. the tronstad and brun electrolytic process at that facility is producing over twenty kilograms of heavy water per year, and this could easily be scaled up.\n", + "since we do not want to alert our enemies to the importance of the material the committee recommends placing an initial order for five litres of heavy water through our own dye industry syndicate corporation which, by happy accident, owns a quarter of the shares in the vemork plant.\n", + "\n" + ] + } + ], + "source": [ + "print(keyword_decipher(cb, kwordb))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first meeting of die alchemisten committee, reichserziehungsministerium, twenty ninth april nineteen thirty nine\n", + "the committee was reconvened by the minister at the request of the chancellor himself.\n", + "it is tasked with realising the military and industrial promise of nuclear energy.\n", + "the committee recognises the technical challenges involved in industrialising the processes hitherto conducted under laboratory conditions, but feels that the obstacles can be overcome by a combination of scientific and engineering excellence already possessed by the state.\n", + "the committee identified that the principle issue is that of controlling the nuclear reaction which is mediated by the energy of free neutrons. these need to be slowed to effectively harness their power, and to this end the committee recommends the acquisition of a suitable moderator.\n", + "the best-known candidate is deuterium and the best source of this material is the power plant at vemork in norway. the tronstad and brun electrolytic process at that facility is producing over twenty kilograms of heavy water per year, and this could easily be scaled up.\n", + "since we do not want to alert our enemies to the importance of the material the committee recommends placing an initial order for five litres of heavy water through our own dye industry syndicate corporation which, by happy accident, owns a quarter of the shares in the vemork plant.\n", + "\n" + ] + } + ], + "source": [ + "pb = keyword_decipher(cb, 'heavywater', KeywordWrapAlphabet.from_last)\n", + "print(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1399" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(pb)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "heavywtrsuxzbcdfgijklmnopq\n", + "heavywtrsqxzbcdfgijklmnopu\n" + ] + } + ], + "source": [ + "print(keyword_cipher_alphabet_of('heavywater', KeywordWrapAlphabet.from_last))\n", + "print(kwordb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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 +} diff --git a/2020-early/2020-a-challenge4.md b/2020-early/2020-a-challenge4.md new file mode 100644 index 0000000..8160cef --- /dev/null +++ b/2020-early/2020-a-challenge4.md @@ -0,0 +1,109 @@ +--- +jupyter: + jupytext: + formats: ipynb,md + text_representation: + extension: .md + format_name: markdown + format_version: '1.2' + jupytext_version: 1.3.4 + kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +```python +import os,sys,inspect +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0,parentdir) +``` + +```python +from cipher.caesar import * +from cipher.affine import * +from cipher.keyword_cipher import * + +from support.text_prettify import * +from support.utilities import * +from support.plot_frequency_histogram import * +%matplotlib inline +``` + +```python +challenge_number = 4 +plaintext_a_filename = f'{challenge_number}a.plaintext' +plaintext_b_filename = f'{challenge_number}b.plaintext' +ciphertext_a_filename = f'{challenge_number}a.ciphertext' +ciphertext_b_filename = f'{challenge_number}b.ciphertext' +``` + +```python +ca = open(ciphertext_a_filename).read() +cb = open(ciphertext_b_filename).read() + +sca = sanitise(ca) +pca = letters(ca) +pta = depunctuate(ca) + +scb = sanitise(cb) +pcb = letters(cb) +ptb = depunctuate(cb) +``` + +```python +kshifta, score = caesar_break(sca, fitness=Ptrigrams) +kshifta +``` + +```python +pa = caesar_decipher(sca, kshifta) +print(pa) +``` + +```python +fpa = lcat(tpack(segment(pa))) +print(fpa) +``` + +```python +open(plaintext_a_filename, 'w').write(fpa) +``` + +```python +fc = collections.Counter(scb) +plot_frequency_histogram(fc, sort_key=fc.get) +``` + +```python +(kwordb, kwrapb), score = keyword_break_mp(scb, fitness=Ptrigrams) +kwordb, kwrapb +``` + +```python +kwordb, score = simulated_annealing_break(scb, fitness=Ptrigrams) +kwordb +``` + +```python +print(keyword_decipher(cb, kwordb)) +``` + +```python +pb = keyword_decipher(cb, 'heavywater', KeywordWrapAlphabet.from_last) +print(pb) +``` + +```python +open(plaintext_b_filename, 'w').write(pb) +``` + +```python +print(keyword_cipher_alphabet_of('heavywater', KeywordWrapAlphabet.from_last)) +print(kwordb) +``` + +```python + +``` diff --git a/2020-early/4a.ciphertext b/2020-early/4a.ciphertext new file mode 100644 index 0000000..5f541f4 --- /dev/null +++ b/2020-early/4a.ciphertext @@ -0,0 +1 @@ +BTUXY KHUEU FFAYQ UFZQD ESDAG BIMEH QDKUZ FQDQE FUZSM ZPBMU PARRU ZMZGZ QJBQO FQPIM KMEKA GEGEB QOFQP ZGOXQ MDQZQ DSKTM EEQDU AGEBA FQZFU MXMZP FTQDQ MDQMZ GYNQD ARSDA GBEIA DWUZS FADQM XUEQF TMFAZ QARYQ UFZQD EOAXX MNADM FADET MENQQ ZUZOA ZFMOF IUFTM SDAGB ARPUE EUPQZ FSQDY MZEOU QZFUE FEOXA EQFAQ UZEFQ UZMZP FTQKT MHQNQ QZBME EUZSU ZFQXX USQZO QOAZO QDZUZ SFTQZ MLUZG OXQMD BDASD MYYQF AFTQE IQPUE TFQMY ITUXQ UIMEF TQDQA ZQARF TQUDO AZFMO FEUZN QDXUZ EYGSS XQPAG FMOAB KARMX QFFQD EQZFN KFTQE OUQZF UEFEV AAEMZ PTMZX QFAIU XTQXY PMYQE MFFTQ DQUOT EQDLU QTGZS EYUZU EFQDU GYUFA GFXUZ QEFTQ BAFQZ FUMXY UXUFM DKMBB XUOMF UAZEA RZGOX QMDQZ QDSKM ZPMBB MDQZF XKFTQ YUZUE FQDIM EEAUY BDQEE QPNKU FEOAZ FQZFE FTMFI UFTUZ MIQQW TQTMP OAZHQ ZQPMF ABXQH QXSDA GBFAP QHQXA BFTQU PQMEI UFTUZ UFFTQ NAEEF QMYUZ NQDXU ZTMHQ DMYBQ PGBYA ZUFAD UZSAR OAYYG ZUOMF UAZEF AMZPR DAYFT QYUZU EFDKM ZPFTQ YAEFB DAYUE UZSXQ MPUEF TQMFF MOTQP YQYAF TQQZH QXABQ IMEYM DWQPP UQMXO TQYUE FQZUM YZAFE GDQTA IRDQQ KAGMD QFAFD MHQXN GFUTM HQFAY QQFGB IUFTY KZQIZ ADIQS UMZRD UQZPE MZPFT QZTQM PNMOW FAQZS XMZPO AGXPK AGYAH QKAGD NMEQF ARDMZ OQMZP YMWQO AZFMO FIUFT EAYQA RAGDM XXUQE UFTUZ WIQET AGXPA BQZPU EOGEE UAZEI UFTFT QRDQZ OTYUZ UEFQD ARMDY MYQZF EIQMD QSAUZ SFAZQ QPTUE TQXBT MDDK diff --git a/2020-early/4a.plaintext b/2020-early/4a.plaintext new file mode 100644 index 0000000..1c7a737 --- /dev/null +++ b/2020-early/4a.plaintext @@ -0,0 +1,14 @@ +phil my visit to meitner s group was very interesting and paid off in an unexpected way as you +suspected nuclear energy has serious potential and there area number of groups working to realise +that one of meitner s collaborators has been in contact with a group of dissident german scientists +close to einstein and they have been passing intelligence concerning the nazi nuclear programme to +the swedish team while i was there one of their contacts in berlin smuggled out a copy of a letter +sent by the scientists joos and hanle to wilhelm dames at the reichs erziehung s ministerium it +outlines the potential military applications of nuclear energy and apparently the minister was so +impressed by its contents that within a week he had convened a toplevel group to develop the ideas +within it the boss team in berlin have ramped up monitoring of communications to and from the +ministry and the most promising lead is the attached memo the envelope was marked die alchemist en i +am not sure how free you are to travel but i have to meetup with my new norwegian friends and then +head back to england could you move your base to france and make contact with some of our allies i +think we should open discussions with the french minister of armaments we are going to need his help +harry \ No newline at end of file diff --git a/2020-early/4b.ciphertext b/2020-early/4b.ciphertext new file mode 100644 index 0000000..9135e95 --- /dev/null +++ b/2020-early/4b.ciphertext @@ -0,0 +1,7 @@ +WSIJK BYYKSCT DW VSY HZARYBSJKYC ADBBSKKYY, IYSARJYIQSYRLCTJBSCSJKYISLB, KNYCKP CSCKR HFISZ CSCYKYYC KRSIKP CSCY +KRY ADBBSKKYY NHJ IYADCMYCYV EP KRY BSCSJKYI HK KRY IYGLYJK DW KRY ARHCAYZZDI RSBJYZW. +SK SJ KHJXYV NSKR IYHZSJSCT KRY BSZSKHIP HCV SCVLJKISHZ FIDBSJY DW CLAZYHI YCYITP. +KRY ADBBSKKYY IYADTCSJYJ KRY KYARCSAHZ ARHZZYCTYJ SCMDZMYV SC SCVLJKISHZSJSCT KRY FIDAYJJYJ RSKRYIKD ADCVLAKYV LCVYI ZHEDIHKDIP ADCVSKSDCJ, ELK WYYZJ KRHK KRY DEJKHAZYJ AHC EY DMYIADBY EP H ADBESCHKSDC DW JASYCKSWSA HCV YCTSCYYISCT YOAYZZYCAY HZIYHVP FDJJYJJYV EP KRY JKHKY. +KRY ADBBSKKYY SVYCKSWSYV KRHK KRY FISCASFZY SJJLY SJ KRHK DW ADCKIDZZSCT KRY CLAZYHI IYHAKSDC NRSAR SJ BYVSHKYV EP KRY YCYITP DW WIYY CYLKIDCJ. KRYJY CYYV KD EY JZDNYV KD YWWYAKSMYZP RHICYJJ KRYSI FDNYI, HCV KD KRSJ YCV KRY ADBBSKKYY IYADBBYCVJ KRY HAGLSJSKSDC DW H JLSKHEZY BDVYIHKDI. +KRY EYJK-XCDNC AHCVSVHKY SJ VYLKYISLB HCV KRY EYJK JDLIAY DW KRSJ BHKYISHZ SJ KRY FDNYI FZHCK HK MYBDIX SC CDINHP. KRY KIDCJKHV HCV EILC YZYAKIDZPKSA FIDAYJJ HK KRHK WHASZSKP SJ FIDVLASCT DMYI KNYCKP XSZDTIHBJ DW RYHMP NHKYI FYI PYHI, HCV KRSJ ADLZV YHJSZP EY JAHZYV LF. +JSCAY NY VD CDK NHCK KD HZYIK DLI YCYBSYJ KD KRY SBFDIKHCAY DW KRY BHKYISHZ KRY ADBBSKKYY IYADBBYCVJ FZHASCT HC SCSKSHZ DIVYI WDI WSMY ZSKIYJ DW RYHMP NHKYI KRIDLTR DLI DNC VPY SCVLJKIP JPCVSAHKY ADIFDIHKSDC NRSAR, EP RHFFP HAASVYCK, DNCJ H GLHIKYI DW KRY JRHIYJ SC KRY MYBDIX FZHCK. diff --git a/2020-early/4b.plaintext b/2020-early/4b.plaintext new file mode 100644 index 0000000..9ad14a8 --- /dev/null +++ b/2020-early/4b.plaintext @@ -0,0 +1,7 @@ +first meeting of die alchemisten committee, reichserziehungsministerium, twenty ninth april nineteen thirty nine +the committee was reconvened by the minister at the request of the chancellor himself. +it is tasked with realising the military and industrial promise of nuclear energy. +the committee recognises the technical challenges involved in industrialising the processes hitherto conducted under laboratory conditions, but feels that the obstacles can be overcome by a combination of scientific and engineering excellence already possessed by the state. +the committee identified that the principle issue is that of controlling the nuclear reaction which is mediated by the energy of free neutrons. these need to be slowed to effectively harness their power, and to this end the committee recommends the acquisition of a suitable moderator. +the best-known candidate is deuterium and the best source of this material is the power plant at vemork in norway. the tronstad and brun electrolytic process at that facility is producing over twenty kilograms of heavy water per year, and this could easily be scaled up. +since we do not want to alert our enemies to the importance of the material the committee recommends placing an initial order for five litres of heavy water through our own dye industry syndicate corporation which, by happy accident, owns a quarter of the shares in the vemork plant. -- 2.34.1