From cc215dec21447bca7c2fb8016df255ab1aac512a Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sat, 4 Jun 2016 21:55:02 +0100 Subject: [PATCH] Updated after tests with real Enigma machine --- Untitled.ipynb | 181 --------------------------------------------- bombe.ipynb | 196 ++++++++++++++++++++++++------------------------- enigma.ipynb | 2 +- enigma.py | 14 +++- test_enigma.py | 83 ++++++++++++++++++++- 5 files changed, 190 insertions(+), 286 deletions(-) delete mode 100644 Untitled.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index 0a8a3e0..0000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,181 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "from enigma import *" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "e31 = Enigma(reflector_b_spec, \n", - " wheel_i_spec, wheel_i_pegs,\n", - " wheel_v_spec, wheel_v_pegs,\n", - " wheel_iii_spec, wheel_iii_pegs,\n", - " 6, 20, 24, \n", - " 'ua pf rq so ni ey bg hl tx zj')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "def advance(e, n):\n", - " def print_state(e):\n", - " print(' self.assertEqual(self.enigma31.wheel_positions, {})'.format(e.wheel_positions))\n", - " print(\" self.assertEqual(cat(self.enigma31.wheel_positions_l), '{}')\".format(cat(e.wheel_positions_l)))\n", - " print(' self.assertEqual(self.enigma31.peg_positions, {})'.format(e.peg_positions))\n", - " print()\n", - " \n", - " \n", - " \n", - " print_state(e)\n", - " for i in range(n):\n", - " print(' self.engima31.advance()')\n", - " e.advance()\n", - " print_state(e)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " self.assertEqual(self.enigma31.wheel_positions, (21, 5, 22))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'ayt')\n", - " self.assertEqual(self.enigma31.peg_positions, ([16], [1], [2]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (21, 5, 23))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'ayu')\n", - " self.assertEqual(self.enigma31.peg_positions, ([16], [1], [1]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (21, 5, 24))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'ayv')\n", - " self.assertEqual(self.enigma31.peg_positions, ([16], [1], [0]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (21, 6, 25))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'azw')\n", - " self.assertEqual(self.enigma31.peg_positions, ([16], [0], [25]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 7, 0))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bax')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [25], [24]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 7, 1))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bay')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [25], [23]))\n", - "\n" - ] - } - ], - "source": [ - "e31.set_wheels('a', 'y', 't')\n", - "advance(e31, 5)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " self.assertEqual(self.enigma31.wheel_positions, (21, 6, 21))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'azs')\n", - " self.assertEqual(self.enigma31.peg_positions, ([16], [0], [3]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 7, 22))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bat')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [25], [2]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 7, 23))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bau')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [25], [1]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 7, 24))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bav')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [25], [0]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 8, 25))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bbw')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [24], [25]))\n", - "\n", - " self.engima31.advance()\n", - " self.assertEqual(self.enigma31.wheel_positions, (22, 8, 0))\n", - " self.assertEqual(cat(self.enigma31.wheel_positions_l), 'bbx')\n", - " self.assertEqual(self.enigma31.peg_positions, ([15], [24], [24]))\n", - "\n" - ] - } - ], - "source": [ - "e31.set_wheels('a', 'z', 's')\n", - "advance(e31, 5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.1+" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/bombe.ipynb b/bombe.ipynb index 99770da..59442e4 100644 --- a/bombe.ipynb +++ b/bombe.ipynb @@ -17,7 +17,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": { "collapsed": true }, @@ -75,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -199,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": { "collapsed": true }, @@ -227,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -238,7 +238,7 @@ "'opgndxcrwomnlnecjz'" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -252,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": { "collapsed": false }, @@ -263,7 +263,7 @@ "'aas'" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -274,7 +274,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": { "collapsed": false }, @@ -302,7 +302,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": { "collapsed": true }, @@ -327,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -355,7 +355,7 @@ " MenuIem(before='e', after='z', number=18)]" ] }, - "execution_count": 12, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -366,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": { "collapsed": false }, @@ -377,7 +377,7 @@ "'s'" ] }, - "execution_count": 13, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -388,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": { "collapsed": false }, @@ -399,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": { "collapsed": false }, @@ -410,7 +410,7 @@ "18" ] }, - "execution_count": 15, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -421,7 +421,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": { "collapsed": false }, @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": { "collapsed": false }, @@ -469,7 +469,7 @@ "False" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -480,7 +480,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": { "collapsed": false }, @@ -516,7 +516,7 @@ " 'z': True}" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -527,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "metadata": { "collapsed": false }, @@ -578,7 +578,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": { "collapsed": false }, @@ -589,7 +589,7 @@ "('a', 'a', 'a')" ] }, - "execution_count": 20, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -600,7 +600,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "metadata": { "collapsed": false }, @@ -638,7 +638,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": { "collapsed": false }, @@ -650,7 +650,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": { "collapsed": false }, @@ -704,7 +704,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "metadata": { "collapsed": false }, @@ -758,7 +758,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": { "collapsed": false }, @@ -769,7 +769,7 @@ "1" ] }, - "execution_count": 25, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -780,7 +780,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": { "collapsed": false }, @@ -793,7 +793,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": { "collapsed": false }, @@ -806,7 +806,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "metadata": { "collapsed": false }, @@ -817,7 +817,7 @@ "('a', 'a', 'b')" ] }, - "execution_count": 28, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -828,7 +828,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "metadata": { "collapsed": false }, @@ -839,7 +839,7 @@ "False" ] }, - "execution_count": 29, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -850,7 +850,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 29, "metadata": { "collapsed": false }, @@ -861,7 +861,7 @@ "('p', 'p', 'p')" ] }, - "execution_count": 30, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -872,7 +872,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 30, "metadata": { "collapsed": false }, @@ -923,7 +923,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": { "collapsed": false }, @@ -934,7 +934,7 @@ "17576" ] }, - "execution_count": 32, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -946,7 +946,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 32, "metadata": { "collapsed": false }, @@ -957,7 +957,7 @@ "(('a', 'a', 'b'), True)" ] }, - "execution_count": 33, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -969,7 +969,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 33, "metadata": { "collapsed": false }, @@ -980,7 +980,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -991,7 +991,7 @@ "[('a', 'a', 'b')]" ] }, - "execution_count": 35, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -1007,7 +1007,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 35, "metadata": { "collapsed": true }, @@ -1029,7 +1029,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 36, "metadata": { "collapsed": false }, @@ -1040,7 +1040,7 @@ "[('a', 'a', 'b')]" ] }, - "execution_count": 37, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -1051,7 +1051,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "metadata": { "collapsed": false }, @@ -1070,7 +1070,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 38, "metadata": { "collapsed": false }, @@ -1081,7 +1081,7 @@ "('e', 'l', 'e')" ] }, - "execution_count": 39, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -1093,7 +1093,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 39, "metadata": { "collapsed": false }, @@ -1104,7 +1104,7 @@ "'dhnpforeeimgg'" ] }, - "execution_count": 40, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1118,7 +1118,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "metadata": { "collapsed": false }, @@ -1129,7 +1129,7 @@ "('j', 'e', 'o')" ] }, - "execution_count": 41, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -1140,7 +1140,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 41, "metadata": { "collapsed": false }, @@ -1163,7 +1163,7 @@ " MenuIem(before='t', after='g', number=13)]" ] }, - "execution_count": 42, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1175,7 +1175,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 42, "metadata": { "collapsed": false, "scrolled": true @@ -1248,7 +1248,7 @@ " ('z', 'z', 'k')]" ] }, - "execution_count": 43, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1265,7 +1265,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 43, "metadata": { "collapsed": false }, @@ -1276,7 +1276,7 @@ "62" ] }, - "execution_count": 44, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1287,7 +1287,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 44, "metadata": { "collapsed": false, "scrolled": true @@ -1311,7 +1311,7 @@ " ('y', 'n', 'c')]" ] }, - "execution_count": 45, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1328,7 +1328,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "metadata": { "collapsed": false }, @@ -1351,7 +1351,7 @@ " ('y', 'n', 'c')]" ] }, - "execution_count": 46, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -1362,7 +1362,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 46, "metadata": { "collapsed": false }, @@ -1379,7 +1379,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 47, "metadata": { "collapsed": false }, @@ -1390,7 +1390,7 @@ "13" ] }, - "execution_count": 48, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -1401,7 +1401,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 48, "metadata": { "collapsed": false }, @@ -1413,7 +1413,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 49, "metadata": { "collapsed": false }, @@ -1424,7 +1424,7 @@ "Signal(bank='e', wire='e')" ] }, - "execution_count": 50, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -1435,7 +1435,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 50, "metadata": { "collapsed": false }, @@ -1446,7 +1446,7 @@ "True" ] }, - "execution_count": 51, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1457,7 +1457,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 51, "metadata": { "collapsed": false }, @@ -1468,7 +1468,7 @@ "True" ] }, - "execution_count": 52, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -1479,7 +1479,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 52, "metadata": { "collapsed": false }, @@ -1533,7 +1533,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 53, "metadata": { "collapsed": false }, @@ -1587,7 +1587,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 54, "metadata": { "collapsed": false }, @@ -1595,15 +1595,15 @@ { "data": { "text/plain": [ - "{frozenset({'b', 'g'}),\n", - " frozenset({'e', 'y'}),\n", - " frozenset({'t', 'x'}),\n", - " frozenset({'m'}),\n", + "{frozenset({'m'}),\n", " frozenset({'i', 'n'}),\n", - " frozenset({'f', 'p'})}" + " frozenset({'f', 'p'}),\n", + " frozenset({'t', 'x'}),\n", + " frozenset({'e', 'y'}),\n", + " frozenset({'b', 'g'})}" ] }, - "execution_count": 55, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -1615,7 +1615,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 55, "metadata": { "collapsed": false }, @@ -1626,7 +1626,7 @@ "True" ] }, - "execution_count": 56, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -1637,7 +1637,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 56, "metadata": { "collapsed": false }, @@ -1645,13 +1645,13 @@ { "data": { "text/plain": [ - "({frozenset({1, 2}), frozenset({2, 3}), frozenset({3, 4})},\n", + "({frozenset({1, 2}), frozenset({3, 4}), frozenset({2, 3})},\n", " frozenset({1, 2}),\n", " frozenset({3, 4}),\n", " frozenset({2, 3}))" ] }, - "execution_count": 57, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -1670,7 +1670,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 57, "metadata": { "collapsed": false }, @@ -1681,7 +1681,7 @@ "False" ] }, - "execution_count": 58, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -1692,7 +1692,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 58, "metadata": { "collapsed": false }, @@ -1703,7 +1703,7 @@ "False" ] }, - "execution_count": 59, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1738,7 +1738,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1+" + "version": "3.4.3+" } }, "nbformat": 4, diff --git a/enigma.ipynb b/enigma.ipynb index 086aa46..06f684a 100644 --- a/enigma.ipynb +++ b/enigma.ipynb @@ -2249,7 +2249,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1+" + "version": "3.4.3+" } }, "nbformat": 4, diff --git a/enigma.py b/enigma.py index 8c72f22..a0056e4 100644 --- a/enigma.py +++ b/enigma.py @@ -182,7 +182,11 @@ class SimpleWheel(LetterTransformer): return object.__getattribute__(self, name) def set_position(self, position): - self.position = ord(position) - ord('a') + if isinstance(position, str): + # self.position = ord(position) - ord('a') + self.position = pos(position) + else: + self.position = position def forward(self, letter): if letter in string.ascii_lowercase: @@ -234,8 +238,12 @@ class Wheel(SimpleWheel): return object.__getattribute__(self, name) def set_position(self, position): - self.position = (pos(position) - self.ring_setting + 1) % 26 - self.peg_positions = [(pos(p) - pos(position)) % 26 for p in self.ring_peg_letters] + if isinstance(position, str): + self.position = (pos(position) - self.ring_setting + 1) % 26 + else: + self.position = (position - self.ring_setting) % 26 + # self.peg_positions = [(pos(p) - pos(position)) % 26 for p in self.ring_peg_letters] + self.peg_positions = [(pos(p) - (self.position + self.ring_setting - 1)) % 26 for p in self.ring_peg_letters] def advance(self): super(Wheel, self).advance() diff --git a/test_enigma.py b/test_enigma.py index 830bb2b..9b59edb 100644 --- a/test_enigma.py +++ b/test_enigma.py @@ -93,6 +93,29 @@ class SimpleWheelTest(unittest.TestCase): for l in string.ascii_lowercase), 'ajpczwrlfbdkotyuqgenhxmivs') + def test_set_position(self): + wheel_3 = SimpleWheel(wheel_iii_spec) + wheel_3.set_position('a') + self.assertEqual(wheel_3.position, 0) + self.assertEqual(wheel_3.position_l, 'a') + + wheel_3.set_position('f') + self.assertEqual(wheel_3.position, 5) + self.assertEqual(wheel_3.position_l, 'f') + + wheel_3.advance() + self.assertEqual(wheel_3.position, 6) + self.assertEqual(wheel_3.position_l, 'g') + + wheel_3.set_position(12) + self.assertEqual(wheel_3.position, 12) + self.assertEqual(wheel_3.position_l, 'm') + + wheel_3.advance() + self.assertEqual(wheel_3.position, 13) + self.assertEqual(wheel_3.position_l, 'n') + + def test_advance(self): wheel_3 = SimpleWheel(wheel_iii_spec) wheel_3.set_position('a') @@ -131,7 +154,7 @@ class SimpleWheelTest(unittest.TestCase): 'tagbpcsdqeufvnzhyixjwlrkom') -class SimpleWheelTest(unittest.TestCase): +class WheelTest(unittest.TestCase): def test_init1(self): wheel = Wheel(wheel_iii_spec, wheel_iii_pegs, position='b', ring_setting=1) @@ -158,7 +181,6 @@ class SimpleWheelTest(unittest.TestCase): for l in string.ascii_lowercase), 'ptlyrmidoxbswhnfckquzgeavj') - def test_advance(self): wheel = Wheel(wheel_vi_spec, wheel_vi_pegs, position='b', ring_setting=3) @@ -243,7 +265,6 @@ class SimpleWheelTest(unittest.TestCase): for l in string.ascii_lowercase), 'ptlyrmidoxbswhnfckquzgeavj') - def test_advance_27(self): wheel = Wheel(wheel_vi_spec, wheel_vi_pegs, position='b', ring_setting=3) @@ -261,6 +282,54 @@ class SimpleWheelTest(unittest.TestCase): for l in string.ascii_lowercase), 'skxqlhcnwarvgmebjptyfdzuio') + def test_set_position(self): + wheel_3 = Wheel(wheel_iii_spec, wheel_iii_pegs, ring_setting=3) + wheel_3.set_position('a') + self.assertEqual(wheel_3.position, 24) + self.assertEqual(wheel_3.position_l, 'a') + self.assertEqual(wheel_3.peg_positions, [21]) + + wheel_3.set_position('z') + self.assertEqual(wheel_3.position, 23) + self.assertEqual(wheel_3.position_l, 'z') + self.assertEqual(wheel_3.peg_positions, [22]) + + wheel_3.set_position(26) + self.assertEqual(wheel_3.position, 23) + self.assertEqual(wheel_3.position_l, 'z') + self.assertEqual(wheel_3.peg_positions, [22]) + + wheel_3.set_position(27) + self.assertEqual(wheel_3.position, 24) + self.assertEqual(wheel_3.position_l, 'a') + self.assertEqual(wheel_3.peg_positions, [21]) + + wheel_3.set_position('f') + self.assertEqual(wheel_3.position, 3) + self.assertEqual(wheel_3.position_l, 'f') + self.assertEqual(wheel_3.peg_positions, [16]) + + wheel_3.set_position(6) + self.assertEqual(wheel_3.position, 3) + self.assertEqual(wheel_3.position_l, 'f') + self.assertEqual(wheel_3.peg_positions, [16]) + + wheel_3.advance() + self.assertEqual(wheel_3.position, 4) + self.assertEqual(wheel_3.position_l, 'g') + self.assertEqual(wheel_3.peg_positions, [15]) + + wheel_3.set_position(12) + self.assertEqual(wheel_3.position, 9) + self.assertEqual(wheel_3.position_l, 'l') + self.assertEqual(wheel_3.peg_positions, [10]) + + wheel_3.advance() + self.assertEqual(wheel_3.position, 10) + self.assertEqual(wheel_3.position_l, 'm') + self.assertEqual(wheel_3.peg_positions, [9]) + + class EnigmaTest(unittest.TestCase): def setUp(self): @@ -281,6 +350,14 @@ class EnigmaTest(unittest.TestCase): 6, 20, 24, 'ua pf rq so ni ey bg hl tx zj') + # Settings for Bletchley Park outreach department's Enigma + self.enigma_bp = Enigma(reflector_b_spec, + wheel_i_spec, wheel_i_pegs, + wheel_iii_spec, wheel_iii_pegs, + wheel_ii_spec, wheel_ii_pegs, + 1, 26, 26, + 'qm we ro tu zj ps dl fg') + def test_middle_advance(self): self.enigma.set_wheels('a', 'a', 't') -- 2.34.1