pub struct EnigmaMachine { /* private fields */ }
Implementations§
Source§impl EnigmaMachine
impl EnigmaMachine
Sourcepub fn new() -> impl EnigmaBuilder
pub fn new() -> impl EnigmaBuilder
Creates a new Enigma machine with blank settings. The settings for the machine must be added using the methods
of EnigmaBuilder
; See the README for an example.
The returned value from this will always be Ok
, and will be an Enigma machine with rotors 1, 1, 1, ring positions
1, 1, and 1, ring settings 1, 1, and 1, reflector A, and an empty plugboard.
Sourcepub fn decode(&self, text: &str) -> String
pub fn decode(&self, text: &str) -> String
Decodes the given text using this Enigma machine.
This is exactly the same as calling machine.encode(text)
, since the enigma cipher is
symmetric; The only difference is semantic meaning and intent, i.e.,
assert_eq!(text, machine.decode(machine.decode(text)));
assert_eq!(text, machine.encode(machine.encode(text)));
assert_eq!(text, machine.decode(machine.encode(text)));
assert_eq!(text, machine.encode(machine.decode(text)));
§Parameters
text
- The text to decode.
§Returns
The decoded text.
Sourcepub fn encode(&self, text: &str) -> String
pub fn encode(&self, text: &str) -> String
Encodes the given text using this Enigma machine.
This is exactly the same as calling machine.decode(text)
, since the enigma cipher is
symmetric; The only difference is semantic meaning and intent, i.e.,
assert_eq!(text, machine.decode(machine.decode(text)));
assert_eq!(text, machine.encode(machine.encode(text)));
assert_eq!(text, machine.decode(machine.encode(text)));
assert_eq!(text, machine.encode(machine.decode(text)));
§Parameters
text
- The text to encode.
§Returns
The encoded text.