StraddlingCheckerboard

Struct StraddlingCheckerboard 

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

A straddling checkerboard cipher implementation.

This cipher maps plaintext characters to variable-length digit sequences. High-frequency letters are encoded as single digits, while low-frequency letters are encoded as two digits prefixed by one of the “long” cipher digits.

§Examples

use old_crypto_rs::StraddlingCheckerboard;
use old_crypto_rs::Block;

let cipher = StraddlingCheckerboard::new("ARABESQUE", "89").unwrap();
let mut encrypted = vec![0u8; 100];
let len = cipher.encrypt(&mut encrypted, b"ATTACK");
encrypted.truncate(len);

Implementations§

Source§

impl StraddlingCheckerboard

Source

pub fn new(key: &str, chrs: &str) -> Result<Self>

Creates a new straddling checkerboard cipher with default frequency.

Uses “ESANTIRU” as the default high-frequency letters and the standard alphabet (A-Z plus ‘/’ and ‘-’).

§Arguments
  • key - The keyword used to shuffle the alphabet (must not be empty)
  • chrs - A string of at least 2 digits that will be used as “long” cipher digits
§Returns

Returns Ok(StraddlingCheckerboard) on success, or Err(String) if validation fails.

§Errors

Returns an error if:

  • key is empty
  • chrs contains fewer than 2 characters
§Examples
use old_crypto_rs::StraddlingCheckerboard;

let cipher = StraddlingCheckerboard::new("ARABESQUE", "89").unwrap();
Source

pub fn new_with_freq( key: &str, chrs: &str, freq_str: &str, alphabet: &str, ) -> Result<Self>

Creates a new straddling checkerboard cipher with custom frequency and alphabet.

Allows full customization of which letters get single-digit codes and what alphabet to use.

§Arguments
  • key - The keyword used to shuffle the alphabet (must not be empty)
  • chrs - A string of at least 2 digits for “long” cipher digit prefixes
  • freq_str - Letters that should receive single-digit encodings
  • alphabet - The alphabet to use for the checkerboard
§Returns

Returns Ok(StraddlingCheckerboard) on success, or Err(String) if validation fails.

§Errors

Returns an error if:

  • key is empty
  • chrs contains fewer than 2 characters

Trait Implementations§

Source§

impl Block for StraddlingCheckerboard

Source§

fn block_size(&self) -> usize

Returns the block size, which equals the key length.

§Returns

The length of the cipher key in bytes.

Source§

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

Encrypts plaintext into digit ciphertext.

Each plaintext letter is replaced with its corresponding digit code (either 1 or 2 digits). Numeric digits in the plaintext are escaped by surrounding them with the ‘/’ marker code and duplicating the digit.

§Arguments
  • dst - Output buffer for the encrypted digit string
  • src - Input plaintext bytes to encrypt
§Returns

The number of bytes written to dst.

§Examples

Encrypting “ATTACK” with key “ARABESQUE” and long digits “89” produces “07708081”.

Source§

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

Decrypts digit ciphertext back into plaintext.

Processes the digit stream, recognizing both single-digit and two-digit codes. Handles escaped numeric digits by detecting the ‘/’ marker pattern.

§Arguments
  • dst - Output buffer for the decrypted plaintext
  • src - Input ciphertext digit string to decrypt
§Returns

The number of bytes written to dst.

§Examples

Decrypting “07708081” with key “ARABESQUE” and long digits “89” produces “ATTACK”.

Source§

impl Debug for StraddlingCheckerboard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.