enigma.machine¶
-
class
enigma.machine.
Machine
(rotors: List[enigma.rotor.Rotor], reflector: enigma.rotor.Rotor, entry_wheel: enigma.rotor.Rotor = None, last_turning_rotor: int = 3)¶ Creates a new Enigma machine
- Parameters
rotors – A list of Rotor objects
reflector – A rotor to be used as a reflector. Optional, if not specified the machine will simply do a right-to-left encoding and then left-to-right directly.
entry_wheel – A rotor to be used as an entry wheel. The military Enigma machine used the standard alphabet (rotor ETW), which equals as not using any entry wheel. But some machines (like the Tirpitz) had a custom one.
last_turning_rotor – Determine which is the last rotor that’s allowed to turn. It defaults to 3 as in most Enigma machines only the first three rotors could rotate.
-
encode
(string: str)¶ Encode a string using the Enigma machine
- Parameters
string – String to be encoded. Unknown characters will be preserved in the output. This is case-sensitive and standard rotors use uppercase letters only.
-
set_plugboard_mapping
(mapping: str)¶ Add a PlugBoard lead
- Parameters
mapping – Must be two characters in one string
-
set_plugboard_mappings
(mappings: str)¶ Add several PlugBoard leads
- Parameters
mapping – Must be a string consisting of character pairs separated by spaces. i.e. “AB CD EF”
-
set_rotor_positions
(*positions: str)¶ Set initial positions for each rotor
- Parameters
positions – Pass each position as an argument. They will be applied to the rotors in the order supplied (left to right) Positions must be passed as characters. Parameters outside the alphabet range will be capped.
-
set_rotor_settings
(*settings: int)¶ Set initial settings for each rotor
- Parameters
settings – Pass each setting as an argument. They will be applied to the rotors in the order supplied (left to right) Settings must be passed as integers. Parameters outside the alphabet range will be capped.