From 388422468f7dcf309d03005822ba8be9d2709b6e Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 20 May 2016 11:18:25 +0100 Subject: [PATCH] Tweaks --- bombe.ipynb | 84 +++++++++-------------------------------------------- enigma.py | 5 +++- 2 files changed, 17 insertions(+), 72 deletions(-) diff --git a/bombe.ipynb b/bombe.ipynb index ab1b457..c340539 100644 --- a/bombe.ipynb +++ b/bombe.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 797, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -17,7 +17,7 @@ }, { "cell_type": "code", - "execution_count": 798, + "execution_count": 3, "metadata": { "collapsed": true }, @@ -49,68 +49,7 @@ }, { "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 }, @@ -123,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 802, + "execution_count": 5, "metadata": { "collapsed": true }, @@ -168,15 +107,17 @@ }, { "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", @@ -198,9 +139,10 @@ " 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", @@ -284,7 +226,7 @@ " 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" ] }, { diff --git a/enigma.py b/enigma.py index 72f4807..cb57f7a 100644 --- a/enigma.py +++ b/enigma.py @@ -1003,6 +1003,9 @@ class Enigma(object): ################################## # # 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']) @@ -1046,7 +1049,7 @@ class Scrambler(object): 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): -- 2.34.1