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]
rotors: &str,
keys: &str,
rings: &str,
reflector: char,
plugboard: &str
) -> Enigma
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
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,