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>

source

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>

source

pub fn set_rotors( self, rotors: Wheel ) -> Enigma<Wheel, AnyPlugboard, AnyReflector>

Set the Enigma rotors

source

pub fn set_plugboard( self, plugboard: Plugboard ) -> Enigma<AnyRotor, Plugboard, AnyReflector>

Set the Enigma plguboard

source

pub fn set_reflector( self, reflector: Reflector ) -> Enigma<AnyRotor, AnyPlugboard, Reflector>

Set the Enigma reflector

source§

impl<AnyPlugboard, AnyReflector> Enigma<Wheel, AnyPlugboard, AnyReflector>

source

pub fn set_grundstellung( &mut self, positions: [Letter; 3] ) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>

Set the starting position for the rotors

source

pub fn set_ringstellung( &mut self, positions: [u8; 3] ) -> &mut Enigma<Wheel, AnyPlugboard, AnyReflector>

Set the ring settings for the rotors

source

pub fn get_grundstellung(&self) -> [Letter; 3]

Get Rotor positions

source§

impl Enigma<Wheel, Plugboard, Reflector>

source

pub fn encrypt_letter(&mut self, letter: Letter) -> Letter

Encrypt/decrypt a Letter and advance the state

source

pub fn encrypt_char(&mut self, letter: char) -> char

Encrypt/decrypt a char and advance the state

Trait Implementations§

source§

impl<R: Clone, P: Clone, O: Clone> Clone for Enigma<R, P, O>

source§

fn clone(&self) -> Enigma<R, P, O>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Debug, P: Debug, O: Debug> Debug for Enigma<R, P, O>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Enigma<Unset, Unset, Unset>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<R: Hash, P: Hash, O: Hash> Hash for Enigma<R, P, O>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<R: Ord, P: Ord, O: Ord> Ord for Enigma<R, P, O>

source§

fn cmp(&self, other: &Enigma<R, P, O>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<R: PartialEq, P: PartialEq, O: PartialEq> PartialEq for Enigma<R, P, O>

source§

fn eq(&self, other: &Enigma<R, P, O>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: PartialOrd, P: PartialOrd, O: PartialOrd> PartialOrd for Enigma<R, P, O>

source§

fn partial_cmp(&self, other: &Enigma<R, P, O>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<R: Copy, P: Copy, O: Copy> Copy for Enigma<R, P, O>

source§

impl<R: Eq, P: Eq, O: Eq> Eq for Enigma<R, P, O>

source§

impl<R, P, O> StructuralPartialEq for Enigma<R, P, O>

Auto Trait Implementations§

§

impl<R, P, O> Freeze for Enigma<R, P, O>
where R: Freeze, P: Freeze, O: Freeze,

§

impl<R, P, O> RefUnwindSafe for Enigma<R, P, O>

§

impl<R, P, O> Send for Enigma<R, P, O>
where R: Send, P: Send, O: Send,

§

impl<R, P, O> Sync for Enigma<R, P, O>
where R: Sync, P: Sync, O: Sync,

§

impl<R, P, O> Unpin for Enigma<R, P, O>
where R: Unpin, P: Unpin, O: Unpin,

§

impl<R, P, O> UnwindSafe for Enigma<R, P, O>
where R: UnwindSafe, P: UnwindSafe, O: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.