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
impl Wheatstone
Sourcepub fn new(start: u8, pkey: &str, ckey: &str) -> Result<Self>
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 alphabetckey- 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
impl Block for Wheatstone
Source§fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
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 assrc)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
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 assrc)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());