"cells": [
{
"cell_type": "code",
- "execution_count": 797,
+ "execution_count": 2,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 798,
+ "execution_count": 3,
"metadata": {
"collapsed": true
},
},
{
"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
},
},
{
"cell_type": "code",
- "execution_count": 802,
+ "execution_count": 5,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 803,
+ "execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"class Bombe(object):\n",
+ " \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",
" 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",
" 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"
]
},
{
##################################
# # 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'])
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):