changeset 6:c399a23e8f20

Added a M209.set_key_wheels() method.
author Brian Neal <bgneal@gmail.com>
date Sun, 02 Jun 2013 15:44:01 -0500
parents c1db39916ec9
children 65f72a842650
files m209/converter.py
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/m209/converter.py	Sun Jun 02 15:31:11 2013 -0500
+++ b/m209/converter.py	Sun Jun 02 15:44:01 2013 -0500
@@ -90,6 +90,15 @@
             drum = Drum(lug_list)
         self.drum = drum
 
+    def set_key_wheels(self, s):
+        """Set the key wheels from left to right to the six letter string s."""
+
+        if len(s) != 6:
+            raise M209Error("Invalid key wheels setting length")
+
+        for n in range(6):
+            self.key_wheels[n].set_pos(s[n])
+
     def encrypt(self, plaintext, group=True, spaces=True):
         """Performs an encrypt operation on the given plaintext and returns
         the ciphertext as a string.
@@ -181,13 +190,6 @@
     print(m209.encrypt(pt))
 
     ct = 'OZGPK AFVAJ JYRZW LRJEG MOVLU M'
-    m209 = M209()
-    m209.set_drum_lugs('1-0 2-0*4 0-3 0-4*3 0-5*3 0-6*11 2-5 2-6 3-4 4-5')
-    m209.set_pins(0, 'BFJKLOSTUWXZ')
-    m209.set_pins(1, 'ABDJKLMORTUV')
-    m209.set_pins(2, 'EHJKNPQRSX')
-    m209.set_pins(3, 'ABCHIJLMPQR')
-    m209.set_pins(4, 'BCDGJLNOPQS')
-    m209.set_pins(5, 'AEFHIJP')
+    m209.set_key_wheels('AAAAAA')
     print(m209.decrypt(ct))