Tweaks
authorNeil Smith <neil.git@njae.me.uk>
Fri, 20 May 2016 10:18:25 +0000 (11:18 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Fri, 20 May 2016 10:18:25 +0000 (11:18 +0100)
bombe.ipynb
enigma.py

index ab1b457c441d51cb55d4e6a5d2385a37379fc6c2..c340539c46ee1642bb80f01ac9ee08a8b0e1fed0 100644 (file)
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 797,
+   "execution_count": 2,
    "metadata": {
     "collapsed": true
    },
    "metadata": {
     "collapsed": true
    },
@@ -17,7 +17,7 @@
   },
   {
    "cell_type": "code",
   },
   {
    "cell_type": "code",
-   "execution_count": 798,
+   "execution_count": 3,
    "metadata": {
     "collapsed": true
    },
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
   },
   {
    "cell_type": "code",
-   "execution_count": 799,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": [
-    "class Bank(object):\n",
-    "    def __init__(self):\n",
-    "        self.signals = dict(zip(string.ascii_lowercase, [False]*len(string.ascii_lowercase)))"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 800,
-   "metadata": {
-    "collapsed": false
-   },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "{'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': False,\n",
-       " 'u': False,\n",
-       " 'v': False,\n",
-       " 'w': False,\n",
-       " 'x': False,\n",
-       " 'y': False,\n",
-       " 'z': False}"
-      ]
-     },
-     "execution_count": 800,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
-   "source": [
-    "c1 = Bank()\n",
-    "c1.signals"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 801,
+   "execution_count": 4,
    "metadata": {
     "collapsed": true
    },
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
   },
   {
    "cell_type": "code",
-   "execution_count": 802,
+   "execution_count": 5,
    "metadata": {
     "collapsed": true
    },
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
   },
   {
    "cell_type": "code",
-   "execution_count": 803,
+   "execution_count": 6,
    "metadata": {
     "collapsed": false
    },
    "outputs": [],
    "source": [
     "class Bombe(object):\n",
    "metadata": {
     "collapsed": false
    },
    "outputs": [],
    "source": [
     "class Bombe(object):\n",
+    "    \n",
     "    def __init__(self, wheel1_spec, wheel2_spec, wheel3_spec, reflector_spec,\n",
     "    def __init__(self, wheel1_spec, wheel2_spec, wheel3_spec, reflector_spec,\n",
-    "                menu=None, start_signal=None, use_diagonal_board=True, verify_plugboard=True):\n",
+    "                menu=None, start_signal=None, use_diagonal_board=True, \n",
+    "                verify_plugboard=True):\n",
     "        self.connections = []\n",
     "        self.wheel1_spec = wheel1_spec\n",
     "        self.wheel2_spec = wheel2_spec\n",
     "        self.connections = []\n",
     "        self.wheel1_spec = wheel1_spec\n",
     "        self.wheel2_spec = wheel2_spec\n",
     "            return object.__getattribute__(self, name)\n",
     "        \n",
     "    def __call__(self, start_positions):\n",
     "            return object.__getattribute__(self, name)\n",
     "        \n",
     "    def __call__(self, start_positions):\n",
-    "        return start_positions, self.test(start_positions=start_positions, \n",
-    "                                          use_diagonal_board=self.use_diagonal_board,\n",
-    "                                          verify_plugboard=self.verify_plugboard)\n",
+    "        return start_positions, self.test(initial_signal=self.test_start,\n",
+    "            start_positions=start_positions, \n",
+    "            use_diagonal_board=self.use_diagonal_board,\n",
+    "            verify_plugboard=self.verify_plugboard)\n",
     "        \n",
     "    def add_connection(self, bank_before, bank_after, scrambler):\n",
     "        self.connections += [Connection([bank_before, bank_after], scrambler)]\n",
     "        \n",
     "    def add_connection(self, bank_before, bank_after, scrambler):\n",
     "        self.connections += [Connection([bank_before, bank_after], scrambler)]\n",
     "                possibles = possibles.union({frozenset((b, active[0]))})\n",
     "            if len(inactive) == 1:\n",
     "                possibles = possibles.union({frozenset((b, inactive[0]))})\n",
     "                possibles = possibles.union({frozenset((b, active[0]))})\n",
     "            if len(inactive) == 1:\n",
     "                possibles = possibles.union({frozenset((b, inactive[0]))})\n",
-    "        return possibles"
+    "        return possibles\n"
    ]
   },
   {
    ]
   },
   {
index 72f480792170725c0b59462781d338961c534510..cb57f7a26fd33a43bbddabac7bb9b9093ed3bf66 100644 (file)
--- a/enigma.py
+++ b/enigma.py
@@ -1003,6 +1003,9 @@ class Enigma(object):
 ##################################
 # # Bombe
 ##################################
 ##################################
 # # Bombe
 ##################################
+#
+# Good explanation of [how the bombe worked](http://www.ellsbury.com/enigmabombe.htm) by Graham Ellsbury
+#
 
 Signal = collections.namedtuple('Signal', ['bank', 'wire'])
 Connection = collections.namedtuple('Connection', ['banks', 'scrambler'])
 
 Signal = collections.namedtuple('Signal', ['bank', 'wire'])
 Connection = collections.namedtuple('Connection', ['banks', 'scrambler'])
@@ -1046,7 +1049,7 @@ class Scrambler(object):
         self.wheel3.set_position(wheel3_pos)      
 
 
         self.wheel3.set_position(wheel3_pos)      
 
 
-class Bombe(object):
+class Bombe(object): 
     def __init__(self, wheel1_spec, wheel2_spec, wheel3_spec, reflector_spec,
                 menu=None, start_signal=None, use_diagonal_board=True, 
                 verify_plugboard=True):
     def __init__(self, wheel1_spec, wheel2_spec, wheel3_spec, reflector_spec,
                 menu=None, start_signal=None, use_diagonal_board=True, 
                 verify_plugboard=True):