X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=bombe.ipynb;h=e28af9aac5316617032de9fa7f1becc61f6ccea5;hb=e66deb186d1af01bb90fc618ed2d990bb675d55c;hp=c340539c46ee1642bb80f01ac9ee08a8b0e1fed0;hpb=6889a439393b5de11b205f96afd0e8eb6e2175d8;p=cipher-tools.git diff --git a/bombe.ipynb b/bombe.ipynb index c340539..e28af9a 100644 --- a/bombe.ipynb +++ b/bombe.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -17,39 +17,7 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# wheel_i_spec = 'ekmflgdqvzntowyhxuspaibrcj'\n", - "# wheel_ii_spec = 'ajdksiruxblhwtmcqgznpyfvoe'\n", - "# wheel_iii_spec = 'bdfhjlcprtxvznyeiwgakmusqo'\n", - "# wheel_iv_spec = 'esovpzjayquirhxlnftgkdcmwb'\n", - "# wheel_v_spec = 'vzbrgityupsdnhlxawmjqofeck'\n", - "# wheel_vi_spec = 'jpgvoumfyqbenhzrdkasxlictw'\n", - "# wheel_vii_spec = 'nzjhgrcxmyswboufaivlpekqdt'\n", - "# wheel_viii_spec = 'fkqhtlxocbjspdzramewniuygv'\n", - "# beta_wheel_spec = 'leyjvcnixwpbqmdrtakzgfuhos'\n", - "# gamma_wheel_spec = 'fsokanuerhmbtiycwlqpzxvgjd'\n", - "\n", - "# wheel_i_pegs = ['q']\n", - "# wheel_ii_pegs = ['e']\n", - "# wheel_iii_pegs = ['v']\n", - "# wheel_iv_pegs = ['j']\n", - "# wheel_v_pegs = ['z']\n", - "# wheel_vi_pegs = ['z', 'm']\n", - "# wheel_vii_pegs = ['z', 'm']\n", - "# wheel_viii_pegs = ['z', 'm']\n", - "\n", - "# reflector_b_spec = 'ay br cu dh eq fs gl ip jx kn mo tz vw'\n", - "# reflector_c_spec = 'af bv cp dj ei go hy kr lz mx nw tq su'" - ] - }, - { - "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -62,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": { "collapsed": true }, @@ -107,9 +75,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -148,6 +116,7 @@ " self.connections += [Connection([bank_before, bank_after], scrambler)]\n", " \n", " def read_menu(self, menu):\n", + " self.connections = []\n", " for item in menu:\n", " scrambler = Scrambler(self.wheel1_spec, self.wheel2_spec, self.wheel3_spec,\n", " self.reflector_spec,\n", @@ -195,7 +164,10 @@ " self.pending += [Signal(current.wire, current.bank)]\n", " for c in self.connections:\n", " if current.bank in c.banks:\n", - " other_bank = [b for b in c.banks if b != current.bank][0]\n", + " if len(set(c.banks)) == 1:\n", + " other_bank = c.banks[0]\n", + " else:\n", + " other_bank = [b for b in c.banks if b != current.bank][0]\n", " other_wire = c.scrambler.lookup(current.wire)\n", " # print(\" adding\", other_bank, other_wire, \"because\", c.banks)\n", " self.pending += [Signal(other_bank, other_wire)]\n", @@ -231,9 +203,9 @@ }, { "cell_type": "code", - "execution_count": 804, + "execution_count": 5, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -243,7 +215,7 @@ }, { "cell_type": "code", - "execution_count": 805, + "execution_count": 6, "metadata": { "collapsed": true }, @@ -259,10 +231,8 @@ }, { "cell_type": "code", - "execution_count": 806, - "metadata": { - "collapsed": false - }, + "execution_count": 7, + "metadata": {}, "outputs": [ { "data": { @@ -270,7 +240,7 @@ "'opgndxcrwomnlnecjz'" ] }, - "execution_count": 806, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -284,10 +254,8 @@ }, { "cell_type": "code", - "execution_count": 807, - "metadata": { - "collapsed": false - }, + "execution_count": 8, + "metadata": {}, "outputs": [ { "data": { @@ -295,7 +263,7 @@ "'aas'" ] }, - "execution_count": 807, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -306,10 +274,8 @@ }, { "cell_type": "code", - "execution_count": 808, - "metadata": { - "collapsed": false - }, + "execution_count": 9, + "metadata": {}, "outputs": [ { "data": { @@ -334,7 +300,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 808, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -346,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 809, + "execution_count": 10, "metadata": { "collapsed": true }, @@ -359,10 +325,8 @@ }, { "cell_type": "code", - "execution_count": 810, - "metadata": { - "collapsed": false - }, + "execution_count": 11, + "metadata": {}, "outputs": [ { "data": { @@ -387,7 +351,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 810, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -398,10 +362,8 @@ }, { "cell_type": "code", - "execution_count": 811, - "metadata": { - "collapsed": false - }, + "execution_count": 12, + "metadata": {}, "outputs": [ { "data": { @@ -409,7 +371,7 @@ "'s'" ] }, - "execution_count": 811, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -420,9 +382,9 @@ }, { "cell_type": "code", - "execution_count": 812, + "execution_count": 13, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -431,10 +393,8 @@ }, { "cell_type": "code", - "execution_count": 813, - "metadata": { - "collapsed": false - }, + "execution_count": 14, + "metadata": {}, "outputs": [ { "data": { @@ -442,7 +402,7 @@ "18" ] }, - "execution_count": 813, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -453,10 +413,8 @@ }, { "cell_type": "code", - "execution_count": 814, - "metadata": { - "collapsed": false - }, + "execution_count": 15, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -490,10 +448,48 @@ }, { "cell_type": "code", - "execution_count": 815, - "metadata": { - "collapsed": false - }, + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ot:hp:gi:ns:di:sx:ac:rt:ew:os:mt:mn:el:ns:es:ac:gj:ez'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "':'.join(cat(sorted(c.banks)) for c in bombe.connections)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'aaa:aab:aac:aad:aae:aaf:aag:aah:aai:aaj:aak:aal:aam:aan:aao:aap:aaq:aar'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "':'.join(cat(c.scrambler.wheel_positions_l) for c in bombe.connections)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, "outputs": [ { "data": { @@ -501,7 +497,7 @@ "False" ] }, - "execution_count": 815, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -512,10 +508,8 @@ }, { "cell_type": "code", - "execution_count": 816, - "metadata": { - "collapsed": false - }, + "execution_count": 19, + "metadata": {}, "outputs": [ { "data": { @@ -548,7 +542,7 @@ " 'z': True}" ] }, - "execution_count": 816, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -559,10 +553,8 @@ }, { "cell_type": "code", - "execution_count": 817, - "metadata": { - "collapsed": false - }, + "execution_count": 20, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -610,10 +602,57 @@ }, { "cell_type": "code", - "execution_count": 818, - "metadata": { - "collapsed": false - }, + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a : abcdefghijklmnopqrstuvwxyz\n", + "b : a.cde.ghij.lmnop.rst..wx.z\n", + "c : abcdefghijklmnopqrstuvwxyz\n", + "d : abcdefghijklmnopqrstuvwx.z\n", + "e : abcdefghijklmnopqrstuvwxyz\n", + "f : a.cde.ghij.lmnop.rst..wx.z\n", + "g : abcdefghijklmnopqrst.vwxyz\n", + "h : abcdefghijklmnopqrstuvwxyz\n", + "i : abcdefghijklmnopqrstu.wxyz\n", + "j : abcdefghi.klmnopqrstuvwxyz\n", + "k : a.cde.ghij.lmnop.rst..wx.z\n", + "l : abcdefghijklmnopqrstuvwxyz\n", + "m : abcdefghijklmnopqrstuvwxyz\n", + "n : abcdefghijklmnopqrstuvwxyz\n", + "o : abcdefghijklmnopqrstuvwxyz\n", + "p : abcdefghijklmnopqrstuvwxyz\n", + "q : a.cde.ghij.lmnop.rst..wx.z\n", + "r : abcdefghijklmnopqrstuvwxyz\n", + "s : abcdefghijklmnopqrstuvwxyz\n", + "t : abcdefghijklmnopqrstuvwxyz\n", + "u : a.cde..hij.lmnop.rst..wx.z\n", + "v : a.cde.gh.j.lmnop.rst..wx.z\n", + "w : abcdefghijklmnopqrstuvwxyz\n", + "x : abcdefghijklmnopqrstuvwxyz\n", + "y : a.c.e.ghij.lmnop.rst..wx.z\n", + "z : abcdefghijklmnopqrstuvwxyz\n" + ] + } + ], + "source": [ + "for b in sorted(bombe.banks):\n", + " print(b, ': ', end='')\n", + " for w in sorted(bombe.banks[b]):\n", + " if bombe.banks[b][w]:\n", + " print(w, end='')\n", + " else:\n", + " print('.', end='')\n", + " print('')" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, "outputs": [ { "data": { @@ -621,7 +660,7 @@ "('a', 'a', 'a')" ] }, - "execution_count": 818, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -632,10 +671,8 @@ }, { "cell_type": "code", - "execution_count": 819, - "metadata": { - "collapsed": false - }, + "execution_count": 23, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -670,9 +707,9 @@ }, { "cell_type": "code", - "execution_count": 820, + "execution_count": 24, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -682,10 +719,8 @@ }, { "cell_type": "code", - "execution_count": 821, - "metadata": { - "collapsed": false - }, + "execution_count": 25, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -736,10 +771,8 @@ }, { "cell_type": "code", - "execution_count": 822, - "metadata": { - "collapsed": false - }, + "execution_count": 26, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -790,10 +823,8 @@ }, { "cell_type": "code", - "execution_count": 823, - "metadata": { - "collapsed": false - }, + "execution_count": 27, + "metadata": {}, "outputs": [ { "data": { @@ -801,7 +832,7 @@ "1" ] }, - "execution_count": 823, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -812,9 +843,9 @@ }, { "cell_type": "code", - "execution_count": 824, + "execution_count": 28, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -825,9 +856,9 @@ }, { "cell_type": "code", - "execution_count": 825, + "execution_count": 29, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -838,10 +869,8 @@ }, { "cell_type": "code", - "execution_count": 826, - "metadata": { - "collapsed": false - }, + "execution_count": 30, + "metadata": {}, "outputs": [ { "data": { @@ -849,7 +878,7 @@ "('a', 'a', 'b')" ] }, - "execution_count": 826, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -860,10 +889,8 @@ }, { "cell_type": "code", - "execution_count": 827, - "metadata": { - "collapsed": false - }, + "execution_count": 31, + "metadata": {}, "outputs": [ { "data": { @@ -871,7 +898,7 @@ "False" ] }, - "execution_count": 827, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -882,10 +909,8 @@ }, { "cell_type": "code", - "execution_count": 828, - "metadata": { - "collapsed": false - }, + "execution_count": 32, + "metadata": {}, "outputs": [ { "data": { @@ -893,7 +918,7 @@ "('p', 'p', 'p')" ] }, - "execution_count": 828, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -904,10 +929,8 @@ }, { "cell_type": "code", - "execution_count": 829, - "metadata": { - "collapsed": false - }, + "execution_count": 33, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -955,10 +978,8 @@ }, { "cell_type": "code", - "execution_count": 830, - "metadata": { - "collapsed": false - }, + "execution_count": 34, + "metadata": {}, "outputs": [ { "data": { @@ -966,7 +987,7 @@ "17576" ] }, - "execution_count": 830, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -978,10 +999,8 @@ }, { "cell_type": "code", - "execution_count": 831, - "metadata": { - "collapsed": false - }, + "execution_count": 35, + "metadata": {}, "outputs": [ { "data": { @@ -989,7 +1008,7 @@ "(('a', 'a', 'b'), True)" ] }, - "execution_count": 831, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -1001,9 +1020,9 @@ }, { "cell_type": "code", - "execution_count": 832, + "execution_count": 36, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -1012,10 +1031,8 @@ }, { "cell_type": "code", - "execution_count": 833, - "metadata": { - "collapsed": false - }, + "execution_count": 37, + "metadata": {}, "outputs": [ { "data": { @@ -1023,7 +1040,7 @@ "[('a', 'a', 'b')]" ] }, - "execution_count": 833, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -1039,7 +1056,7 @@ }, { "cell_type": "code", - "execution_count": 857, + "execution_count": 38, "metadata": { "collapsed": true }, @@ -1061,10 +1078,8 @@ }, { "cell_type": "code", - "execution_count": 835, - "metadata": { - "collapsed": false - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "data": { @@ -1072,7 +1087,7 @@ "[('a', 'a', 'b')]" ] }, - "execution_count": 835, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1083,9 +1098,9 @@ }, { "cell_type": "code", - "execution_count": 836, + "execution_count": 40, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -1102,10 +1117,8 @@ }, { "cell_type": "code", - "execution_count": 837, - "metadata": { - "collapsed": false - }, + "execution_count": 41, + "metadata": {}, "outputs": [ { "data": { @@ -1113,7 +1126,7 @@ "('e', 'l', 'e')" ] }, - "execution_count": 837, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1125,10 +1138,8 @@ }, { "cell_type": "code", - "execution_count": 838, - "metadata": { - "collapsed": false - }, + "execution_count": 42, + "metadata": {}, "outputs": [ { "data": { @@ -1136,7 +1147,7 @@ "'dhnpforeeimgg'" ] }, - "execution_count": 838, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1150,10 +1161,8 @@ }, { "cell_type": "code", - "execution_count": 839, - "metadata": { - "collapsed": false - }, + "execution_count": 43, + "metadata": {}, "outputs": [ { "data": { @@ -1161,7 +1170,7 @@ "('j', 'e', 'o')" ] }, - "execution_count": 839, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1172,10 +1181,8 @@ }, { "cell_type": "code", - "execution_count": 840, - "metadata": { - "collapsed": false - }, + "execution_count": 44, + "metadata": {}, "outputs": [ { "data": { @@ -1195,7 +1202,7 @@ " MenuIem(before='t', after='g', number=13)]" ] }, - "execution_count": 840, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1207,9 +1214,8 @@ }, { "cell_type": "code", - "execution_count": 841, + "execution_count": 45, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -1280,7 +1286,7 @@ " ('z', 'z', 'k')]" ] }, - "execution_count": 841, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -1297,10 +1303,8 @@ }, { "cell_type": "code", - "execution_count": 842, - "metadata": { - "collapsed": false - }, + "execution_count": 46, + "metadata": {}, "outputs": [ { "data": { @@ -1308,7 +1312,7 @@ "62" ] }, - "execution_count": 842, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -1319,9 +1323,8 @@ }, { "cell_type": "code", - "execution_count": 843, + "execution_count": 47, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -1343,7 +1346,7 @@ " ('y', 'n', 'c')]" ] }, - "execution_count": 843, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -1360,10 +1363,8 @@ }, { "cell_type": "code", - "execution_count": 858, - "metadata": { - "collapsed": false - }, + "execution_count": 48, + "metadata": {}, "outputs": [ { "data": { @@ -1383,7 +1384,7 @@ " ('y', 'n', 'c')]" ] }, - "execution_count": 858, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -1394,9 +1395,9 @@ }, { "cell_type": "code", - "execution_count": 844, + "execution_count": 49, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -1411,10 +1412,8 @@ }, { "cell_type": "code", - "execution_count": 845, - "metadata": { - "collapsed": false - }, + "execution_count": 50, + "metadata": {}, "outputs": [ { "data": { @@ -1422,7 +1421,7 @@ "13" ] }, - "execution_count": 845, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1433,9 +1432,9 @@ }, { "cell_type": "code", - "execution_count": 846, + "execution_count": 51, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -1445,10 +1444,8 @@ }, { "cell_type": "code", - "execution_count": 847, - "metadata": { - "collapsed": false - }, + "execution_count": 52, + "metadata": {}, "outputs": [ { "data": { @@ -1456,7 +1453,7 @@ "Signal(bank='e', wire='e')" ] }, - "execution_count": 847, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -1467,10 +1464,8 @@ }, { "cell_type": "code", - "execution_count": 848, - "metadata": { - "collapsed": false - }, + "execution_count": 53, + "metadata": {}, "outputs": [ { "data": { @@ -1478,7 +1473,7 @@ "True" ] }, - "execution_count": 848, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1489,10 +1484,8 @@ }, { "cell_type": "code", - "execution_count": 849, - "metadata": { - "collapsed": false - }, + "execution_count": 54, + "metadata": {}, "outputs": [ { "data": { @@ -1500,7 +1493,7 @@ "True" ] }, - "execution_count": 849, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -1511,10 +1504,8 @@ }, { "cell_type": "code", - "execution_count": 850, - "metadata": { - "collapsed": false - }, + "execution_count": 55, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1565,10 +1556,8 @@ }, { "cell_type": "code", - "execution_count": 851, - "metadata": { - "collapsed": false - }, + "execution_count": 56, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1619,23 +1608,21 @@ }, { "cell_type": "code", - "execution_count": 852, - "metadata": { - "collapsed": false - }, + "execution_count": 57, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{frozenset({'e', 'y'}),\n", - " frozenset({'t', 'x'}),\n", + "{frozenset({'t', 'x'}),\n", " frozenset({'i', 'n'}),\n", " frozenset({'m'}),\n", - " frozenset({'b', 'g'}),\n", - " frozenset({'f', 'p'})}" + " frozenset({'e', 'y'}),\n", + " frozenset({'f', 'p'}),\n", + " frozenset({'b', 'g'})}" ] }, - "execution_count": 852, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -1647,10 +1634,8 @@ }, { "cell_type": "code", - "execution_count": 853, - "metadata": { - "collapsed": false - }, + "execution_count": 58, + "metadata": {}, "outputs": [ { "data": { @@ -1658,7 +1643,7 @@ "True" ] }, - "execution_count": 853, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1669,10 +1654,8 @@ }, { "cell_type": "code", - "execution_count": 854, - "metadata": { - "collapsed": false - }, + "execution_count": 59, + "metadata": {}, "outputs": [ { "data": { @@ -1683,7 +1666,7 @@ " frozenset({2, 3}))" ] }, - "execution_count": 854, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1702,10 +1685,8 @@ }, { "cell_type": "code", - "execution_count": 855, - "metadata": { - "collapsed": false - }, + "execution_count": 60, + "metadata": {}, "outputs": [ { "data": { @@ -1713,7 +1694,7 @@ "False" ] }, - "execution_count": 855, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -1724,10 +1705,8 @@ }, { "cell_type": "code", - "execution_count": 856, - "metadata": { - "collapsed": false - }, + "execution_count": 61, + "metadata": {}, "outputs": [ { "data": { @@ -1735,7 +1714,7 @@ "False" ] }, - "execution_count": 856, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -1744,6 +1723,223 @@ "{1, 2}.isdisjoint({1, 6})" ] }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Tsest" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'slgncszxltkzebghstgywdmpr'" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "target_ct = ''.join(c.lower() for c in 'SLGNC SZXLT KZEBG HSTGY WDMPR' if c in string.ascii_letters)\n", + "target_ct" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'theyweredetectedbybritishshipsinclud'" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "target_pt = ''.join(c.lower() for c in 'Theyw erede tecte d byBri tishs hipsi nclud' if c in string.ascii_letters)\n", + "target_pt" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[MenuIem(before='w', after='c', number=1),\n", + " MenuIem(before='e', after='s', number=2),\n", + " MenuIem(before='r', after='z', number=3),\n", + " MenuIem(before='e', after='x', number=4),\n", + " MenuIem(before='d', after='l', number=5),\n", + " MenuIem(before='e', after='t', number=6),\n", + " MenuIem(before='t', after='k', number=7),\n", + " MenuIem(before='e', after='z', number=8),\n", + " MenuIem(before='c', after='e', number=9),\n", + " MenuIem(before='t', after='b', number=10),\n", + " MenuIem(before='e', after='g', number=11),\n", + " MenuIem(before='d', after='h', number=12),\n", + " MenuIem(before='b', after='s', number=13),\n", + " MenuIem(before='y', after='t', number=14),\n", + " MenuIem(before='b', after='g', number=15),\n", + " MenuIem(before='r', after='y', number=16),\n", + " MenuIem(before='i', after='w', number=17),\n", + " MenuIem(before='t', after='d', number=18),\n", + " MenuIem(before='i', after='m', number=19),\n", + " MenuIem(before='s', after='p', number=20)]" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tbt_menu = [MenuItem(p, c, i+1) for i, (p, c) in enumerate(zip(target_pt[4:24], target_ct[4:24]))]\n", + "tbt_menu" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "tbt_bombe = Bombe(wheel_iii_spec, wheel_i_spec, wheel_ii_spec, reflector_b_spec, \n", + " menu=tbt_menu)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('k', 'r', 'n')]" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tbt_wheel_posns = run_multi_bombe(wheel_iii_spec, wheel_i_spec, wheel_ii_spec, reflector_b_spec, tbt_menu)\n", + "tbt_wheel_posns" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Signal(bank='e', wire='e')" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tbt_bombe.test_start" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "a : abcdefghi..lmnop.rst.v.x.z\n", + "b : a...ef.hi..lmnop.r.t...x..\n", + "c : a..defg.i..lmn.p.rst...x..\n", + "d : a.c.efghi.klmnopqrstu.wxyz\n", + "e : abcdefghijklmnopqrstuvwx.z\n", + "f : abcdefghijklmno.qrstuvwxyz\n", + "g : a.cdefghijklmnopqrstuvwxyz\n", + "h : ab.defghi...mnopqrstuvwxyz\n", + "i : abcdefghijklm.opqrstuvwxyz\n", + "j : ....efg.i..lmnop...t...x..\n", + "k : ...defg.i..lmn.p..st...x..\n", + "l : abcdefg.ijklmnopqrstuv.x..\n", + "m : abcdefghijkl.nopqrstuvwxyz\n", + "n : abcdefgh.jklmnopqrstuvwxyz\n", + "o : ab.defghij.lmnop.r.tuvwxyz\n", + "p : abcde.ghijklmnopqrstuvwxyz\n", + "q : ...defghi..lmn.p..st...x..\n", + "r : abcdefghi..lmnop.rst.v.x.z\n", + "s : a.cdefghi.klmn.pqr.tuvwxyz\n", + "t : abcdefghijklmnopqrstuvw.yz\n", + "u : ...defghi..lmnop..st...x..\n", + "v : a...efghi..lmnop.rst...x..\n", + "w : ...defghi...mnop..st...x..\n", + "x : abcdefghijklmnopqrs.uvwxyz\n", + "y : ...d.fghi...mnop..st...x..\n", + "z : a..defghi...mnop.rst...x..\n" + ] + } + ], + "source": [ + "r = tbt_bombe.test(start_positions=('l', 's', 'd'))\n", + "print(r)\n", + "for b in sorted(w_bombe.banks):\n", + " print(b, ': ', end='')\n", + " for w in sorted(w_bombe.banks[b]):\n", + " if w_bombe.banks[b][w]:\n", + " print(w, end='')\n", + " else:\n", + " print('.', end='')\n", + " print('')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "set()" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ps = tbt_bombe.possible_plugboards()\n", + "ps" + ] + }, { "cell_type": "code", "execution_count": null, @@ -1770,9 +1966,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1+" + "version": "3.5.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 }