Nihilist

Struct Nihilist 

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

Nihilist cipher combining straddling checkerboard and transposition.

This cipher performs a two-stage encryption:

  1. Converts plaintext to digits using a straddling checkerboard
  2. Applies columnar transposition to the resulting digits

The decryption process reverses these steps in opposite order.

Implementations§

Source§

impl Nihilist

Source

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:

  • key1 is empty or invalid for the straddling checkerboard
  • key2 is empty or invalid for the transposition cipher
  • chrs is not exactly two characters or contains invalid positions

Trait Implementations§

Source§

impl Block for Nihilist

Source§

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

Encrypts the source data into the destination buffer.

The encryption process:

  1. Converts plaintext to digits using the straddling checkerboard
  2. 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

Decrypts the source ciphertext into the destination buffer.

The decryption process:

  1. Reverses the columnar transposition
  2. 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.

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.