1. Brian Neal
  2. enigma

Commits

Brian Neal  committed 1dac708 Draft

Added a get_rotor_count() method to EnigmaMachine.
Added a verbose option to pyenigma.py that calls it.

  • Participants
  • Parent commits c0ee738
  • Branches default

Comments (0)

Files changed (3)

File enigma/docs/source/reference.rst

View file
          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

File enigma/machine.py

View file
             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]

File enigma/main.py

View file
             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()
 
     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)