Struct ultra::Enigma[][src]

pub struct Enigma { /* fields omitted */ }

Represents an Enigma machine with rotor, key, and ring settings.

Implementations

impl Enigma[src]

pub fn new(
    rotors: &str,
    keys: &str,
    rings: &str,
    reflector: char,
    plugboard: &str
) -> Enigma
[src]

Creates a new Enigma, where rotors is a string of three digits ranging from 1-8 (corresponding to rotors I through VIII of the real Enigma machine), keys and rings are three character strings containing the key and ring settings, reflector is one of 'A', 'B', or 'C', and plugboard is a string of whitespace-delimited pairs of characters.

Examples

Enigma with rotors I, II, and III, key setting ABC, ring setting DEF, reflector B, and a plugboard connection between ‘P’ and ‘Y’.

use ultra::Enigma;

let mut enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");

pub fn random() -> Enigma[src]

Creates a new random Enigma with random settings based on thread-local RNG.

Examples

use ultra::Enigma;

let mut enigma_1 = Enigma::random();
let mut enigma_2 = Enigma::random();
assert!(enigma_1.encrypt("ENIGMA") != enigma_2.encrypt("ENIGMA"));

pub fn random_from_u64_seed(seed: u64) -> Enigma[src]

Creates a new random Enigma from a given u64 seed.

Examples

use ultra::Enigma;

let mut enigma_1 = Enigma::random_from_u64_seed(42);
let mut enigma_2 = Enigma::random_from_u64_seed(42);
assert_eq!(enigma_1.encrypt("ENIGMA"), enigma_2.encrypt("ENIGMA"));

pub fn encrypt(&mut self, msg: &str) -> String[src]

Encrypts an entire message, advancing the rotors of the machine after each alphabetic character is encrypted.

Examples

use ultra::Enigma;

let mut enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");
assert_eq!(enigma.encrypt("ENIGMA"), "HKAJWW");

pub fn reset(&mut self)[src]

Resets the Enigma to its initial state.

Examples

use ultra::Enigma;

let msg = "THIS IS A TEST";

let mut enigma = Enigma::random();
let ciphertext_1 = enigma.encrypt(msg);
let ciphertext_2 = enigma.encrypt(msg);

enigma.reset();

assert_eq!(ciphertext_1, enigma.encrypt(msg));
assert!(ciphertext_1 != ciphertext_2);

pub fn rotor_list(&self) -> String[src]

Returns a string representing the Enigma’s rotor list.

Examples

use ultra::Enigma;

let enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");
assert_eq!(enigma.rotor_list(), "123");

pub fn key_settings(&self) -> String[src]

Returns a string representing the Enigma’s key settings.

Examples

use ultra::Enigma;

let enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");
assert_eq!(enigma.key_settings(), "ABC");

pub fn ring_settings(&self) -> String[src]

Returns a string representing the Enigma’s ring settings.

Examples

use ultra::Enigma;

let enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");
assert_eq!(enigma.ring_settings(), "DEF");

pub fn plugboard(&self) -> String[src]

Returns a string representing the Enigma’s plugboard.

Examples

use ultra::Enigma;

let enigma = Enigma::new("123", "ABC", "DEF", 'B', "PY");
assert_eq!(enigma.plugboard(), "PY");

Trait Implementations

impl Clone for Enigma[src]

impl Debug for Enigma[src]

impl Display for Enigma[src]

Auto Trait Implementations

impl RefUnwindSafe for Enigma

impl Send for Enigma

impl Sync for Enigma

impl Unpin for Enigma

impl UnwindSafe for Enigma

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,