From e6a2bc7836b33a0cabe43ad44ccaafcf95a7ff86 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 7 May 2020 14:20:08 +0100 Subject: [PATCH] Done challenge 6 --- 2020-early/2020-a-challenge6.ipynb | 435 +++++++++++++++++++++++++++++ 2020-early/2020-a-challenge6.md | 115 ++++++++ 2020-early/6a.ciphertext | 1 + 2020-early/6a.plaintext | 16 ++ 2020-early/6b.ciphertext | 1 + 2020-early/6b.plaintext | 12 + 6 files changed, 580 insertions(+) create mode 100644 2020-early/2020-a-challenge6.ipynb create mode 100644 2020-early/2020-a-challenge6.md create mode 100644 2020-early/6a.ciphertext create mode 100644 2020-early/6a.plaintext create mode 100644 2020-early/6b.ciphertext create mode 100644 2020-early/6b.plaintext diff --git a/2020-early/2020-a-challenge6.ipynb b/2020-early/2020-a-challenge6.ipynb new file mode 100644 index 0000000..1ebc696 --- /dev/null +++ b/2020-early/2020-a-challenge6.ipynb @@ -0,0 +1,435 @@ +{ + "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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from cipher.caesar import *\n", + "from cipher.affine import *\n", + "from cipher.keyword_cipher import *\n", + "from cipher.column_transposition 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 = 6\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": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa0AAAEiCAYAAABKsI06AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAVkElEQVR4nO3dfbBkdX3n8fcn4BMYw8NcDDCMF63RBE2y4EhhjFsGTERRIbWwC1EZXaxZIz4khuiwbgrLXSpjtNZNalc2I7CMKwthiQoJJpEgBhMFHIan4cEwCyOMEBlFicAGGPnuH31m6zre4Z7bDzPzm/t+Vd3qPr/z+/X5dt/u+7m/06dPp6qQJKkFP7WzC5AkqS9DS5LUDENLktQMQ0uS1AxDS5LUDENLktSMPXd2AQCLFi2q6enpnV2GJGkXcMMNN3y3qqZmW7dLhNb09DRr167d2WVIknYBSb61vXXuHpQkNcPQkiQ1w9CSJDXD0JIkNcPQkiQ1w9CSJDXD0JIkNWPO0EpyfpIHk6zfpv29Sb6Z5LYkfzij/cwkG7p1r5tE0ZKkhanPh4svAP4r8JmtDUl+FTge+MWqejzJAV37YcDJwEuBg4C/SfLiqvrRuAuXJC08c860quoa4KFtmn8LWFVVj3d9HuzajwcurqrHq+oeYANw5BjrlSQtYMOexunFwKuTnA38M3BGVX0DOBi4dka/TV3bT0iyAlgBsGTJkiHLkCRN0vTKK3r33bjquAlWMjDsgRh7AvsCRwG/B1ySJEBm6Vuz3UBVra6q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5u3LokFzB4Hwbg3G4X2Zyq6onuoIgfVNWP+oyZOXwefd/DYKZ7dRIYnMjznT3q+0aSy4GbGTwOaxnMsucad1v3x/nbVfVAzxq/CnwY+Hr33Ppnej4nq+p73QEA64G/rKrf67nNHWLU19qQ7gCWJ/kTBu9FnrMDttlb9xw5G/jbJD9i8P7423duVbOa7+P4V8C7ktzC4D27Se96/gmeEUMT04XjOuCkqrprHuP2Z3AQR5+Z4EiSPLeqHumOmroGWFFV6ya93d1ZBkfAPlJVn9jZtWj7kkwDf1FVcx7pvCvZnXcPaidKchiDo8iummdgHcTgQIUd9QdvdXdgyjrgzwwsadfmTEuS1AxnWpKkZhhakqRmGFqSpGYYWpKkZhhakqRmGFqSpGb8Px5ODz4dpDLoAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "fc = collections.Counter(sca)\n", + "plot_frequency_histogram(fc, sort_key=fc.get)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('norway', )" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(kworda, kwrapa), score = keyword_break_mp(sca, fitness=Ptrigrams)\n", + "kworda, kwrapa" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harryiguessyouhaveheardbynowabouttheinvasionithascomeasnoshocktoanyonethebritishhadbeenopenlydiscussingacountermanoeuvreandthatisnowasignificantpartofthenazipropagandatheofficiallineisthewehrmachtaretheretoprotectthecountrysneutralityagainstfrancobritishaggressiontheattachedinvasionorderswereinterceptedbybossagentsinthecapitalwhohaveestablishedaheadquartersnexttothetelephoneexchangeasfaraswecantelltheirtapintothesecuretelegraphicsystemhasnotyetbeendetectedbutwewillneedtolookoutforfakeintelligenceincasethatchangesunsurprisinglytheordersusethemostsecurecipherwehaveseenyetacolumnartranspositionluckilyihadsomeideawhattolookforsincenorskhydrowasanimportanttargetforthereichserziehungsministeriumandthatgavemeabigcluethemessagemakesmeverygladthatmonsieurallierwasabletoevacuatetheheavywaternowthatthesshavetakencontrolofrjukanitisonlyamatteroftimeuntiltheybuilduptheirownstocksbutthatwilltakeawhileandwecanusethatperiodtoworkoutwhattodonextwewillberelyingheavilyonyournetworkinthecountrytofeeduswithintelligenceonthefactorywhichiswhyiaskedourcommunicationsteamtosetupthismoresecurechannelifwecanbreakthetelegraphsystemweshouldassumethatthenaziscantooiwouldlikeustomovetousingvigenereciphersforourfuturemessagesstaysafephil\n" + ] + } + ], + "source": [ + "pa = cat(reversed(keyword_decipher(sca, kworda, kwrapa)))\n", + "print(pa)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "harry i guess you have heard by now about the invasion it has come as no shock to anyone the british\n", + "had been openly discussing a counter manoeuvre and that is now a significant part of the nazi\n", + "propaganda the official line is the wehrmacht are there to protect the country s neutrality against\n", + "franco british aggression the attached invasion orders were intercepted by boss agents in the\n", + "capital who have established a headquarters next to the telephone exchange as far as we can tell\n", + "their tap into the secure telegraphic system has not yet been detected but we will need to lookout\n", + "for fake intelligence in case that changes unsurprisingly the orders use the most secure cipher we\n", + "have seen yet a columnar transposition luckily i had some idea what to look for since norsk hydro\n", + "was an important target for the reichs erziehung s ministerium and that gave me a big clue the\n", + "message makes me very glad that monsieur allier was able to evacuate the heavy water now that the ss\n", + "have taken control of rj uk an it is only a matter of time until they buildup their own stocks but\n", + "that will take a while and we can use that period to workout what to do next we will be relying\n", + "heavily on your network in the country to feed us with intelligence on the factory which is why i\n", + "asked our communications team to setup this more secure channel if we can break the telegraph system\n", + "we should assume that the nazis can too i would like us to move to using vi genere ciphers for our\n", + "future messages stay safe phil\n" + ] + } + ], + "source": [ + "fpa = lcat(tpack(segment(pa)))\n", + "print(fpa)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1501" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_a_filename, 'w').write(fpa)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa0AAAEiCAYAAABKsI06AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAATcElEQVR4nO3dfbRldV3H8fcnxgfACoGLIYgXW7NMsgd0ZGFmi8QKRYVWUNgDo9GaLJ+NErIWLsvVmK7M1kprAnJKEgk1KKykEcNS0BlAGBgVkhEmSa6PKZQy8u2PvScveOGec/Y9c+c39/1a665z9j77d37fc84+93N+e++zT6oKSZJa8B3LXYAkSaMytCRJzTC0JEnNMLQkSc0wtCRJzTC0JEnNWLXcBQAcfPDBNTs7u9xlSJL2AFu2bPl8Vc0sdNseEVqzs7Ns3rx5ucuQJO0BknzmgW5z86AkqRmGliSpGYaWJKkZhpYkqRmGliSpGYaWJKkZhpYkqRmGliSpGYaWJKkZhpYkqRl7xGmcJEl7ptmzLht52e3rT5xiJR1HWpKkZhhakqRmLBpaSc5PcmeSrfPmvTHJJ5Jcn+S9SQ6Yd9vZSW5J8skkPzWtwiVJK88oI623Ayfcb97lwBOr6geBTwFnAyQ5CjgN+P6+zVuT7LNk1UqSVrRFQ6uqrgS+eL9576+qnf3kVcDh/fWTgAur6utVdStwC3DMEtYrSVrBlmKf1i8D/9hfPwy4fd5tO/p53ybJuiSbk2yem5tbgjIkSXu7QaGV5DXATuCCXbMWWKwWaltVG6pqTVWtmZlZ8FeVJUm6j4m/p5VkLfAc4Piq2hVMO4DHzFvscOCz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wMeM40CpznSuCnk+zbj4CfO+X+Jpbk0cDdVfUOus39T5pyl1cCJyfZL8n+wE8z2haB76bb2nF3ku+j2yy+O3yVbnfEODYBpyQ5BLp1Ncljl7yyB7E3j7ReQjdiuiIJdCd3/JXFGiU5HdhZVX/T72D8cJJnVNUHxux/5E+jVfWxJJcCHwc+A2ymGz2N3lnVXUmeA1ye5K6qumSR5W/s/+n8Z1XdMU5fA2wD1ib5c7r9dm8boc2HgNcAH+kf4/8y+qbBifqsqm+kO3Dny1X1zTH6mkj/Wrwe+Nck36TbN/mCEdvek+R1wNXArcAnplZo1981Sd5Ftw/2M4z3WuxuPwC8Mcm9wD3Ar02zs/65eTvdvlfofrH92hGa/hPwoiTX0+3b3B2b+aiqL/QHUm0F/rGqfnOENjcl+R3g/emOUrwHeDHdurBbeEaMKeg/MV9TVSN/AknyiKr6Wn9025XAuqq6ZmpFrgBJZoF/qKqxjv7s34zXAKdW1c1TKE3ShPbazYPLpd8k8RG6zRHj2NDv2LwGeLeBtTySHEV3RNwmA0va8zjSkiQ1w5GWJKkZhpYkqRmGliSpGYaWJKkZhpYkqRmGliSpGf8H83I2pfa/h6UAAAAASUVORK5CYII=\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": [ + "'\\nTRSXS EYHHN LASOR ILHRN NZCHT LYRON AEHSN UIPCN EOLDO ADPNC TRHRS ATORS ONAWT EETDD RYTNO DBEIF INCTR MIEOT ASSGR TRDPE SVBHL OAHEE ACMCE OMLTE RLEFY AYOFS OTAEN REAEO ENBAS OTEVA ENRNN UVJIE NTARL EEMID ATTOD ITRUE UDRRI FRAEB FHDHH UWUSS ESRCC UESEE NVAIE SATSI ACOSA AOENI AWTED OEIHN RELEU IENUR NICNR YEYCT ITDTS TELRY FOAOF WNAAC YSUNE HAVTL STRAU SBDRT TATTT RSHOS KEHHU DLDRE OESOC SIDHE HEEHT SCLNE ENEAE BANVT INSRL PJASH HIEIH TTTUI TRRUN LWEIU RITNI TAHUL BFSAC TENER LONRE IOILH HTUTS ASDRL OTSES REREE LRARN ARLEH OOCPE DBHAE KDRUN EEDRD RDSPP ETLWE NUYDN TEABA IHFRF HNOSP OYRAO PTCTD AMEIF ENENV UEERF IBTHO IMOAG DOSYF NXFRC KPHOE ETMOO EDLFN RTSFO IIGIH EALOR UDCEA TDRSL ETSCI TLPER UOWME ISNIP OKFTK IHCAH OGAUA DUELF TANWA EOONH UEVOT UHYTU LDEEE OAWTE ADLES IRTUL ETEIF ASCDR TISAR TWJEL EPRDL STRAL ECBGU WENEE AICTN HMNDM OINHY REASO RSGTC YNTIU REWSE EFRIM TMHEE TOWSE RDPEF TDENH ODLEP ATRVT TLCEY CINRT YOOCL SRSAC AMDNE DGURP IHTIL ETHLD SWHCR UOEDC NUEUL TRERE OOBAC NNTUW EOYCT AOOKE NEETE EKTSA ODRDE BEKTA IEABS MEOTO ITLTR JRYNC IRNII SOEEN'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rscb = cat(reversed(cb))\n", + "rscb" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(((3, 1, 4, 2, 0), False, True), -3026.420927215971)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(kwordb, fillb, emptyb), score = column_transposition_break_mp(scb, fitness=Ptrigrams)\n", + "(kwordb, fillb, emptyb), score" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'uranprojektspecialordersforsixtyninthinfantrydivisioncommandedbygeneralmajorhermanntitteloncetheinitialobjectivesofunternehmenweseruebunghavebeenachievedanelitetaskforceistobeassembledandorderedtoproceedatallspeedtorjukanwheretheyaretotakepossessionofthenorskhydrofactorystaffatthefacilityaretobetreatedwellbutmustnotunderanycircumstancesbeallowedtoleavetheareathepowerplantshouldbesurveyedsecuredandplacedundertwentyfourhourguardstocksofheavywatershouldbeheldinthemostprotectedlocationwithinthefacilitypreferablyundergroundandcertainlyunderarmedguardoncetheareaissecurethesswilltakecontrolofnorskhydroitsoperationsanditssecuritythewehrmachtwillcontinuetoprovideareapatrolsandtopolicelocalresidentsoncetheplantissecuredanditsstaffhavebeenplacedunderhousearrestyouwillcontactthereichserziehungsministeriumwhowillfurnishfurtherordersnhstaffwillbeundertheauthorityoftheministryexercisedthroughthess'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pb = column_transposition_decipher(scb, kwordb, fillcolumnwise=fillb, emptycolumnwise=emptyb)\n", + "pb" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uran projekt special orders for sixty ninth infantry division commanded by general major hermann\n", + "tittel once the initial objectives of unternehmen we serue bung have been achieved an elite\n", + "taskforce is to be assembled and ordered to proceed at all speed to rj uk an where they are to take\n", + "possession of the norsk hydro factory staff at the facility are to be treated well but must not\n", + "under any circumstances be allowed to leave the area the powerplant should be surveyed secured and\n", + "placed under twenty four hour guard stocks of heavy water should beheld in the most protected\n", + "location within the facility preferably underground and certainly under armed guard once the area is\n", + "secure the ss will take control of norsk hydro its operations and its security the wehrmacht will\n", + "continue to provide area patrols and to police local residents once the plant is secured and its\n", + "staff have been placed under house arrest you will contact the reichs erziehung s ministerium who\n", + "will furnish further orders nh staff will be under the authority of the ministry exercised through\n", + "the ss\n" + ] + } + ], + "source": [ + "fpb = lcat(tpack(segment(pb)))\n", + "print(fpb)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1077" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "open(plaintext_b_filename, 'w').write(fpb)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['penal',\n", + " 'reich',\n", + " 'renal',\n", + " 'ripen',\n", + " 'scram',\n", + " 'scrap',\n", + " 'sepal',\n", + " 'shoal',\n", + " 'shock',\n", + " 'shrek',\n", + " 'siren',\n", + " 'sloan',\n", + " 'venal',\n", + " 'verdi',\n", + " 'vetch',\n", + " 'viral',\n", + " 'vireo',\n", + " 'virgo',\n", + " 'vital',\n", + " 'voter',\n", + " 'votes',\n", + " 'welch',\n", + " 'wench',\n", + " 'wendi',\n", + " 'wesak',\n", + " 'wiser',\n", + " 'wives',\n", + " 'yowls',\n", + " 'remake',\n", + " 'remark',\n", + " 'rename',\n", + " 'repair',\n", + " 'repeal',\n", + " 'scrams',\n", + " 'scraps',\n", + " 'sepals',\n", + " 'serape',\n", + " 'shoals',\n", + " 'shocks',\n", + " 'shreks',\n", + " 'sirens',\n", + " 'tercel',\n", + " 'terran',\n", + " 'thrall',\n", + " 'tirana',\n", + " 'tishri',\n", + " 'unsnap',\n", + " 'virgil',\n", + " 'virgin',\n", + " 'wesaks',\n", + " 'within',\n", + " 'seepage',\n", + " 'serapes',\n", + " 'teenage',\n", + " 'tishris',\n", + " 'unsnaps',\n", + " 'wendell',\n", + " 'wittier',\n", + " 'remedied',\n", + " 'repairer',\n", + " 'repealer',\n", + " 'ringling',\n", + " 'riparian',\n", + " 'seepages',\n", + " 'selassie',\n", + " 'singling',\n", + " 'teetotal',\n", + " 'terraria',\n", + " 'tingling',\n", + " 'wittiest',\n", + " 'selassies']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transpositions[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-challenge6.md b/2020-early/2020-a-challenge6.md new file mode 100644 index 0000000..61f8e69 --- /dev/null +++ b/2020-early/2020-a-challenge6.md @@ -0,0 +1,115 @@ +--- +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 cipher.column_transposition import * + +from support.text_prettify import * +from support.utilities import * +from support.plot_frequency_histogram import * +%matplotlib inline +``` + +```python +challenge_number = 6 +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 +fc = collections.Counter(sca) +plot_frequency_histogram(fc, sort_key=fc.get) +``` + +```python +(kworda, kwrapa), score = keyword_break_mp(sca, fitness=Ptrigrams) +kworda, kwrapa +``` + +```python +pa = cat(reversed(keyword_decipher(sca, kworda, kwrapa))) +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 +rscb = cat(reversed(cb)) +rscb +``` + +```python +(kwordb, fillb, emptyb), score = column_transposition_break_mp(scb, fitness=Ptrigrams) +(kwordb, fillb, emptyb), score +``` + +```python +pb = column_transposition_decipher(scb, kwordb, fillcolumnwise=fillb, emptycolumnwise=emptyb) +pb +``` + +```python +fpb = lcat(tpack(segment(pb))) +print(fpb) +``` + +```python +open(plaintext_b_filename, 'w').write(fpb) +``` + +```python +transpositions[kwordb] +``` + +```python + +``` diff --git a/2020-early/6a.ciphertext b/2020-early/6a.ciphertext new file mode 100644 index 0000000..42bd909 --- /dev/null +++ b/2020-early/6a.ciphertext @@ -0,0 +1 @@ +FCBJA YNMVN PMMAZ NMMAG ALQPQ YLQIL IYMLA BJCRA LAHAZ CSZHC MQIPA SIGIP MQAEC FWFQI TCIIP HNRMC XNHAB PPNBP AGQMM NWFQI BMATG APMVM BJNLZ AFAPA BPENA LOHNR ATYCF AHHNB RALQR AMALI GMCBP JQPAM IPGNA PMHIC PNRCH QGGIR LQIWA EMNCV BTMCB RCBTV LIPRN YABPH IARHA ZCFFA PHCBP CTMQW AAYIP VLPHQ IRABP HCELI TPAHL QIVHI VFCSN ABZHC VFALA OFFCT ATPUA HIWIP PNBTP QIELI TIPWI CLAJP NBPAM QHNRA TWHNA FCBTN AENPF FCTPN BPPQO MERIP MHTIL CABPJ QWFCQ OVABP FCPHQ AGCPY ILAPP NGNVF HIMCP CHNEQ DLYIF ILPHI RHAEN PASNB MMABP PNBPT IHLAP NTVSN ABABP APNQR NSAIP AFONM NTLAC FFNLQ ACMHI GPNBP WNFZV LASAG MAENG AZNMM AGABP AQFRZ CONAG ASNZP NBPWH NGQCL APMCH CGMZH QBACX LAMBR CALAB PLIYP AZLNP PHNPL IJGCH NMNTI LWVBE MLIHA RHCML IYEII FIPPN BTNAW CAGIM WNBCV FCERQ FHICP CMIJM HNLPL NHGQF IRNPA VHAAM ASNBA TLABJ CRALQ RAMPM IGABP AMQML AWLIA BPVFZ HCMCL JLQMH QMAZH NBRPN BPAMN RHCAR HAZCF FAPHC AENYL IYPQI EIIFI PWAAH FFCTA TPQOW APRAP AWHAA OPAVP IHMNB GAPMV MRCBJ NLZAF APALQ RAMAB PIPHC JNPLC ABPFF APHNR ATMNL NYMNA ZHNBR UAAHI BJAFA PABPI PPUAH MLAPL NQKWN ABNWA BMCFO NPMAA SNBIB TFNPC JNRAB PHCMP HAZNM MIOVO WAPJA RLAPH CALAT MLAWL IHICM NSHCW ABRNP PNABP HICMM ALZZN BMCPC LOIRH NLYPM HCNZN VPCFN LPQAH MVLPH QIRAB PPRAP ILJIP ALABP ALNPB RNGLB ATABP MCAHC FFNCR CYYIA BPNWH NZNJI LJCXN HABPY IPLNJ PHNRC YCHZC MNTIH MCPNB PWHNA LSQAI HNGLA PHQIR NZHCM MQRMC WVFHA JIHAA OWNBB MCPCL OABPA HIVHN IPERI BMIHM NAGIR MNBPC HICMN SHCAB PPQIO NTIHV OWLNA BASNB QIVMM AQZCV LLNB diff --git a/2020-early/6a.plaintext b/2020-early/6a.plaintext new file mode 100644 index 0000000..c832226 --- /dev/null +++ b/2020-early/6a.plaintext @@ -0,0 +1,16 @@ +harry i guess you have heard by now about the invasion it has come as no shock to anyone the british +had been openly discussing a counter manoeuvre and that is now a significant part of the nazi +propaganda the official line is the wehrmacht are there to protect the country s neutrality against +franco british aggression the attached invasion orders were intercepted by boss agents in the +capital who have established a headquarters next to the telephone exchange as far as we can tell +their tap into the secure telegraphic system has not yet been detected but we will need to lookout +for fake intelligence in case that changes unsurprisingly the orders use the most secure cipher we +have seen yet a columnar transposition luckily i had some idea what to look for since norsk hydro +was an important target for the reichs erziehung s ministerium and that gave me a big clue the +message makes me very glad that monsieur allier was able to evacuate the heavy water now that the ss +have taken control of rj uk an it is only a matter of time until they buildup their own stocks but +that will take a while and we can use that period to workout what to do next we will be relying +heavily on your network in the country to feed us with intelligence on the factory which is why i +asked our communications team to setup this more secure channel if we can break the telegraph system +we should assume that the nazis can too i would like us to move to using vi genere ciphers for our +future messages stay safe phil \ No newline at end of file diff --git a/2020-early/6b.ciphertext b/2020-early/6b.ciphertext new file mode 100644 index 0000000..68023bf --- /dev/null +++ b/2020-early/6b.ciphertext @@ -0,0 +1 @@ +NEEOS IINRI CNYRJ RTLTI OTOEM SBAEI ATKEB EDRDO ASTKE ETEEN EKOOA TCYOE WUTNN CABOO ERERT LUEUN CDEOU RCHWS DLHTE LITHI PRUGD ENDMA CASRS LCOOY TRNIC YECLT TVRTA PELDO HNEDT FEPDR ESWOT EEHMT MIRFE ESWER UITNY CTGSR OSAER YHNIO MDNMH NTCIA EENEW UGBCE LARTS LDRPE LEJWT RASIT RDCSA FIETE LUTRI SELDA ETWAO EEEDL UTYHU TOVEU HNOOE AWNAT FLEUD AUAGO HACHI KTFKO PINSI EMWOU REPLT ICSTE LSRDT AECDU ROLAE HIGII OFSTR NFLDE OOMTE EOHPK CRFXN FYSOD GAOMI OHTBI FREEU VNENE FIEMA DTCTP OARYO PSONH FRFHI ABAET NDYUN EWLTE PPSDR DRDEE NURDK EAHBD EPCOO HELRA NRARL EERER SESTO LRDSA STUTH HLIOI ERNOL RENET CASFB LUHAT INTIR UIEWL NURRT IUTTT HIEIH HSAJP LRSNI TVNAB EAENE ENLCS THEEH EHDIS COSEO ERDLD UHHEK SOHSR TTTAT TRDBS UARTS LTVAH ENUSY CAANW FOAOF YRLET STDTI TCYEY RNCIN RUNEI UELER NHIEO DETWA INEOA ASOCA ISTAS EIAVN EESEU CCRSE SSUWU HHDHF BEARF IRRDU EURTI DOTTA DIMEE LRATN EIJVU NNRNE AVETO SABNE OEAER NEATO SFOYA YFELR ETLMO ECMCA EEHAO LHBVS EPDRT RGSSA TOEIM RTCNI FIEBD ONTYR DDTEE TWANO SROTA SRHRT CNPDA ODLOE NCPIU NSHEA NORYL THCZN NRHLI ROSAL NHHYE SXSRT diff --git a/2020-early/6b.plaintext b/2020-early/6b.plaintext new file mode 100644 index 0000000..db562df --- /dev/null +++ b/2020-early/6b.plaintext @@ -0,0 +1,12 @@ +uran projekt special orders for sixty ninth infantry division commanded by general major hermann +tittel once the initial objectives of unternehmen we serue bung have been achieved an elite +taskforce is to be assembled and ordered to proceed at all speed to rj uk an where they are to take +possession of the norsk hydro factory staff at the facility are to be treated well but must not +under any circumstances be allowed to leave the area the powerplant should be surveyed secured and +placed under twenty four hour guard stocks of heavy water should beheld in the most protected +location within the facility preferably underground and certainly under armed guard once the area is +secure the ss will take control of norsk hydro its operations and its security the wehrmacht will +continue to provide area patrols and to police local residents once the plant is secured and its +staff have been placed under house arrest you will contact the reichs erziehung s ministerium who +will furnish further orders nh staff will be under the authority of the ministry exercised through +the ss \ No newline at end of file -- 2.34.1