Wheatstone

Struct Wheatstone 

Source
pub struct Wheatstone { /* private fields */ }
Expand description

Wheatstone cipher machine implementation.

This struct represents a Wheatstone cipher with two keyed alphabets:

  • A plaintext wheel (27 characters, including ‘+’ as a separator)
  • A ciphertext wheel (26 characters, standard alphabet)

The cipher maintains internal state to track the current positions of both wheels during encryption and decryption operations.

Implementations§

Source§

impl Wheatstone

Source

pub fn new(start: u8, pkey: &str, ckey: &str) -> Result<Self>

Creates a new Wheatstone cipher with the provided configuration.

§Arguments
  • start - The starting character on the ciphertext wheel (typically ‘A’-‘Z’)
  • pkey - The plaintext key used to shuffle the plaintext alphabet
  • ckey - The ciphertext key used to shuffle the ciphertext alphabet
§Returns

Returns Ok(Wheatstone) if the cipher is successfully created, or Err(String) if either key is empty.

§Example
use old_crypto_rs::Wheatstone;

let cipher = Wheatstone::new(b'M', "CIPHER", "MACHINE").unwrap();

Trait Implementations§

Source§

impl Block for Wheatstone

Source§

fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize

Encrypts plaintext using the Wheatstone cipher.

This method encrypts the entire source buffer character by character, writing the ciphertext to the destination buffer. The cipher state is automatically reset before encryption to ensure consistent results.

§Arguments
  • dst - Mutable slice where the ciphertext will be written (must be at least as long as src)
  • src - Slice containing the plaintext to encrypt
§Returns

The number of bytes encrypted (equal to src.len())

§Example
use old_crypto_rs::{Block, Wheatstone};

let cipher = Wheatstone::new(b'M', "CIPHER", "MACHINE").unwrap();
let plaintext = b"HELLO";
let mut ciphertext = vec![0u8; plaintext.len()];
let len = cipher.encrypt(&mut ciphertext, plaintext);
assert_eq!(len, plaintext.len());
Source§

fn decrypt(&self, dst: &mut [u8], src: &[u8]) -> usize

Decrypts ciphertext using the Wheatstone cipher.

This method decrypts the entire source buffer character by character, writing the plaintext to the destination buffer. The cipher state is automatically reset before decryption to ensure consistent results.

§Arguments
  • dst - Mutable slice where the plaintext will be written (must be at least as long as src)
  • src - Slice containing the ciphertext to decrypt
§Returns

The number of bytes decrypted (equal to src.len())

§Example
use old_crypto_rs::{Block, Wheatstone};

let cipher = Wheatstone::new(b'M', "CIPHER", "MACHINE").unwrap();
let ciphertext = b"BYVLQ";
let mut plaintext = vec![0u8; ciphertext.len()];
let len = cipher.decrypt(&mut plaintext, ciphertext);
assert_eq!(len, ciphertext.len());
Source§

fn block_size(&self) -> usize

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.