X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=bombe.ipynb;h=93e0ccbfcd5ac4996251c5eb08db7e6deadd969b;hb=15b19a3315ed3cf9081ff2c1b0dd77de59164a77;hp=59442e4f4da5bf6481be0f923171939245d2c938;hpb=5184c96f06f9f97d6af9b3d994e9b227cbb8b76c;p=cipher-tools.git diff --git a/bombe.ipynb b/bombe.ipynb index 59442e4..93e0ccb 100644 --- a/bombe.ipynb +++ b/bombe.ipynb @@ -75,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 31, "metadata": { "collapsed": false }, @@ -116,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", @@ -199,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 32, "metadata": { "collapsed": false }, @@ -211,7 +212,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 33, "metadata": { "collapsed": true }, @@ -227,7 +228,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -238,7 +239,7 @@ "'opgndxcrwomnlnecjz'" ] }, - "execution_count": 7, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -252,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 35, "metadata": { "collapsed": false }, @@ -263,7 +264,7 @@ "'aas'" ] }, - "execution_count": 8, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -274,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 36, "metadata": { "collapsed": false }, @@ -302,7 +303,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 9, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -314,7 +315,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 37, "metadata": { "collapsed": true }, @@ -327,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 38, "metadata": { "collapsed": false }, @@ -355,7 +356,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 11, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -366,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 39, "metadata": { "collapsed": false }, @@ -377,7 +378,7 @@ "'s'" ] }, - "execution_count": 12, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -388,7 +389,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 42, "metadata": { "collapsed": false }, @@ -399,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 43, "metadata": { "collapsed": false }, @@ -410,7 +411,7 @@ "18" ] }, - "execution_count": 14, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -421,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 27, "metadata": { "collapsed": false }, @@ -430,6 +431,24 @@ "name": "stdout", "output_type": "stream", "text": [ + "['t', 'o'] aaa\n", + "['h', 'p'] aab\n", + "['i', 'g'] aac\n", + "['s', 'n'] aad\n", + "['i', 'd'] aae\n", + "['s', 'x'] aaf\n", + "['a', 'c'] aag\n", + "['t', 'r'] aah\n", + "['e', 'w'] aai\n", + "['s', 'o'] aaj\n", + "['t', 'm'] aak\n", + "['m', 'n'] aal\n", + "['e', 'l'] aam\n", + "['s', 'n'] aan\n", + "['s', 'e'] aao\n", + "['a', 'c'] aap\n", + "['g', 'j'] aaq\n", + "['e', 'z'] aar\n", "['t', 'o'] aaa\n", "['h', 'p'] aab\n", "['i', 'g'] aac\n", @@ -458,7 +477,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 44, "metadata": { "collapsed": false }, @@ -466,10 +485,54 @@ { "data": { "text/plain": [ - "False" + "'ot:hp:gi:ns:di:sx:ac:rt:ew:os:mt:mn:el:ns:es:ac:gj:ez'" ] }, - "execution_count": 16, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "':'.join(cat(sorted(c.banks)) for c in bombe.connections)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'aaa:aab:aac:aad:aae:aaf:aag:aah:aai:aaj:aak:aal:aam:aan:aao:aap:aaq:aar'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "':'.join(cat(c.scrambler.wheel_positions_l) for c in bombe.connections)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -480,7 +543,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 57, "metadata": { "collapsed": false }, @@ -488,35 +551,35 @@ { "data": { "text/plain": [ - "{'a': True,\n", - " 'b': True,\n", - " 'c': True,\n", - " 'd': True,\n", - " 'e': True,\n", - " 'f': True,\n", - " 'g': True,\n", - " 'h': True,\n", - " 'i': True,\n", - " 'j': True,\n", - " 'k': True,\n", - " 'l': True,\n", - " 'm': True,\n", - " 'n': True,\n", - " 'o': True,\n", - " 'p': True,\n", - " 'q': True,\n", - " 'r': True,\n", - " 's': True,\n", + "{'a': False,\n", + " 'b': False,\n", + " 'c': False,\n", + " 'd': False,\n", + " 'e': False,\n", + " 'f': False,\n", + " 'g': False,\n", + " 'h': False,\n", + " 'i': False,\n", + " 'j': False,\n", + " 'k': False,\n", + " 'l': False,\n", + " 'm': False,\n", + " 'n': False,\n", + " 'o': False,\n", + " 'p': False,\n", + " 'q': False,\n", + " 'r': False,\n", + " 's': False,\n", " 't': True,\n", - " 'u': True,\n", - " 'v': True,\n", - " 'w': True,\n", - " 'x': True,\n", - " 'y': True,\n", - " 'z': True}" + " 'u': False,\n", + " 'v': False,\n", + " 'w': False,\n", + " 'x': False,\n", + " 'y': False,\n", + " 'z': False}" ] }, - "execution_count": 17, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -527,7 +590,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 48, "metadata": { "collapsed": false }, @@ -578,7 +641,58 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 49, + "metadata": { + "collapsed": false + }, + "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": 50, "metadata": { "collapsed": false }, @@ -589,7 +703,7 @@ "('a', 'a', 'a')" ] }, - "execution_count": 19, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -600,7 +714,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 51, "metadata": { "collapsed": false }, @@ -638,7 +752,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 52, "metadata": { "collapsed": false }, @@ -650,7 +764,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 53, "metadata": { "collapsed": false }, @@ -704,7 +818,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 54, "metadata": { "collapsed": false }, @@ -758,7 +872,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 55, "metadata": { "collapsed": false }, @@ -769,7 +883,7 @@ "1" ] }, - "execution_count": 24, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -1051,7 +1165,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 58, "metadata": { "collapsed": false }, @@ -1070,7 +1184,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 59, "metadata": { "collapsed": false }, @@ -1081,7 +1195,7 @@ "('e', 'l', 'e')" ] }, - "execution_count": 38, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1738,7 +1852,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3+" + "version": "3.5.1+" } }, "nbformat": 4,