pub struct Nihilist { /* private fields */ }Expand description
Nihilist cipher combining straddling checkerboard and transposition.
This cipher performs a two-stage encryption:
- Converts plaintext to digits using a straddling checkerboard
- Applies columnar transposition to the resulting digits
The decryption process reverses these steps in opposite order.
Implementations§
Source§impl Nihilist
impl Nihilist
Sourcepub fn new(key1: &str, key2: &str, chrs: &str) -> Result<Self>
pub fn new(key1: &str, key2: &str, chrs: &str) -> Result<Self>
Creates a new Nihilist cipher with the specified keys.
§Arguments
key1- The key for the straddling checkerboard (e.g., “ARABESQUE”)key2- The key for the transposition cipher (e.g., “SUBWAY”)chrs- Two characters defining the blank positions in the checkerboard (e.g., “37”)
§Returns
Returns Ok(Nihilist) if both keys are valid, or Err(String) with an error message
if either key is invalid or empty.
§Examples
use old_crypto_rs::Nihilist;
let cipher = Nihilist::new("ARABESQUE", "SUBWAY", "37").unwrap();§Errors
Returns an error if:
key1is empty or invalid for the straddling checkerboardkey2is empty or invalid for the transposition cipherchrsis not exactly two characters or contains invalid positions
Trait Implementations§
Source§impl Block for Nihilist
impl Block for Nihilist
Source§fn block_size(&self) -> usize
fn block_size(&self) -> usize
Returns the block size of the cipher.
The block size is determined by the transposition cipher’s key length.
§Returns
The number of characters that can be processed in one block.
Source§fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
fn encrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
Encrypts the source data into the destination buffer.
The encryption process:
- Converts plaintext to digits using the straddling checkerboard
- Applies columnar transposition to the resulting digits
§Arguments
dst- Destination buffer for the ciphertext (must be large enough)src- Source plaintext to encrypt
§Returns
The number of bytes written to dst.
Source§fn decrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
fn decrypt(&self, dst: &mut [u8], src: &[u8]) -> usize
Decrypts the source ciphertext into the destination buffer.
The decryption process:
- Reverses the columnar transposition
- Converts the resulting digits back to plaintext using the straddling checkerboard
§Arguments
dst- Destination buffer for the plaintext (must be large enough)src- Source ciphertext to decrypt
§Returns
The number of bytes written to dst.