# HG changeset patch # User Brian Neal # Date 1338855775 18000 # Node ID 1dac708e7b716846f0bd18f52fea4b8fa982dce5 # Parent c0ee73872f4e122832ee4f5f1011273df1cefbee Added a get_rotor_count() method to EnigmaMachine. Added a verbose option to pyenigma.py that calls it. diff -r c0ee73872f4e -r 1dac708e7b71 enigma/docs/source/reference.rst --- a/enigma/docs/source/reference.rst Mon Jun 04 18:51:51 2012 -0500 +++ b/enigma/docs/source/reference.rst Mon Jun 04 19:22:55 2012 -0500 @@ -100,6 +100,12 @@ right) :rtype: string + .. method:: get_rotor_count() + + Returns a list of integers that represent the rotation counts for each + rotor. The rotation counts are reset to 0 every time :meth:`set_display` + is called. + .. method:: key_press(key) Simulate a front panel key press. First the rotors are stepped by diff -r c0ee73872f4e -r 1dac708e7b71 enigma/machine.py --- a/enigma/machine.py Mon Jun 04 18:51:51 2012 -0500 +++ b/enigma/machine.py Mon Jun 04 19:22:55 2012 -0500 @@ -249,3 +249,7 @@ result.append(self.key_press(c)) return ''.join(result) + + def get_rotor_counts(self): + """Return the rotor rotation counts as a list of integers.""" + return [r.rotations for r in self.rotors] diff -r c0ee73872f4e -r 1dac708e7b71 enigma/main.py --- a/enigma/main.py Mon Jun 04 18:51:51 2012 -0500 +++ b/enigma/main.py Mon Jun 04 19:22:55 2012 -0500 @@ -89,6 +89,8 @@ action='store_true', help=('if the input text contains chars not found on the enigma' ' keyboard, delete them from the input')) + parser.add_argument('-v', '--verbose', action='store_true', default=False, + help='provide verbose output; include final rotor positions') args = parser.parse_args() @@ -118,6 +120,12 @@ machine.set_display(args.start) s = machine.process_text(text, replace_char=replace_char) + + if args.verbose: + print('Final rotor positions:', machine.get_display()) + print('Rotor rotation counts:', machine.get_rotor_counts()) + print('Output:') + print(s)