Skip to main content

VicCipher

Struct VicCipher 

Source
pub struct VicCipher<A: Alphabet, D: Derive<F>, F: Frequent> { /* private fields */ }
Expand description

VIC cipher implementation combining straddling checkerboard and transposition ciphers.

The VIC cipher uses a complex key derivation system and three main components:

  • A straddling checkerboard for initial encoding
  • A first regular transposition
  • A second irregular transposition

Implementations§

Source§

impl<A: Alphabet, D: Derive<F>, F: Frequent> VicCipher<A, D, F>

Source

pub fn new(ind: &str, phrase: &str, imsg: &str, persn: usize) -> Result<Self>

Creates a new VIC cipher instance with the specified key material.

This constructor performs the complex key derivation process used in the VIC cipher, which involves expanding the key material into three separate keys:

  • A key for the first regular transposition
  • A key for the second irregular transposition
  • A key for the straddling checkerboard
§Arguments
  • persn - Personal number used for the straddling checkerboard (typically 2 digits)
  • ind - Indicator string containing at least 5 digits used in key derivation
  • phrase - Key phrase that must be at least 20 characters long, used for key expansion
  • imsg - Initial message number as a string of digits
§Returns

Returns Ok(VicCipher) if the cipher was successfully constructed, or Err(String) if any of the key material is invalid or if the transposition or straddling checkerboard construction fails.

§Examples
use old_crypto_rs::EnglishVic;

let cipher = EnglishVic::new(
    "77651",
    "IDREAMOFJEANNIEWITHT",
    "741776",
    6,
).unwrap();

Trait Implementations§

Source§

impl<A: Alphabet, D: Derive<F>, F: Frequent> Block for VicCipher<A, D, F>

Source§

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

Encrypts plaintext using the VIC cipher.

The encryption process consists of three steps:

  1. Encode using the straddling checkerboard
  2. Apply the first (regular) transposition
  3. Apply the second (irregular) transposition
§Arguments
  • dst - Destination buffer for ciphertext (must be large enough)
  • src - Source plaintext as bytes
§Returns

Returns the number of bytes written to the destination buffer.

Source§

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

Decrypts ciphertext using the VIC cipher.

The decryption process reverses the encryption steps:

  1. Reverse the second (irregular) transposition
  2. Reverse the first (regular) transposition
  3. Decode using the straddling checkerboard
§Arguments
  • dst - Destination buffer for plaintext (must be large enough)
  • src - Source ciphertext as bytes
§Returns

Returns the number of bytes written to the destination buffer.

Source§

fn block_size(&self) -> usize

Source§

impl<A: Debug + Alphabet, D: Debug + Derive<F>, F: Debug + Frequent> Debug for VicCipher<A, D, F>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, D, F> Freeze for VicCipher<A, D, F>

§

impl<A, D, F> RefUnwindSafe for VicCipher<A, D, F>

§

impl<A, D, F> Send for VicCipher<A, D, F>
where A: Send, D: Send, F: Send,

§

impl<A, D, F> Sync for VicCipher<A, D, F>
where A: Sync, D: Sync, F: Sync,

§

impl<A, D, F> Unpin for VicCipher<A, D, F>
where A: Unpin, D: Unpin, F: Unpin,

§

impl<A, D, F> UnsafeUnpin for VicCipher<A, D, F>

§

impl<A, D, F> UnwindSafe for VicCipher<A, D, F>
where A: UnwindSafe, D: UnwindSafe, F: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.