# HG changeset patch # User Brian Neal # Date 1370205841 18000 # Node ID c399a23e8f2079d4fea5e4022ad82a326cd6abb5 # Parent c1db39916ec9a5f86a5fab204ca15869aba610ef Added a M209.set_key_wheels() method. diff -r c1db39916ec9 -r c399a23e8f20 m209/converter.py --- 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))