Struct UncheckedEnigmaMachine

Source
pub struct UncheckedEnigmaMachine { /* private fields */ }

Implementations§

Source§

impl UncheckedEnigmaMachine

Source

pub unsafe fn decrypt_unchecked(&self, text: &str) -> String

Decrypts the given ciphertext while skipping all safety checks for maxmimum speed.

This is exactly the same as calling machine.encrypt_unchecked(text), since the enigma cipher is symmetric; The only difference is semantic meaning and intent, i.e.,

assert_eq!(text, machine.decrypt_unchecked(machine.decrypt_unchecked(text)));
assert_eq!(text, machine.encrypt_unchecked(machine.encrypt_unchecked(text)));
assert_eq!(text, machine.decrypt_unchecked(machine.encrypt_unchecked(text)));
assert_eq!(text, machine.encrypt_unchecked(machine.decrypt_unchecked(text)));
§Parameters
  • text - The ciphertext to decrypt
§Returns

The decrypted plaintext.

§Safety

This function may panic if the Enigma machine was constructed with invalid settings. If the machine was constructed correctly, this is guarnateed to not panic, and will function identically to EnigmaMachine::decrypt(), with marginally better performance. See the Performance section of the README for more information.

Source

pub unsafe fn encrypt_unchecked(&self, text: &str) -> String

Encrypts the given plaintext while skipping all safety checks for maxmimum speed.

This is exactly the same as calling machine.decrypt_unchecked(text), since the enigma cipher is symmetric; The only difference is semantic meaning and intent, i.e.,

assert_eq!(text, machine.decrypt_unchecked(machine.decrypt_unchecked(text)));
assert_eq!(text, machine.encrypt_unchecked(machine.encrypt_unchecked(text)));
assert_eq!(text, machine.decrypt_unchecked(machine.encrypt_unchecked(text)));
assert_eq!(text, machine.encrypt_unchecked(machine.decrypt_unchecked(text)));
§Parameters
  • text - The ciphertext to decrypt
§Returns

The decrypted plaintext.

§Safety

This function may panic if the Enigma machine was constructed with invalid settings. If the machine was constructed correctly, this is guarnateed to not panic, and will function identically to EnigmaMachine::decrypt(), with marginally better performance. See the Performance section of the README for more information.

Trait Implementations§

Source§

impl UncheckedEnigmaBuilder for UncheckedEnigmaMachine

Source§

fn rotors(self, first: u8, second: u8, third: u8) -> impl UncheckedEnigmaBuilder

Sets the rotors for the machine. Read more
Source§

fn ring_positions( self, first: u8, second: u8, third: u8, ) -> impl UncheckedEnigmaBuilder

Sets the “ring positions” or “rotor positions” of the machine, unchecked. Read more
Source§

fn ring_settings( self, first: u8, second: u8, third: u8, ) -> impl UncheckedEnigmaBuilder

Sets the ring settings of the machine, unchecked. Read more
Source§

fn plugboard(self, plugboard: &str) -> impl UncheckedEnigmaBuilder

Sets the plugboard for the machine. The given plugboard should be a space-separated string of letter pairs. This is automatically bidirectional, meaning the pair AY will map A to Y and also Y to A. Read more
Source§

fn reflector(self, reflector: &str) -> impl UncheckedEnigmaBuilder

Sets the reflector of the machine. Read more
Source§

fn build(self) -> UncheckedEnigmaMachine

Finalizes building the Enigma machine. This is an absolutely zero-cost method that simply converts the impl UncheckedEnigmaBuilder opaque type into the concrete EnigmaMachine by just returning self.

Auto Trait Implementations§

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>,

Source§

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>,

Source§

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.