Mercurial > public > enigma
changeset 38:1dac708e7b71
Added a get_rotor_count() method to EnigmaMachine.
Added a verbose option to pyenigma.py that calls it.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 04 Jun 2012 19:22:55 -0500 |
parents | c0ee73872f4e |
children | e328fcb6659b |
files | enigma/docs/source/reference.rst enigma/machine.py enigma/main.py |
diffstat | 3 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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]
--- 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)