Struct mini_enigma::state_machine::Enigma
source · pub struct Enigma<R, P, O> { /* private fields */ }
Expand description
Enigma Finite State Machine
An incomplete instance (e.g. from Enigma::default
) can be initialised later
semi-dynamically with the compiler checking correct initialisation before use.
§Examples
let enigma = Enigma::default()
.set_rotors(Wheel::new([ROTOR_I, ROTOR_II, ROTOR_III]))
.set_plugboard(Plugboard::new(&[]));
let mut enigma = enigma.set_reflector(REFLECTOR_A);
enigma.encrypt_letter(Letter::A);
The compiler can detect if one of the required initialisation steps is missing:
ⓘ
let mut enigma = Enigma::default()
.set_rotors(Wheel::new([ROTOR_I, ROTOR_II, ROTOR_III]))
.set_plugboard(Plugboard::new(&[]));
enigma.encrypt_letter(Letter::A); // encrypt can't be called until a reflector is set
Implementations§
source§impl Enigma<Unset, Unset, Unset>
impl Enigma<Unset, Unset, Unset>
sourcepub fn new(config: &EnigmaSettings) -> Enigma<Wheel, Plugboard, Reflector>
pub fn new(config: &EnigmaSettings) -> Enigma<Wheel, Plugboard, Reflector>
Create a fully setup Enigma FSM from the provided settings
§Examples
let mut enigma = Enigma::new(&EnigmaSettings {
rotors: [ROTOR_II, ROTOR_IV, ROTOR_V],
plugboard: Plugboard::from_str(
"AV,BS,CG,DL,FU,HZ,IN,KM,OW,RX",
).unwrap(),
reflector: REFLECTOR_B,
ringstellung: [2, 21, 12],
grundstellung: [Letter::B, Letter::L, Letter::A],
});
enigma.encrypt_letter(Letter::A);
source§impl<AnyRotor, AnyPlugboard, AnyReflector> Enigma<AnyRotor, AnyPlugboard, AnyReflector>
impl<AnyRotor, AnyPlugboard, AnyReflector> Enigma<AnyRotor, AnyPlugboard, AnyReflector>
sourcepub fn set_rotors(
self,
rotors: Wheel
) -> Enigma<Wheel, AnyPlugboard, AnyReflector>
pub fn set_rotors( self, rotors: Wheel ) -> Enigma<Wheel, AnyPlugboard, AnyReflector>
Set the Enigma rotors
sourcepub fn set_plugboard(
self,
plugboard: Plugboard
) -> Enigma<AnyRotor, Plugboard, AnyReflector>
pub fn set_plugboard( self, plugboard: Plugboard ) -> Enigma<AnyRotor, Plugboard, AnyReflector>
Set the Enigma plguboard
sourcepub fn set_reflector(
self,
reflector: Reflector
) -> Enigma<AnyRotor, AnyPlugboard, Reflector>
pub fn set_reflector( self, reflector: Reflector ) -> Enigma<AnyRotor, AnyPlugboard, Reflector>
Set the Enigma reflector
source§impl<AnyPlugboard, AnyReflector> Enigma<Wheel, AnyPlugboard, AnyReflector>
impl<AnyPlugboard, AnyReflector> Enigma<Wheel, AnyPlugboard, AnyReflector>
sourcepub fn set_grundstellung(
&mut self,
positions: [Letter; 3]
) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>
pub fn set_grundstellung( &mut self, positions: [Letter; 3] ) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>
Set the starting position for the rotors
sourcepub fn set_ringstellung(
&mut self,
positions: [u8; 3]
) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>
pub fn set_ringstellung( &mut self, positions: [u8; 3] ) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>
Set the ring settings for the rotors
sourcepub fn get_grundstellung(&self) -> [Letter; 3]
pub fn get_grundstellung(&self) -> [Letter; 3]
Get Rotor
positions
Trait Implementations§
source§impl<R: Ord, P: Ord, O: Ord> Ord for Enigma<R, P, O>
impl<R: Ord, P: Ord, O: Ord> Ord for Enigma<R, P, O>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<R: PartialEq, P: PartialEq, O: PartialEq> PartialEq for Enigma<R, P, O>
impl<R: PartialEq, P: PartialEq, O: PartialEq> PartialEq for Enigma<R, P, O>
source§impl<R: PartialOrd, P: PartialOrd, O: PartialOrd> PartialOrd for Enigma<R, P, O>
impl<R: PartialOrd, P: PartialOrd, O: PartialOrd> PartialOrd for Enigma<R, P, O>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<R: Copy, P: Copy, O: Copy> Copy for Enigma<R, P, O>
impl<R: Eq, P: Eq, O: Eq> Eq for Enigma<R, P, O>
impl<R, P, O> StructuralPartialEq for Enigma<R, P, O>
Auto Trait Implementations§
impl<R, P, O> Freeze for Enigma<R, P, O>
impl<R, P, O> RefUnwindSafe for Enigma<R, P, O>
impl<R, P, O> Send for Enigma<R, P, O>
impl<R, P, O> Sync for Enigma<R, P, O>
impl<R, P, O> Unpin for Enigma<R, P, O>
impl<R, P, O> UnwindSafe for Enigma<R, P, O>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more