4 "cell_type": "markdown",
8 "Specification from [Codes and Ciphers](http://www.codesandciphers.org.uk/enigma/rotorspec.htm) page.\n",
10 "Example Enigma machines from [Louise Dale](http://enigma.louisedade.co.uk/enigma.html) (full simulation) and [EnigmaCo](http://enigmaco.de/enigma/enigma.html) (good animation of the wheels, but no ring settings).\n",
12 "There's also the nice Enigma simulator for Android by [Franklin Heath](https://franklinheath.co.uk/2012/02/04/our-first-app-published-enigma-simulator/), available on the [Google Play store](https://play.google.com/store/apps/details?id=uk.co.franklinheath.enigmasim&hl=en_GB)."
17 "execution_count": 733,
24 "import collections\n",
28 "def clean(text): return cat(l.lower() for l in text if l in string.ascii_letters)\n",
30 "def pos(letter): \n",
31 " if letter in string.ascii_lowercase:\n",
32 " return ord(letter) - ord('a')\n",
33 " elif letter in string.ascii_uppercase:\n",
34 " return ord(letter) - ord('A')\n",
38 "def unpos(number): return chr(number % 26 + ord('a'))"
43 "execution_count": 734,
49 "wheel_i_spec = 'ekmflgdqvzntowyhxuspaibrcj'\n",
50 "wheel_ii_spec = 'ajdksiruxblhwtmcqgznpyfvoe'\n",
51 "wheel_iii_spec = 'bdfhjlcprtxvznyeiwgakmusqo'\n",
52 "wheel_iv_spec = 'esovpzjayquirhxlnftgkdcmwb'\n",
53 "wheel_v_spec = 'vzbrgityupsdnhlxawmjqofeck'\n",
54 "wheel_vi_spec = 'jpgvoumfyqbenhzrdkasxlictw'\n",
55 "wheel_vii_spec = 'nzjhgrcxmyswboufaivlpekqdt'\n",
56 "wheel_viii_spec = 'fkqhtlxocbjspdzramewniuygv'\n",
57 "beta_wheel_spec = 'leyjvcnixwpbqmdrtakzgfuhos'\n",
58 "gamma_wheel_spec = 'fsokanuerhmbtiycwlqpzxvgjd'\n",
60 "wheel_i_pegs = ['q']\n",
61 "wheel_ii_pegs = ['e']\n",
62 "wheel_iii_pegs = ['v']\n",
63 "wheel_iv_pegs = ['j']\n",
64 "wheel_v_pegs = ['z']\n",
65 "wheel_vi_pegs = ['z', 'm']\n",
66 "wheel_vii_pegs = ['z', 'm']\n",
67 "wheel_viii_pegs = ['z', 'm']\n",
69 "reflector_b_spec = 'ay br cu dh eq fs gl ip jx kn mo tz vw'\n",
70 "reflector_c_spec = 'af bv cp dj ei go hy kr lz mx nw tq su'"
75 "execution_count": 735,
81 "class LetterTransformer(object):\n",
82 " def __init__(self, specification, raw_transform=False):\n",
83 " if raw_transform:\n",
84 " transform = specification\n",
86 " transform = self.parse_specification(specification)\n",
87 " self.validate_transform(transform)\n",
88 " self.make_transform_map(transform)\n",
90 " def parse_specification(self, specification):\n",
91 " return list(zip(string.ascii_lowercase, clean(specification)))\n",
92 " # return specification\n",
94 " def validate_transform(self, transform):\n",
95 " \"\"\"A set of pairs, of from-to\"\"\"\n",
96 " if len(transform) != 26:\n",
97 " raise ValueError(\"Transform specification has {} pairs, requires 26\".\n",
98 " format(len(transform)))\n",
99 " for p in transform:\n",
100 " if len(p) != 2:\n",
101 " raise ValueError(\"Not all mappings in transform \"\n",
102 " \"have two elements\")\n",
103 " if len(set([p[0] for p in transform])) != 26:\n",
104 " raise ValueError(\"Transform specification must list 26 origin letters\") \n",
105 " if len(set([p[1] for p in transform])) != 26:\n",
106 " raise ValueError(\"Transform specification must list 26 destination letters\") \n",
108 " def make_empty_transform(self):\n",
109 " self.forward_map = [0] * 26\n",
110 " self.backward_map = [0] * 26\n",
112 " def make_transform_map(self, transform):\n",
113 " self.make_empty_transform()\n",
114 " for p in transform:\n",
115 " self.forward_map[pos(p[0])] = pos(p[1])\n",
116 " self.backward_map[pos(p[1])] = pos(p[0])\n",
117 " return self.forward_map, self.backward_map\n",
119 " def forward(self, letter):\n",
120 " if letter in string.ascii_lowercase:\n",
121 " return unpos(self.forward_map[pos(letter)])\n",
125 " def backward(self, letter):\n",
126 " if letter in string.ascii_lowercase:\n",
127 " return unpos(self.backward_map[pos(letter)])\n",
134 "execution_count": 736,
170 "execution_count": 736,
172 "output_type": "execute_result"
176 "tmap = [('z', 'a')] + [(l, string.ascii_lowercase[i+1]) for i, l in enumerate(string.ascii_lowercase[:-1])]\n",
182 "execution_count": 737,
190 "'zyxwcabdefghijklmnopqrstuv'"
193 "execution_count": 737,
195 "output_type": "execute_result"
199 "cat(collections.OrderedDict.fromkeys('zyxwc' + string.ascii_lowercase))"
204 "execution_count": 738,
211 "tmap2 = list(zip(string.ascii_lowercase, cat(collections.OrderedDict.fromkeys('zyxwc' + string.ascii_lowercase))))"
216 "execution_count": 739,
279 "execution_count": 739,
281 "output_type": "execute_result"
285 "lt = LetterTransformer(tmap, raw_transform = True)\n",
286 "assert(lt.forward_map == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0])\n",
287 "assert(lt.backward_map == [25, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24])\n",
288 "lt.forward_map, lt.backward_map"
293 "execution_count": 740,
356 "execution_count": 740,
358 "output_type": "execute_result"
362 "lt = LetterTransformer(cat(collections.OrderedDict.fromkeys('zyxwc' + string.ascii_lowercase)))\n",
363 "assert(lt.forward_map == [25, 24, 23, 22, 2, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21])\n",
364 "assert(lt.backward_map == [5, 6, 4, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 3, 2, 1, 0])\n",
365 "assert(cat(lt.forward(l) for l in string.ascii_lowercase) == 'zyxwcabdefghijklmnopqrstuv')\n",
366 "assert(cat(lt.backward(l) for l in string.ascii_lowercase) == 'fgehijklmnopqrstuvwxyzdcba')\n",
367 "lt.forward_map, lt.backward_map"
372 "execution_count": 741,
380 "'zyxwcabdefghijklmnopqrstuv'"
383 "execution_count": 741,
385 "output_type": "execute_result"
389 "cat(lt.forward(l) for l in string.ascii_lowercase)"
394 "execution_count": 742,
402 "'fgehijklmnopqrstuvwxyzdcba'"
405 "execution_count": 742,
407 "output_type": "execute_result"
411 "cat(lt.backward(l) for l in string.ascii_lowercase)"
416 "execution_count": 743,
422 "class Plugboard(LetterTransformer):\n",
423 " def parse_specification(self, specification):\n",
424 " return [tuple(clean(p)) for p in specification.split()]\n",
426 " def validate_transform(self, transform):\n",
427 " \"\"\"A set of pairs, of from-to\"\"\"\n",
428 " for p in transform:\n",
429 " if len(p) != 2:\n",
430 " raise ValueError(\"Not all mappings in transform\"\n",
431 " \"have two elements\")\n",
433 " def make_empty_transform(self):\n",
434 " self.forward_map = list(range(26))\n",
435 " self.backward_map = list(range(26))\n",
437 " def make_transform_map(self, transform):\n",
438 " expanded_transform = transform + [tuple(reversed(p)) for p in transform]\n",
439 " return super(Plugboard, self).make_transform_map(expanded_transform)"
444 "execution_count": 744,
450 "pb = Plugboard([('a', 'z'), ('b', 'y')], raw_transform=True)"
455 "execution_count": 745,
463 "'zycdefghijklmnopqrstuvwxba'"
466 "execution_count": 745,
468 "output_type": "execute_result"
472 "cat(pb.forward(l) for l in string.ascii_lowercase)"
477 "execution_count": 746,
485 "'zycdefghijklmnopqrstuvwxba'"
488 "execution_count": 746,
490 "output_type": "execute_result"
494 "cat(pb.backward(l) for l in string.ascii_lowercase)"
499 "execution_count": 747,
505 "pb = Plugboard('az by')"
510 "execution_count": 748,
518 "('zycdefghijklmnopqrstuvwxba', 'zycdefghijklmnopqrstuvwxba')"
521 "execution_count": 748,
523 "output_type": "execute_result"
527 "cat(pb.forward(l) for l in string.ascii_lowercase), cat(pb.backward(l) for l in string.ascii_lowercase)"
532 "execution_count": 749,
540 "('ugcdypblnzkhmisfrqoxavwtej', 'ugcdypblnzkhmisfrqoxavwtej')"
543 "execution_count": 749,
545 "output_type": "execute_result"
549 "pb = Plugboard('ua pf rq so ni ey bg hl tx zj'.upper())\n",
550 "assert(pb.forward_map == pb.backward_map)\n",
551 "assert(pb.forward_map == [20, 6, 2, 3, 24, 15, 1, 11, 13, 25, 10, 7, 12, 8, 18, 5, 17, 16, 14, 23, 0, 21, 22, 19, 4, 9])\n",
552 "assert(cat(pb.forward(l) for l in string.ascii_lowercase) == 'ugcdypblnzkhmisfrqoxavwtej')\n",
553 "assert(cat(pb.backward(l) for l in string.ascii_lowercase) == 'ugcdypblnzkhmisfrqoxavwtej')\n",
554 "cat(pb.forward(l) for l in string.ascii_lowercase), cat(pb.backward(l) for l in string.ascii_lowercase)"
559 "execution_count": 750,
565 "class Reflector(Plugboard):\n",
566 " def validate_transform(self, transform):\n",
567 " if len(transform) != 13:\n",
568 " raise ValueError(\"Reflector specification has {} pairs, requires 13\".\n",
569 " format(len(transform)))\n",
570 " if len(set([p[0] for p in transform] + \n",
571 " [p[1] for p in transform])) != 26:\n",
572 " raise ValueError(\"Reflector specification does not contain 26 letters\")\n",
574 " super(Reflector, self).validate_transform(transform)\n",
575 " except ValueError as v:\n",
576 " raise ValueError(\"Not all mappings in reflector have two elements\")"
581 "execution_count": 751,
604 "execution_count": 751,
606 "output_type": "execute_result"
610 "# reflector_b_text = '(AY) (BR) (CU) (DH) (EQ) (FS) (GL) (IP) (JX) (KN) (MO) (TZ) (VW)'\n",
611 "reflector_b_l = [tuple(clean(p)) for p in reflector_b_spec.split()]\n",
617 "execution_count": 752,
623 "reflector_b = Reflector(reflector_b_spec)\n",
624 "assert(reflector_b.forward_map == reflector_b.backward_map)\n",
625 "assert(reflector_b.forward_map == [24, 17, 20, 7, 16, 18, 11, 3, 15, 23, 13, 6, 14, 10, 12, 8, 4, 1, 5, 25, 2, 22, 21, 9, 0, 19])\n",
626 "assert(cat(reflector_b.forward(l) for l in string.ascii_lowercase) == 'yruhqsldpxngokmiebfzcwvjat')\n",
627 "assert(cat(reflector_b.backward(l) for l in string.ascii_lowercase) == 'yruhqsldpxngokmiebfzcwvjat')"
632 "execution_count": 753,
640 "'yruhqsldpxngokmiebfzcwvjat'"
643 "execution_count": 753,
645 "output_type": "execute_result"
649 "cat(reflector_b.forward(l) for l in string.ascii_lowercase)"
654 "execution_count": 754,
660 "reflector_c = Reflector(reflector_c_spec)"
665 "execution_count": 755,
673 "'fvpjiaoyedrzxwgctkuqsbnmhl'"
676 "execution_count": 755,
678 "output_type": "execute_result"
682 "cat(reflector_c.forward(l) for l in string.ascii_lowercase)"
687 "execution_count": 756,
693 "class SimpleWheel(LetterTransformer):\n",
694 " def __init__(self, transform, position='a', raw_transform=False):\n",
695 " super(SimpleWheel, self).__init__(transform, raw_transform)\n",
696 " self.set_position(position)\n",
698 " def __getattribute__(self,name):\n",
699 " if name=='position_l':\n",
700 " return unpos(self.position)\n",
702 " return object.__getattribute__(self, name)\n",
704 " def set_position(self, position):\n",
705 " self.position = ord(position) - ord('a')\n",
707 " def forward(self, letter):\n",
708 " if letter in string.ascii_lowercase:\n",
709 " return unpos((self.forward_map[(pos(letter) + self.position) % 26] - self.position))\n",
713 " def backward(self, letter):\n",
714 " if letter in string.ascii_lowercase:\n",
715 " return unpos((self.backward_map[(pos(letter) + self.position) % 26] - self.position))\n",
719 " def advance(self):\n",
720 " self.position = (self.position + 1) % 26\n",
721 " return self.position"
726 "execution_count": 757,
763 "execution_count": 757,
765 "output_type": "execute_result"
769 "rotor_1_transform = list(zip(string.ascii_lowercase, 'EKMFLGDQVZNTOWYHXUSPAIBRCJ'.lower()))\n",
775 "execution_count": 758,
781 "rotor_1_transform = list(zip(string.ascii_lowercase, 'EKMFLGDQVZNTOWYHXUSPAIBRCJ'.lower()))\n",
782 "wheel_1 = SimpleWheel(rotor_1_transform, raw_transform=True)\n",
783 "assert(cat(wheel_1.forward(l) for l in string.ascii_lowercase) == 'ekmflgdqvzntowyhxuspaibrcj')\n",
784 "assert(cat(wheel_1.backward(l) for l in string.ascii_lowercase) == 'uwygadfpvzbeckmthxslrinqoj')"
789 "execution_count": 759,
797 "('ekmflgdqvzntowyhxuspaibrcj', 'uwygadfpvzbeckmthxslrinqoj')"
800 "execution_count": 759,
802 "output_type": "execute_result"
806 "cat(wheel_1.forward(l) for l in string.ascii_lowercase), cat(wheel_1.backward(l) for l in string.ascii_lowercase)"
811 "execution_count": 760,
822 "execution_count": 760,
824 "output_type": "execute_result"
833 "execution_count": 761,
839 "wheel_2 = SimpleWheel(wheel_ii_spec)\n",
840 "assert(cat(wheel_2.forward(l) for l in string.ascii_lowercase) == 'ajdksiruxblhwtmcqgznpyfvoe')\n",
841 "assert(cat(wheel_2.backward(l) for l in string.ascii_lowercase) == 'ajpczwrlfbdkotyuqgenhxmivs')"
846 "execution_count": 762,
854 "('ajdksiruxblhwtmcqgznpyfvoe', 'ajpczwrlfbdkotyuqgenhxmivs')"
857 "execution_count": 762,
859 "output_type": "execute_result"
863 "cat(wheel_2.forward(l) for l in string.ascii_lowercase), cat(wheel_2.backward(l) for l in string.ascii_lowercase)"
868 "execution_count": 763,
876 "('bdfhjlcprtxvznyeiwgakmusqo', 'tagbpcsdqeufvnzhyixjwlrkom')"
879 "execution_count": 763,
881 "output_type": "execute_result"
885 "wheel_3 = SimpleWheel(wheel_iii_spec)\n",
886 "wheel_3.set_position('a')\n",
887 "wheel_3.advance()\n",
888 "assert(cat(wheel_3.forward(l) for l in string.ascii_lowercase) == 'cegikboqswuymxdhvfzjltrpna')\n",
889 "assert(cat(wheel_3.backward(l) for l in string.ascii_lowercase) == 'zfaobrcpdteumygxhwivkqjnls')\n",
890 "assert(wheel_3.position == 1)\n",
891 "assert(wheel_3.position_l == 'b')\n",
893 "for _ in range(24): wheel_3.advance()\n",
894 "assert(wheel_3.position == 25)\n",
895 "assert(wheel_3.position_l == 'z')\n",
896 "assert(cat(wheel_3.forward(l) for l in string.ascii_lowercase) == 'pcegikmdqsuywaozfjxhblnvtr')\n",
897 "assert(cat(wheel_3.backward(l) for l in string.ascii_lowercase) == 'nubhcqdterfvgwoaizjykxmslp')\n",
899 "wheel_3.advance()\n",
900 "assert(wheel_3.position == 0)\n",
901 "assert(wheel_3.position_l == 'a')\n",
902 "assert(cat(wheel_3.forward(l) for l in string.ascii_lowercase) == 'bdfhjlcprtxvznyeiwgakmusqo')\n",
903 "assert(cat(wheel_3.backward(l) for l in string.ascii_lowercase) == 'tagbpcsdqeufvnzhyixjwlrkom')\n",
905 "cat(wheel_3.forward(l) for l in string.ascii_lowercase), cat(wheel_3.backward(l) for l in string.ascii_lowercase)"
910 "execution_count": 764,
916 "class Wheel(SimpleWheel):\n",
917 " def __init__(self, transform, ring_peg_letters, ring_setting=1, position='a', raw_transform=False):\n",
918 " self.ring_peg_letters = ring_peg_letters\n",
919 " self.ring_setting = ring_setting\n",
920 " super(Wheel, self).__init__(transform, position=position, raw_transform=raw_transform)\n",
921 " self.set_position(position)\n",
923 " def __getattribute__(self,name):\n",
924 " if name=='position_l':\n",
925 " return unpos(self.position + self.ring_setting - 1)\n",
927 " return object.__getattribute__(self, name)\n",
929 " def set_position(self, position):\n",
930 " self.position = (pos(position) - self.ring_setting + 1) % 26\n",
931 " # self.position_l = position\n",
932 " self.peg_positions = [(pos(p) - pos(position)) % 26 for p in self.ring_peg_letters]\n",
934 " def advance(self):\n",
935 " super(Wheel, self).advance()\n",
936 " self.peg_positions = [(p - 1) % 26 for p in self.peg_positions]\n",
937 " # self.position_l = unpos(self.position + self.ring_setting - 1)\n",
938 " return self.position"
943 "execution_count": 765,
949 "wheel_3 = Wheel(wheel_iii_spec, wheel_iii_pegs, position='b', ring_setting=1)"
954 "execution_count": 766,
965 "execution_count": 766,
967 "output_type": "execute_result"
971 "wheel_3.position, wheel_3.peg_positions"
976 "execution_count": 767,
987 "execution_count": 767,
989 "output_type": "execute_result"
993 "wheel_6 = Wheel(wheel_vi_spec, wheel_vi_pegs, position='b', ring_setting=3)\n",
994 "wheel_6.position, wheel_6.peg_positions"
999 "execution_count": 768,
1007 "output_type": "stream",
1040 "for _ in range(27):\n",
1041 " wheel_6.advance()\n",
1042 " print(wheel_6.position, wheel_6.peg_positions)"
1046 "cell_type": "code",
1047 "execution_count": 769,
1053 "wheel_3 = Wheel(wheel_iii_spec, wheel_iii_pegs, position='b', ring_setting=1)\n",
1054 "assert(wheel_3.position == 1)\n",
1055 "assert(wheel_3.peg_positions == [20])\n",
1056 "assert(wheel_3.position_l == 'b')\n",
1057 "wheel_3.advance()\n",
1058 "assert(wheel_3.position == 2)\n",
1059 "assert(wheel_3.peg_positions == [19])\n",
1060 "assert(wheel_3.position_l == 'c')"
1064 "cell_type": "code",
1065 "execution_count": 770,
1071 "wheel_6 = Wheel(wheel_vi_spec, wheel_vi_pegs, position='b', ring_setting=3)\n",
1072 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'xkqhwpvngzrcfoiaselbtymjdu')\n",
1073 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'ptlyrmidoxbswhnfckquzgeavj')\n",
1074 "assert(wheel_6.position == 25)\n",
1075 "assert(11 in wheel_6.peg_positions)\n",
1076 "assert(24 in wheel_6.peg_positions)\n",
1077 "assert(wheel_6.position_l == 'b')\n",
1079 "wheel_6.advance()\n",
1080 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'jpgvoumfyqbenhzrdkasxlictw')\n",
1081 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'skxqlhcnwarvgmebjptyfdzuio')\n",
1082 "assert(wheel_6.position == 0)\n",
1083 "assert(10 in wheel_6.peg_positions)\n",
1084 "assert(23 in wheel_6.peg_positions)\n",
1085 "assert(wheel_6.position_l == 'c')\n",
1087 "for _ in range(22): wheel_6.advance()\n",
1088 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'mgxantkzsyqjcufirldvhoewbp')\n",
1089 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'dymswobuplgraevzkqifntxcjh')\n",
1090 "assert(wheel_6.position == 22)\n",
1091 "assert(1 in wheel_6.peg_positions)\n",
1092 "assert(14 in wheel_6.peg_positions)\n",
1093 "assert(wheel_6.position_l == 'y')\n",
1095 "wheel_6.advance()\n",
1096 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'fwzmsjyrxpibtehqkcugndvaol')\n",
1097 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'xlrvnatokfqzduyjphemswbigc')\n",
1098 "assert(wheel_6.position == 23)\n",
1099 "assert(0 in wheel_6.peg_positions)\n",
1100 "assert(13 in wheel_6.peg_positions)\n",
1101 "assert(wheel_6.position_l == 'z')\n",
1103 "wheel_6.advance()\n",
1104 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'vylrixqwohasdgpjbtfmcuznke')\n",
1105 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'kqumzsnjepyctxiogdlrvahfbw')\n",
1106 "assert(wheel_6.position == 24)\n",
1107 "assert(25 in wheel_6.peg_positions)\n",
1108 "assert(12 in wheel_6.peg_positions)\n",
1109 "assert(wheel_6.position_l == 'a')\n",
1111 "wheel_6.advance()\n",
1112 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'xkqhwpvngzrcfoiaselbtymjdu')\n",
1113 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'ptlyrmidoxbswhnfckquzgeavj')\n",
1114 "assert(wheel_6.position == 25)\n",
1115 "assert(24 in wheel_6.peg_positions)\n",
1116 "assert(11 in wheel_6.peg_positions)\n",
1117 "assert(wheel_6.position_l == 'b')\n",
1119 "wheel_6.advance()\n",
1120 "assert(cat(wheel_6.forward(l) for l in string.ascii_lowercase) == 'jpgvoumfyqbenhzrdkasxlictw')\n",
1121 "assert(cat(wheel_6.backward(l) for l in string.ascii_lowercase) == 'skxqlhcnwarvgmebjptyfdzuio')\n",
1122 "assert(wheel_6.position == 0)\n",
1123 "assert(23 in wheel_6.peg_positions)\n",
1124 "assert(10 in wheel_6.peg_positions)\n",
1125 "assert(wheel_6.position_l == 'c')"
1129 "cell_type": "code",
1130 "execution_count": 771,
1138 "(0, 'c', [23, 10])"
1141 "execution_count": 771,
1143 "output_type": "execute_result"
1147 "wheel_6.position, wheel_6.position_l, wheel_6.peg_positions"
1151 "cell_type": "code",
1152 "execution_count": 772,
1158 "class Enigma(object):\n",
1159 " def __init__(self, reflector_spec,\n",
1160 " left_wheel_spec, left_wheel_pegs,\n",
1161 " middle_wheel_spec, middle_wheel_pegs,\n",
1162 " right_wheel_spec, right_wheel_pegs,\n",
1163 " left_ring_setting, middle_ring_setting, right_ring_setting,\n",
1164 " plugboard_setting):\n",
1165 " self.reflector = Reflector(reflector_spec)\n",
1166 " self.left_wheel = Wheel(left_wheel_spec, left_wheel_pegs, ring_setting=left_ring_setting)\n",
1167 " self.middle_wheel = Wheel(middle_wheel_spec, middle_wheel_pegs, ring_setting=middle_ring_setting)\n",
1168 " self.right_wheel = Wheel(right_wheel_spec, right_wheel_pegs, ring_setting=right_ring_setting)\n",
1169 " self.plugboard = Plugboard(plugboard_setting)\n",
1171 " def __getattribute__(self,name):\n",
1172 " if name=='wheel_positions':\n",
1173 " return self.left_wheel.position, self.middle_wheel.position, self.right_wheel.position \n",
1174 " elif name=='wheel_positions_l':\n",
1175 " return self.left_wheel.position_l, self.middle_wheel.position_l, self.right_wheel.position_l \n",
1176 " elif name=='peg_positions':\n",
1177 " return self.left_wheel.peg_positions, self.middle_wheel.peg_positions, self.right_wheel.peg_positions\n",
1179 " return object.__getattribute__(self, name)\n",
1182 " def set_wheels(self, left_wheel_position, middle_wheel_position, right_wheel_position):\n",
1183 " self.left_wheel.set_position(left_wheel_position)\n",
1184 " self.middle_wheel.set_position(middle_wheel_position)\n",
1185 " self.right_wheel.set_position(right_wheel_position)\n",
1187 " def lookup(self, letter):\n",
1188 " a = self.plugboard.forward(letter)\n",
1189 " b = self.right_wheel.forward(a)\n",
1190 " c = self.middle_wheel.forward(b)\n",
1191 " d = self.left_wheel.forward(c)\n",
1192 " e = self.reflector.forward(d)\n",
1193 " f = self.left_wheel.backward(e)\n",
1194 " g = self.middle_wheel.backward(f)\n",
1195 " h = self.right_wheel.backward(g)\n",
1196 " i = self.plugboard.backward(h)\n",
1199 " def advance(self):\n",
1200 " advance_middle = False\n",
1201 " advance_left = False\n",
1202 " if 0 in self.right_wheel.peg_positions:\n",
1203 " advance_middle = True\n",
1204 " if 0 in self.middle_wheel.peg_positions:\n",
1205 " advance_left = True\n",
1206 " advance_middle = True\n",
1207 " self.right_wheel.advance()\n",
1208 " if advance_middle: self.middle_wheel.advance()\n",
1209 " if advance_left: self.left_wheel.advance()\n",
1211 " def encipher_letter(self, letter):\n",
1212 " self.advance()\n",
1213 " return self.lookup(letter)\n",
1215 " def encipher(self, message):\n",
1216 " enciphered = ''\n",
1217 " for letter in clean(message):\n",
1218 " enciphered += self.encipher_letter(letter)\n",
1219 " return enciphered"
1223 "cell_type": "code",
1224 "execution_count": 773,
1230 "enigma = Enigma(reflector_b_spec, \n",
1231 " wheel_i_spec, wheel_i_pegs,\n",
1232 " wheel_ii_spec, wheel_ii_pegs,\n",
1233 " wheel_iii_spec, wheel_iii_pegs,\n",
1239 "cell_type": "code",
1240 "execution_count": 774,
1251 "execution_count": 774,
1253 "output_type": "execute_result"
1257 "enigma.lookup('a')"
1261 "cell_type": "code",
1262 "execution_count": 775,
1273 "execution_count": 775,
1275 "output_type": "execute_result"
1279 "enigma.lookup('u')"
1283 "cell_type": "code",
1284 "execution_count": 776,
1292 "'uejobtpzwcnsrkdgvmlfaqiyxh'"
1295 "execution_count": 776,
1297 "output_type": "execute_result"
1301 "cat(enigma.lookup(l) for l in string.ascii_lowercase)"
1305 "cell_type": "code",
1306 "execution_count": 777,
1314 "output_type": "stream",
1316 "0 :: a a a ; [16] [4] [21] uejobtpzwcnsrkdgvmlfaqiyxh\n",
1317 "1 :: a a b ; [16] [4] [20] baqmfexihswpdytlcvjozrkgnu\n",
1318 "2 :: a a c ; [16] [4] [19] djralkwpobfeyqihncxzvugsmt\n",
1319 "3 :: a a d ; [16] [4] [18] zlejcuitgdmbkonsvxphfqyrwa\n",
1320 "4 :: a a e ; [16] [4] [17] gcblwtakqzhdosmxiunfryepvj\n",
1321 "5 :: a a f ; [16] [4] [16] osnirgfmdpvuhcajwebxlkqtzy\n",
1322 "6 :: a a g ; [16] [4] [15] wymvnqzjlhoicekuftxrpdasbg\n",
1323 "7 :: a a h ; [16] [4] [14] cjafkdztpbeuormiwnvhlsqyxg\n",
1324 "8 :: a a i ; [16] [4] [13] xijuyslvbczgnmqwotfrdhpaek\n",
1325 "9 :: a a j ; [16] [4] [12] lfzrwbytjisaovmuxdkhpneqgc\n",
1326 "10 :: a a k ; [16] [4] [11] tkezcqynuwbpvhslfxoaimjrgd\n",
1327 "11 :: a a l ; [16] [4] [10] kiwfnduxbsaotelqpvjmgrchzy\n",
1328 "12 :: a a m ; [16] [4] [9] sfkutbpoxycrnmhgwlaedzqijv\n",
1329 "13 :: a a n ; [16] [4] [8] baqwlkhgrsfextpocijnvudmzy\n",
1330 "14 :: a a o ; [16] [4] [7] teofbdzxqkjyrscvimnawpuhlg\n",
1331 "15 :: a a p ; [16] [4] [6] mhypswrbzxqvaondkgeutlfjci\n",
1332 "16 :: a a q ; [16] [4] [5] cpasnrhgkuixzevbyfdwjotlqm\n",
1333 "17 :: a a r ; [16] [4] [4] dlfatcjwygvbnmzrxpueskhqio\n",
1334 "18 :: a a s ; [16] [4] [3] lxymzjuqtfpadsrkhonigwvbce\n",
1335 "19 :: a a t ; [16] [4] [2] puvioztjdhxmlyeawsrgbcqknf\n",
1336 "20 :: a a u ; [16] [4] [1] baigpldqcowfyzjehvtsxrkumn\n",
1337 "21 :: a a v ; [16] [4] [0] mnvfydiwgzsoablrxpkutchqej\n",
1338 "22 :: a b w ; [16] [3] [25] ulfopcykswhbzvderqixanjtgm\n",
1339 "23 :: a b x ; [16] [3] [24] qmwftdyovursbzhxaklejicpgn\n",
1340 "24 :: a b y ; [16] [3] [23] oljmzxrvucybdqasngpwihtfke\n",
1341 "25 :: a b z ; [16] [3] [22] fwevcalzxutgysrqponkjdbimh\n"
1346 "enigma.set_wheels('a', 'a', 'a')\n",
1347 "for i in range(26):\n",
1348 " print(i, '::', \n",
1349 " enigma.left_wheel.position_l, enigma.middle_wheel.position_l, enigma.right_wheel.position_l, ';',\n",
1350 " enigma.left_wheel.peg_positions, enigma.middle_wheel.peg_positions, enigma.right_wheel.peg_positions, \n",
1351 " cat(enigma.lookup(l) for l in string.ascii_lowercase))\n",
1356 "cell_type": "code",
1357 "execution_count": 778,
1364 "enigma.set_wheels('a', 'a', 't')\n",
1365 "assert(enigma.wheel_positions == (0, 0, 19))\n",
1366 "assert(cat(enigma.wheel_positions_l) == 'aat')\n",
1367 "assert(enigma.peg_positions == ([16], [4], [2]))\n",
1368 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'puvioztjdhxmlyeawsrgbcqknf')\n",
1370 "enigma.advance()\n",
1371 "assert(enigma.wheel_positions == (0, 0, 20))\n",
1372 "assert(cat(enigma.wheel_positions_l) == 'aau')\n",
1373 "assert(enigma.peg_positions == ([16], [4], [1]))\n",
1374 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'baigpldqcowfyzjehvtsxrkumn')\n",
1376 "enigma.advance()\n",
1377 "assert(enigma.wheel_positions == (0, 0, 21))\n",
1378 "assert(cat(enigma.wheel_positions_l) == 'aav')\n",
1379 "assert(enigma.peg_positions == ([16], [4], [0]))\n",
1380 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'mnvfydiwgzsoablrxpkutchqej')\n",
1382 "enigma.advance()\n",
1383 "assert(enigma.wheel_positions == (0, 1, 22))\n",
1384 "assert(cat(enigma.wheel_positions_l) == 'abw')\n",
1385 "assert(enigma.peg_positions == ([16], [3], [25]))\n",
1386 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ulfopcykswhbzvderqixanjtgm')\n",
1388 "enigma.advance()\n",
1389 "assert(enigma.wheel_positions == (0, 1, 23))\n",
1390 "assert(cat(enigma.wheel_positions_l) == 'abx')\n",
1391 "assert(enigma.peg_positions == ([16], [3], [24]))\n",
1392 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qmwftdyovursbzhxaklejicpgn')\n",
1394 "enigma.advance()\n",
1395 "assert(enigma.wheel_positions == (0, 1, 24))\n",
1396 "assert(cat(enigma.wheel_positions_l) == 'aby')\n",
1397 "assert(enigma.peg_positions == ([16], [3], [23]))\n",
1398 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'oljmzxrvucybdqasngpwihtfke')\n"
1402 "cell_type": "code",
1403 "execution_count": 779,
1411 "output_type": "stream",
1413 "(1, 5, 24) ('b', 'f', 'y') ([15], [25], [23]) baknstqzrmcxjdvygiefwoulph\n"
1418 "enigma.set_wheels('a', 'd', 't')\n",
1419 "assert(enigma.wheel_positions == (0, 3, 19))\n",
1420 "assert(cat(enigma.wheel_positions_l) == 'adt')\n",
1421 "assert(enigma.peg_positions == ([16], [1], [2]))\n",
1422 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'zcbpqxwsjiuonmldethrkygfva')\n",
1424 "enigma.advance()\n",
1425 "assert(enigma.wheel_positions == (0, 3, 20))\n",
1426 "assert(cat(enigma.wheel_positions_l) == 'adu')\n",
1427 "assert(enigma.peg_positions == ([16], [1], [1]))\n",
1428 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ehprawjbngotxikcsdqlzyfmvu')\n",
1430 "enigma.advance()\n",
1431 "assert(enigma.wheel_positions == (0, 3, 21))\n",
1432 "assert(cat(enigma.wheel_positions_l) == 'adv')\n",
1433 "assert(enigma.peg_positions == ([16], [1], [0]))\n",
1434 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'eqzxarpihmnvjkwgbfuyslodtc')\n",
1436 "enigma.advance()\n",
1437 "assert(enigma.wheel_positions == (0, 4, 22))\n",
1438 "assert(cat(enigma.wheel_positions_l) == 'aew')\n",
1439 "assert(enigma.peg_positions == ([16], [0], [25]))\n",
1440 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qedcbtpluzmhkongavwfirsyxj')\n",
1442 "enigma.advance()\n",
1443 "assert(enigma.wheel_positions == (1, 5, 23))\n",
1444 "assert(cat(enigma.wheel_positions_l) == 'bfx')\n",
1445 "assert(enigma.peg_positions == ([15], [25], [24]))\n",
1446 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'iwuedhsfazqxytvrkpgncoblmj')\n",
1448 "enigma.advance()\n",
1449 "assert(enigma.wheel_positions == (1, 5, 24))\n",
1450 "assert(cat(enigma.wheel_positions_l) == 'bfy')\n",
1451 "assert(enigma.peg_positions == ([15], [25], [23]))\n",
1452 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'baknstqzrmcxjdvygiefwoulph')\n",
1454 "print(enigma.wheel_positions, enigma.wheel_positions_l, enigma.peg_positions, \n",
1455 " cat(enigma.lookup(l) for l in string.ascii_lowercase))\n"
1459 "cell_type": "code",
1460 "execution_count": 780,
1471 "execution_count": 780,
1473 "output_type": "execute_result"
1477 "enigma.set_wheels('a', 'a', 'a')\n",
1478 "ct = enigma.encipher('testmessage')\n",
1479 "assert(ct == 'olpfhnvflyn')\n",
1484 "cell_type": "code",
1485 "execution_count": 781,
1496 "execution_count": 781,
1498 "output_type": "execute_result"
1502 "enigma.set_wheels('a', 'd', 't')\n",
1503 "ct = enigma.encipher('testmessage')\n",
1504 "assert(ct == 'lawnjgpwjik')\n",
1509 "cell_type": "code",
1510 "execution_count": 782,
1517 "output_type": "stream",
1519 "enigma.advance()\n",
1520 "assert(enigma.wheel_positions == (1, 5, 5))\n",
1521 "assert(cat(enigma.wheel_positions_l) == 'bff')\n",
1522 "assert(enigma.peg_positions == ([15], [25], [16]))\n",
1523 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'zpqiogfsdlmjkyebcvhxwrutna')\n",
1525 "enigma.advance()\n",
1526 "assert(enigma.wheel_positions == (1, 5, 6))\n",
1527 "assert(cat(enigma.wheel_positions_l) == 'bfg')\n",
1528 "assert(enigma.peg_positions == ([15], [25], [15]))\n",
1529 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'fjmnwayslbxicdpouthrqzekgv')\n",
1531 "enigma.advance()\n",
1532 "assert(enigma.wheel_positions == (1, 5, 7))\n",
1533 "assert(cat(enigma.wheel_positions_l) == 'bfh')\n",
1534 "assert(enigma.peg_positions == ([15], [25], [14]))\n",
1535 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'csafzdyloxuhnmitwvbpkrqjge')\n",
1537 "enigma.advance()\n",
1538 "assert(enigma.wheel_positions == (1, 5, 8))\n",
1539 "assert(cat(enigma.wheel_positions_l) == 'bfi')\n",
1540 "assert(enigma.peg_positions == ([15], [25], [13]))\n",
1541 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'kihyvulcbtagwrqzonxjfemsdp')\n",
1543 "enigma.advance()\n",
1544 "assert(enigma.wheel_positions == (1, 5, 9))\n",
1545 "assert(cat(enigma.wheel_positions_l) == 'bfj')\n",
1546 "assert(enigma.peg_positions == ([15], [25], [12]))\n",
1547 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'pgzrytbksqhwxvuajdifonlmec')\n",
1549 "enigma.advance()\n",
1550 "assert(enigma.wheel_positions == (1, 5, 10))\n",
1551 "assert(cat(enigma.wheel_positions_l) == 'bfk')\n",
1552 "assert(enigma.peg_positions == ([15], [25], [11]))\n",
1553 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'fkirsazncwbvyhpoudexqljtmg')\n",
1555 "enigma.advance()\n",
1556 "assert(enigma.wheel_positions == (1, 5, 11))\n",
1557 "assert(cat(enigma.wheel_positions_l) == 'bfl')\n",
1558 "assert(enigma.peg_positions == ([15], [25], [10]))\n",
1559 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'mhkronubsvctafeqpdilgjxwzy')\n",
1561 "enigma.advance()\n",
1562 "assert(enigma.wheel_positions == (1, 5, 12))\n",
1563 "assert(cat(enigma.wheel_positions_l) == 'bfm')\n",
1564 "assert(enigma.peg_positions == ([15], [25], [9]))\n",
1565 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'gnkuoxarzycmlbetvhwpdqsfji')\n",
1567 "enigma.advance()\n",
1568 "assert(enigma.wheel_positions == (1, 5, 13))\n",
1569 "assert(cat(enigma.wheel_positions_l) == 'bfn')\n",
1570 "assert(enigma.peg_positions == ([15], [25], [8]))\n",
1571 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'bainslqkcxhfudpogtermwvjzy')\n",
1573 "enigma.advance()\n",
1574 "assert(enigma.wheel_positions == (1, 5, 14))\n",
1575 "assert(cat(enigma.wheel_positions_l) == 'bfo')\n",
1576 "assert(enigma.peg_positions == ([15], [25], [7]))\n",
1577 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'xemfbdnwjitycgzusvqkprhalo')\n",
1579 "enigma.advance()\n",
1580 "assert(enigma.wheel_positions == (1, 5, 15))\n",
1581 "assert(cat(enigma.wheel_positions_l) == 'bfp')\n",
1582 "assert(enigma.peg_positions == ([15], [25], [6]))\n",
1583 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qixksmhgbtdvfonrapejwluczy')\n",
1585 "enigma.advance()\n",
1586 "assert(enigma.wheel_positions == (1, 5, 16))\n",
1587 "assert(cat(enigma.wheel_positions_l) == 'bfq')\n",
1588 "assert(enigma.peg_positions == ([15], [25], [5]))\n",
1589 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cgaulmbskwiefrtzynhodxjvqp')\n",
1591 "enigma.advance()\n",
1592 "assert(enigma.wheel_positions == (1, 5, 17))\n",
1593 "assert(cat(enigma.wheel_positions_l) == 'bfr')\n",
1594 "assert(enigma.peg_positions == ([15], [25], [4]))\n",
1595 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'iwqfldszaxvenmyrcpgutkbjoh')\n",
1597 "enigma.advance()\n",
1598 "assert(enigma.wheel_positions == (1, 5, 18))\n",
1599 "assert(cat(enigma.wheel_positions_l) == 'bfs')\n",
1600 "assert(enigma.peg_positions == ([15], [25], [3]))\n",
1601 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'vxykrjilgfdhqtusmepnoazbcw')\n",
1603 "enigma.advance()\n",
1604 "assert(enigma.wheel_positions == (1, 5, 19))\n",
1605 "assert(cat(enigma.wheel_positions_l) == 'bft')\n",
1606 "assert(enigma.peg_positions == ([15], [25], [2]))\n",
1607 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ieysbvkjahgmlpxnwtdrzfqocu')\n",
1609 "enigma.advance()\n",
1610 "assert(enigma.wheel_positions == (1, 5, 20))\n",
1611 "assert(cat(enigma.wheel_positions_l) == 'bfu')\n",
1612 "assert(enigma.peg_positions == ([15], [25], [1]))\n",
1613 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'baihkjvdcfepywsltxoqzgnrmu')\n",
1615 "enigma.advance()\n",
1616 "assert(enigma.wheel_positions == (1, 5, 21))\n",
1617 "assert(cat(enigma.wheel_positions_l) == 'bfv')\n",
1618 "assert(enigma.peg_positions == ([15], [25], [0]))\n",
1619 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'bayjtrilgdshvzuwxfkeompqcn')\n",
1621 "enigma.advance()\n",
1622 "assert(enigma.wheel_positions == (1, 6, 22))\n",
1623 "assert(cat(enigma.wheel_positions_l) == 'bgw')\n",
1624 "assert(enigma.peg_positions == ([15], [24], [25]))\n",
1625 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'rszqohpfxyutvwegdablkmnijc')\n",
1627 "enigma.advance()\n",
1628 "assert(enigma.wheel_positions == (1, 6, 23))\n",
1629 "assert(cat(enigma.wheel_positions_l) == 'bgx')\n",
1630 "assert(enigma.peg_positions == ([15], [24], [24]))\n",
1631 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'nfoxhbzeyrwqpacmljtsvukdig')\n",
1633 "enigma.advance()\n",
1634 "assert(enigma.wheel_positions == (1, 6, 24))\n",
1635 "assert(cat(enigma.wheel_positions_l) == 'bgy')\n",
1636 "assert(enigma.peg_positions == ([15], [24], [23]))\n",
1637 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'czaogmeihtuqfsdxlwnjkyrpvb')\n",
1639 "enigma.advance()\n",
1640 "assert(enigma.wheel_positions == (1, 6, 25))\n",
1641 "assert(cat(enigma.wheel_positions_l) == 'bgz')\n",
1642 "assert(enigma.peg_positions == ([15], [24], [22]))\n",
1643 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'omwgysdjkhizbxarupfvqtcnel')\n",
1645 "enigma.advance()\n",
1646 "assert(enigma.wheel_positions == (1, 6, 0))\n",
1647 "assert(cat(enigma.wheel_positions_l) == 'bga')\n",
1648 "assert(enigma.peg_positions == ([15], [24], [21]))\n",
1649 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cxafmdrzoqutepinjgvlksybwh')\n",
1651 "enigma.advance()\n",
1652 "assert(enigma.wheel_positions == (1, 6, 1))\n",
1653 "assert(cat(enigma.wheel_positions_l) == 'bgb')\n",
1654 "assert(enigma.peg_positions == ([15], [24], [20]))\n",
1655 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'jymvnrxkoahwceiuzftspdlgbq')\n",
1657 "enigma.advance()\n",
1658 "assert(enigma.wheel_positions == (1, 6, 2))\n",
1659 "assert(cat(enigma.wheel_positions_l) == 'bgc')\n",
1660 "assert(enigma.peg_positions == ([15], [24], [19]))\n",
1661 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'uzlyiqwrestcnmxvfhjkapgodb')\n",
1663 "enigma.advance()\n",
1664 "assert(enigma.wheel_positions == (1, 6, 3))\n",
1665 "assert(cat(enigma.wheel_positions_l) == 'bgd')\n",
1666 "assert(enigma.peg_positions == ([15], [24], [18]))\n",
1667 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'veosbuhgpzqynmcikwdxfartlj')\n",
1669 "enigma.advance()\n",
1670 "assert(enigma.wheel_positions == (1, 6, 4))\n",
1671 "assert(cat(enigma.wheel_positions_l) == 'bge')\n",
1672 "assert(enigma.peg_positions == ([15], [24], [17]))\n",
1673 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ydhbmtrclxsiezpougkfqwvjan')\n",
1680 "for i in range(26):\n",
1681 " enigma.advance()\n",
1682 " print('enigma.advance()')\n",
1683 " print(\"assert(enigma.wheel_positions == {})\".format(enigma.wheel_positions))\n",
1684 " print(\"assert(cat(enigma.wheel_positions_l) == '{}')\".format(cat(enigma.wheel_positions_l)))\n",
1685 " print(\"assert(enigma.peg_positions == {})\".format(enigma.peg_positions))\n",
1686 " print(\"assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == '{}')\".format(cat(enigma.lookup(l) for l in string.ascii_lowercase)))\n",
1691 "cell_type": "code",
1692 "execution_count": 783,
1703 "execution_count": 783,
1705 "output_type": "execute_result"
1709 "enigma.set_wheels('a', 'd', 't')\n",
1710 "ct = enigma.encipher('hellothere')\n",
1711 "assert(ct == 'bahxvfrpdc')\n",
1716 "cell_type": "code",
1717 "execution_count": 784,
1725 "'kvmmwrlqlqsqpeugjrcxzwpfyiyybwloewrouvkpoztceuwtfjzqwpbqldttsr'"
1728 "execution_count": 784,
1730 "output_type": "execute_result"
1734 "enigma.set_wheels('b', 'd', 'q')\n",
1735 "ct = enigma.encipher('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')\n",
1736 "assert(ct == 'kvmmwrlqlqsqpeugjrcxzwpfyiyybwloewrouvkpoztceuwtfjzqwpbqldttsr')\n",
1737 "assert(enigma.left_wheel.position_l == 'c')\n",
1738 "assert(enigma.middle_wheel.position_l == 'h')\n",
1739 "assert(enigma.right_wheel.position_l == 'a')\n",
1744 "cell_type": "code",
1745 "execution_count": 785,
1756 "execution_count": 785,
1758 "output_type": "execute_result"
1762 "enigma.left_wheel.position_l"
1766 "cell_type": "code",
1767 "execution_count": 786,
1773 "# Setting sheet line 31 from http://www.codesandciphers.org.uk/enigma/enigma3.htm\n",
1774 "# Enigma simulation settings are \n",
1775 "# http://enigma.louisedade.co.uk/enigma.html?m3;b;b153;AFTX;AJFE;AU-BG-EY-FP-HL-IN-JZ-OS-QR-TX\n",
1776 "w_enigma = Enigma(reflector_b_spec, \n",
1777 " wheel_i_spec, wheel_i_pegs,\n",
1778 " wheel_v_spec, wheel_v_pegs,\n",
1779 " wheel_iii_spec, wheel_iii_pegs,\n",
1781 " 'ua pf rq so ni ey bg hl tx zj')"
1785 "cell_type": "code",
1786 "execution_count": 787,
1792 "# Setting sheet line 31 from http://www.codesandciphers.org.uk/enigma/enigma3.htm\n",
1793 "# Enigma simulation settings are \n",
1794 "# http://enigma.louisedade.co.uk/enigma.html?m3;b;b153;AFTX;AJFE;AU-BG-EY-FP-HL-IN-JZ-OS-QR-TX\n",
1795 "enigma = Enigma(reflector_b_spec, \n",
1796 " wheel_i_spec, wheel_i_pegs,\n",
1797 " wheel_v_spec, wheel_v_pegs,\n",
1798 " wheel_iii_spec, wheel_iii_pegs,\n",
1800 " 'ua pf rq so ni ey bg hl tx zj')"
1804 "cell_type": "code",
1805 "execution_count": 788,
1811 "enigma.set_wheels('j', 'e', 'u')\n",
1813 "enigma.advance()\n",
1814 "assert(enigma.wheel_positions == (4, 11, 24))\n",
1815 "assert(cat(enigma.wheel_positions_l) == 'jev')\n",
1816 "assert(enigma.peg_positions == ([7], [21], [0]))\n",
1817 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'mvqjlyowkdieasgzcunxrbhtfp')\n",
1819 "enigma.advance()\n",
1820 "assert(enigma.wheel_positions == (4, 12, 25))\n",
1821 "assert(cat(enigma.wheel_positions_l) == 'jfw')\n",
1822 "assert(enigma.peg_positions == ([7], [20], [25]))\n",
1823 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'sjolzuyvrbwdpxcmtiaqfhknge')\n",
1825 "enigma.advance()\n",
1826 "assert(enigma.wheel_positions == (4, 12, 0))\n",
1827 "assert(cat(enigma.wheel_positions_l) == 'jfx')\n",
1828 "assert(enigma.peg_positions == ([7], [20], [24]))\n",
1829 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qrxedkoywufmlvgsabpzjnicht')\n",
1831 "enigma.advance()\n",
1832 "assert(enigma.wheel_positions == (4, 12, 1))\n",
1833 "assert(cat(enigma.wheel_positions_l) == 'jfy')\n",
1834 "assert(enigma.peg_positions == ([7], [20], [23]))\n",
1835 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'hpsukliagqefwvtbjxcodnmrzy')\n",
1837 "enigma.advance()\n",
1838 "assert(enigma.wheel_positions == (4, 12, 2))\n",
1839 "assert(cat(enigma.wheel_positions_l) == 'jfz')\n",
1840 "assert(enigma.peg_positions == ([7], [20], [22]))\n",
1841 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'zevnbpyqowrtxdifhkulscjmga')\n"
1845 "cell_type": "code",
1846 "execution_count": 789,
1852 "enigma.set_wheels('i', 'd', 'z')\n",
1854 "enigma.advance()\n",
1855 "assert(enigma.wheel_positions == (3, 10, 3))\n",
1856 "assert(cat(enigma.wheel_positions_l) == 'ida')\n",
1857 "assert(enigma.peg_positions == ([8], [22], [21]))\n",
1858 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ikhpqrvcambzjondefwyxgsutl')\n",
1860 "enigma.advance()\n",
1861 "assert(enigma.wheel_positions == (3, 10, 4))\n",
1862 "assert(cat(enigma.wheel_positions_l) == 'idb')\n",
1863 "assert(enigma.peg_positions == ([8], [22], [20]))\n",
1864 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cdabskhgzwfmlqvunyexpojtri')\n",
1866 "enigma.advance()\n",
1867 "assert(enigma.wheel_positions == (3, 10, 5))\n",
1868 "assert(cat(enigma.wheel_positions_l) == 'idc')\n",
1869 "assert(enigma.peg_positions == ([8], [22], [19]))\n",
1870 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'pcbwiqhgemyvjsuaftnroldzkx')\n",
1872 "enigma.advance()\n",
1873 "assert(enigma.wheel_positions == (3, 10, 6))\n",
1874 "assert(cat(enigma.wheel_positions_l) == 'idd')\n",
1875 "assert(enigma.peg_positions == ([8], [22], [18]))\n",
1876 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'xcbfvdnouptmlghjzwykierasq')\n",
1878 "enigma.advance()\n",
1879 "assert(enigma.wheel_positions == (3, 10, 7))\n",
1880 "assert(cat(enigma.wheel_positions_l) == 'ide')\n",
1881 "assert(enigma.peg_positions == ([8], [22], [17]))\n",
1882 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'xfvglbdynuseriwqpmkzjcoaht')\n",
1884 "enigma.advance()\n",
1885 "assert(enigma.wheel_positions == (3, 10, 8))\n",
1886 "assert(cat(enigma.wheel_positions_l) == 'idf')\n",
1887 "assert(enigma.peg_positions == ([8], [22], [16]))\n",
1888 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'tfpqlbouynsewjgcdxkahzmriv')\n",
1890 "enigma.advance()\n",
1891 "assert(enigma.wheel_positions == (3, 10, 9))\n",
1892 "assert(cat(enigma.wheel_positions_l) == 'idg')\n",
1893 "assert(enigma.peg_positions == ([8], [22], [15]))\n",
1894 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cjaunvlwtbygzexrspqidfhokm')\n",
1896 "enigma.advance()\n",
1897 "assert(enigma.wheel_positions == (3, 10, 10))\n",
1898 "assert(cat(enigma.wheel_positions_l) == 'idh')\n",
1899 "assert(enigma.peg_positions == ([8], [22], [14]))\n",
1900 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'yltxkrqvowebzpingfucshjdam')\n",
1902 "enigma.advance()\n",
1903 "assert(enigma.wheel_positions == (3, 10, 11))\n",
1904 "assert(cat(enigma.wheel_positions_l) == 'idi')\n",
1905 "assert(enigma.peg_positions == ([8], [22], [13]))\n",
1906 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'myktluzrnxceaiqsohpdfwvjbg')\n",
1908 "enigma.advance()\n",
1909 "assert(enigma.wheel_positions == (3, 10, 12))\n",
1910 "assert(cat(enigma.wheel_positions_l) == 'idj')\n",
1911 "assert(enigma.peg_positions == ([8], [22], [12]))\n",
1912 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'pynjrmiugdqxfcvakewzhoslbt')\n",
1914 "enigma.advance()\n",
1915 "assert(enigma.wheel_positions == (3, 10, 13))\n",
1916 "assert(cat(enigma.wheel_positions_l) == 'idk')\n",
1917 "assert(enigma.peg_positions == ([8], [22], [11]))\n",
1918 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'mwvedyplnoxhaijgrqtszcbkfu')\n",
1920 "enigma.advance()\n",
1921 "assert(enigma.wheel_positions == (3, 10, 14))\n",
1922 "assert(cat(enigma.wheel_positions_l) == 'idl')\n",
1923 "assert(enigma.peg_positions == ([8], [22], [10]))\n",
1924 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qcbrfeutvoxpnmjladzhgiykws')\n",
1926 "enigma.advance()\n",
1927 "assert(enigma.wheel_positions == (3, 10, 15))\n",
1928 "assert(cat(enigma.wheel_positions_l) == 'idm')\n",
1929 "assert(enigma.peg_positions == ([8], [22], [9]))\n",
1930 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'dnoahryetsmukbcvwfjilpqzgx')\n",
1932 "enigma.advance()\n",
1933 "assert(enigma.wheel_positions == (3, 10, 16))\n",
1934 "assert(cat(enigma.wheel_positions_l) == 'idn')\n",
1935 "assert(enigma.peg_positions == ([8], [22], [8]))\n",
1936 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'nidcfehgbqsovalyjzkxwmutpr')\n",
1938 "enigma.advance()\n",
1939 "assert(enigma.wheel_positions == (3, 10, 17))\n",
1940 "assert(cat(enigma.wheel_positions_l) == 'ido')\n",
1941 "assert(enigma.peg_positions == ([8], [22], [7]))\n",
1942 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'joifxdulcarhzpbntkwqgysevm')\n",
1944 "enigma.advance()\n",
1945 "assert(enigma.wheel_positions == (3, 10, 18))\n",
1946 "assert(cat(enigma.wheel_positions_l) == 'idp')\n",
1947 "assert(enigma.peg_positions == ([8], [22], [6]))\n",
1948 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ptnlsxvozmwdjchayuebrgkfqi')\n",
1950 "enigma.advance()\n",
1951 "assert(enigma.wheel_positions == (3, 10, 19))\n",
1952 "assert(cat(enigma.wheel_positions_l) == 'idq')\n",
1953 "assert(enigma.peg_positions == ([8], [22], [5]))\n",
1954 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'slwopzqnmxybihdeguavrtcjkf')\n",
1956 "enigma.advance()\n",
1957 "assert(enigma.wheel_positions == (3, 10, 20))\n",
1958 "assert(cat(enigma.wheel_positions_l) == 'idr')\n",
1959 "assert(enigma.peg_positions == ([8], [22], [4]))\n",
1960 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'hcbedwlamzogixkytsrqvufnpj')\n",
1962 "enigma.advance()\n",
1963 "assert(enigma.wheel_positions == (3, 10, 21))\n",
1964 "assert(cat(enigma.wheel_positions_l) == 'ids')\n",
1965 "assert(enigma.peg_positions == ([8], [22], [3]))\n",
1966 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'odxbjwzrmelkisavuhnyqpfctg')\n",
1968 "enigma.advance()\n",
1969 "assert(enigma.wheel_positions == (3, 10, 22))\n",
1970 "assert(cat(enigma.wheel_positions_l) == 'idt')\n",
1971 "assert(enigma.peg_positions == ([8], [22], [2]))\n",
1972 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'udgbfeclrwnhxksvtioqapjmzy')\n",
1974 "enigma.advance()\n",
1975 "assert(enigma.wheel_positions == (3, 10, 23))\n",
1976 "assert(cat(enigma.wheel_positions_l) == 'idu')\n",
1977 "assert(enigma.peg_positions == ([8], [22], [1]))\n",
1978 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'nrdczqxmowvshaiufblypkjgte')\n",
1980 "enigma.advance()\n",
1981 "assert(enigma.wheel_positions == (3, 10, 24))\n",
1982 "assert(cat(enigma.wheel_positions_l) == 'idv')\n",
1983 "assert(enigma.peg_positions == ([8], [22], [0]))\n",
1984 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'hkifjdoacebqtzgulyvmpsxwrn')\n",
1986 "enigma.advance()\n",
1987 "assert(enigma.wheel_positions == (3, 11, 25))\n",
1988 "assert(cat(enigma.wheel_positions_l) == 'iew')\n",
1989 "assert(enigma.peg_positions == ([8], [21], [25]))\n",
1990 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'yptzuhofqvnmlkgbixwcejsrad')\n",
1992 "enigma.advance()\n",
1993 "assert(enigma.wheel_positions == (3, 11, 0))\n",
1994 "assert(cat(enigma.wheel_positions_l) == 'iex')\n",
1995 "assert(enigma.peg_positions == ([8], [21], [24]))\n",
1996 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'vkdcwhqfjibzsptngumoraeyxl')\n",
1998 "enigma.advance()\n",
1999 "assert(enigma.wheel_positions == (3, 11, 1))\n",
2000 "assert(cat(enigma.wheel_positions_l) == 'iey')\n",
2001 "assert(enigma.peg_positions == ([8], [21], [23]))\n",
2002 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'wenpbqrouxlkychdfgzvitajms')\n"
2006 "cell_type": "code",
2007 "execution_count": 790,
2015 "('verylongtestmessagewithanextrabitofmessageforgoodmeasure',\n",
2017 " ('i', 'f', 'd'),\n",
2018 " ([8], [20], [18]),\n",
2019 " 'urygzpdmxtwshqvfnbljaokice')"
2022 "execution_count": 790,
2024 "output_type": "execute_result"
2028 "enigma.set_wheels('i', 'd', 'z')\n",
2029 "ct = enigma.encipher('verylongtestmessagewithanextrabitofmessageforgoodmeasure')\n",
2030 "assert(ct == 'gstsegeqdrthkfwesljjomfvcqwcfspxpfqqmewvddybarzwubxtpejz')\n",
2031 "assert(enigma.wheel_positions == (3, 12, 6))\n",
2032 "assert(cat(enigma.wheel_positions_l) == 'ifd')\n",
2033 "assert(enigma.peg_positions == ([8], [20], [18]))\n",
2034 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'urygzpdmxtwshqvfnbljaokice')\n",
2036 "enigma.set_wheels('i', 'd', 'z')\n",
2037 "pt = enigma.encipher('gstsegeqdrthkfwesljjomfvcqwcfspxpfqqmewvddybarzwubxtpejz')\n",
2038 "assert(pt == 'verylongtestmessagewithanextrabitofmessageforgoodmeasure')\n",
2040 "pt, enigma.wheel_positions, enigma.wheel_positions_l, enigma.peg_positions, cat(enigma.lookup(l) for l in string.ascii_lowercase)"
2044 "cell_type": "code",
2045 "execution_count": 791,
2052 "output_type": "stream",
2054 "enigma.advance()\n",
2055 "assert(enigma.wheel_positions == (3, 10, 3))\n",
2056 "assert(cat(enigma.wheel_positions_l) == 'ida')\n",
2057 "assert(enigma.peg_positions == ([8], [22], [21]))\n",
2058 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ikhpqrvcambzjondefwyxgsutl')\n",
2060 "enigma.advance()\n",
2061 "assert(enigma.wheel_positions == (3, 10, 4))\n",
2062 "assert(cat(enigma.wheel_positions_l) == 'idb')\n",
2063 "assert(enigma.peg_positions == ([8], [22], [20]))\n",
2064 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cdabskhgzwfmlqvunyexpojtri')\n",
2066 "enigma.advance()\n",
2067 "assert(enigma.wheel_positions == (3, 10, 5))\n",
2068 "assert(cat(enigma.wheel_positions_l) == 'idc')\n",
2069 "assert(enigma.peg_positions == ([8], [22], [19]))\n",
2070 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'pcbwiqhgemyvjsuaftnroldzkx')\n",
2072 "enigma.advance()\n",
2073 "assert(enigma.wheel_positions == (3, 10, 6))\n",
2074 "assert(cat(enigma.wheel_positions_l) == 'idd')\n",
2075 "assert(enigma.peg_positions == ([8], [22], [18]))\n",
2076 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'xcbfvdnouptmlghjzwykierasq')\n",
2078 "enigma.advance()\n",
2079 "assert(enigma.wheel_positions == (3, 10, 7))\n",
2080 "assert(cat(enigma.wheel_positions_l) == 'ide')\n",
2081 "assert(enigma.peg_positions == ([8], [22], [17]))\n",
2082 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'xfvglbdynuseriwqpmkzjcoaht')\n",
2084 "enigma.advance()\n",
2085 "assert(enigma.wheel_positions == (3, 10, 8))\n",
2086 "assert(cat(enigma.wheel_positions_l) == 'idf')\n",
2087 "assert(enigma.peg_positions == ([8], [22], [16]))\n",
2088 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'tfpqlbouynsewjgcdxkahzmriv')\n",
2090 "enigma.advance()\n",
2091 "assert(enigma.wheel_positions == (3, 10, 9))\n",
2092 "assert(cat(enigma.wheel_positions_l) == 'idg')\n",
2093 "assert(enigma.peg_positions == ([8], [22], [15]))\n",
2094 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'cjaunvlwtbygzexrspqidfhokm')\n",
2096 "enigma.advance()\n",
2097 "assert(enigma.wheel_positions == (3, 10, 10))\n",
2098 "assert(cat(enigma.wheel_positions_l) == 'idh')\n",
2099 "assert(enigma.peg_positions == ([8], [22], [14]))\n",
2100 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'yltxkrqvowebzpingfucshjdam')\n",
2102 "enigma.advance()\n",
2103 "assert(enigma.wheel_positions == (3, 10, 11))\n",
2104 "assert(cat(enigma.wheel_positions_l) == 'idi')\n",
2105 "assert(enigma.peg_positions == ([8], [22], [13]))\n",
2106 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'myktluzrnxceaiqsohpdfwvjbg')\n",
2108 "enigma.advance()\n",
2109 "assert(enigma.wheel_positions == (3, 10, 12))\n",
2110 "assert(cat(enigma.wheel_positions_l) == 'idj')\n",
2111 "assert(enigma.peg_positions == ([8], [22], [12]))\n",
2112 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'pynjrmiugdqxfcvakewzhoslbt')\n",
2114 "enigma.advance()\n",
2115 "assert(enigma.wheel_positions == (3, 10, 13))\n",
2116 "assert(cat(enigma.wheel_positions_l) == 'idk')\n",
2117 "assert(enigma.peg_positions == ([8], [22], [11]))\n",
2118 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'mwvedyplnoxhaijgrqtszcbkfu')\n",
2120 "enigma.advance()\n",
2121 "assert(enigma.wheel_positions == (3, 10, 14))\n",
2122 "assert(cat(enigma.wheel_positions_l) == 'idl')\n",
2123 "assert(enigma.peg_positions == ([8], [22], [10]))\n",
2124 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'qcbrfeutvoxpnmjladzhgiykws')\n",
2126 "enigma.advance()\n",
2127 "assert(enigma.wheel_positions == (3, 10, 15))\n",
2128 "assert(cat(enigma.wheel_positions_l) == 'idm')\n",
2129 "assert(enigma.peg_positions == ([8], [22], [9]))\n",
2130 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'dnoahryetsmukbcvwfjilpqzgx')\n",
2132 "enigma.advance()\n",
2133 "assert(enigma.wheel_positions == (3, 10, 16))\n",
2134 "assert(cat(enigma.wheel_positions_l) == 'idn')\n",
2135 "assert(enigma.peg_positions == ([8], [22], [8]))\n",
2136 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'nidcfehgbqsovalyjzkxwmutpr')\n",
2138 "enigma.advance()\n",
2139 "assert(enigma.wheel_positions == (3, 10, 17))\n",
2140 "assert(cat(enigma.wheel_positions_l) == 'ido')\n",
2141 "assert(enigma.peg_positions == ([8], [22], [7]))\n",
2142 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'joifxdulcarhzpbntkwqgysevm')\n",
2144 "enigma.advance()\n",
2145 "assert(enigma.wheel_positions == (3, 10, 18))\n",
2146 "assert(cat(enigma.wheel_positions_l) == 'idp')\n",
2147 "assert(enigma.peg_positions == ([8], [22], [6]))\n",
2148 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'ptnlsxvozmwdjchayuebrgkfqi')\n",
2150 "enigma.advance()\n",
2151 "assert(enigma.wheel_positions == (3, 10, 19))\n",
2152 "assert(cat(enigma.wheel_positions_l) == 'idq')\n",
2153 "assert(enigma.peg_positions == ([8], [22], [5]))\n",
2154 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'slwopzqnmxybihdeguavrtcjkf')\n",
2156 "enigma.advance()\n",
2157 "assert(enigma.wheel_positions == (3, 10, 20))\n",
2158 "assert(cat(enigma.wheel_positions_l) == 'idr')\n",
2159 "assert(enigma.peg_positions == ([8], [22], [4]))\n",
2160 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'hcbedwlamzogixkytsrqvufnpj')\n",
2162 "enigma.advance()\n",
2163 "assert(enigma.wheel_positions == (3, 10, 21))\n",
2164 "assert(cat(enigma.wheel_positions_l) == 'ids')\n",
2165 "assert(enigma.peg_positions == ([8], [22], [3]))\n",
2166 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'odxbjwzrmelkisavuhnyqpfctg')\n",
2168 "enigma.advance()\n",
2169 "assert(enigma.wheel_positions == (3, 10, 22))\n",
2170 "assert(cat(enigma.wheel_positions_l) == 'idt')\n",
2171 "assert(enigma.peg_positions == ([8], [22], [2]))\n",
2172 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'udgbfeclrwnhxksvtioqapjmzy')\n",
2174 "enigma.advance()\n",
2175 "assert(enigma.wheel_positions == (3, 10, 23))\n",
2176 "assert(cat(enigma.wheel_positions_l) == 'idu')\n",
2177 "assert(enigma.peg_positions == ([8], [22], [1]))\n",
2178 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'nrdczqxmowvshaiufblypkjgte')\n",
2180 "enigma.advance()\n",
2181 "assert(enigma.wheel_positions == (3, 10, 24))\n",
2182 "assert(cat(enigma.wheel_positions_l) == 'idv')\n",
2183 "assert(enigma.peg_positions == ([8], [22], [0]))\n",
2184 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'hkifjdoacebqtzgulyvmpsxwrn')\n",
2186 "enigma.advance()\n",
2187 "assert(enigma.wheel_positions == (3, 11, 25))\n",
2188 "assert(cat(enigma.wheel_positions_l) == 'iew')\n",
2189 "assert(enigma.peg_positions == ([8], [21], [25]))\n",
2190 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'yptzuhofqvnmlkgbixwcejsrad')\n",
2192 "enigma.advance()\n",
2193 "assert(enigma.wheel_positions == (3, 11, 0))\n",
2194 "assert(cat(enigma.wheel_positions_l) == 'iex')\n",
2195 "assert(enigma.peg_positions == ([8], [21], [24]))\n",
2196 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'vkdcwhqfjibzsptngumoraeyxl')\n",
2198 "enigma.advance()\n",
2199 "assert(enigma.wheel_positions == (3, 11, 1))\n",
2200 "assert(cat(enigma.wheel_positions_l) == 'iey')\n",
2201 "assert(enigma.peg_positions == ([8], [21], [23]))\n",
2202 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'wenpbqrouxlkychdfgzvitajms')\n",
2204 "enigma.advance()\n",
2205 "assert(enigma.wheel_positions == (3, 11, 2))\n",
2206 "assert(cat(enigma.wheel_positions_l) == 'iez')\n",
2207 "assert(enigma.peg_positions == ([8], [21], [22]))\n",
2208 "assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == 'szgyqvclkoihurjwenaxmfptdb')\n",
2214 "enigma.set_wheels('i', 'd', 'z')\n",
2216 "for i in range(26):\n",
2217 " enigma.advance()\n",
2218 " print('enigma.advance()')\n",
2219 " print(\"assert(enigma.wheel_positions == {})\".format(enigma.wheel_positions))\n",
2220 " print(\"assert(cat(enigma.wheel_positions_l) == '{}')\".format(cat(enigma.wheel_positions_l)))\n",
2221 " print(\"assert(enigma.peg_positions == {})\".format(enigma.peg_positions))\n",
2222 " print(\"assert(cat(enigma.lookup(l) for l in string.ascii_lowercase) == '{}')\".format(cat(enigma.lookup(l) for l in string.ascii_lowercase)))\n",
2227 "cell_type": "code",
2228 "execution_count": null,
2238 "display_name": "Python 3",
2239 "language": "python",
2243 "codemirror_mode": {
2247 "file_extension": ".py",
2248 "mimetype": "text/x-python",
2250 "nbconvert_exporter": "python",
2251 "pygments_lexer": "ipython3",