VigenereCipher

Struct VigenereCipher 

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

A Vigenere cipher implementation.

This cipher uses a keyword to perform a series of Caesar ciphers on the plaintext. It is a classic example of a polyalphabetic substitution cipher.

Implementations§

Source§

impl VigenereCipher

Source

pub fn new(key: &str) -> Self

Creates a new Vigenere cipher with the given key string.

Non-alphabetic characters in the key are ignored. The key is converted to uppercase before processing.

§Arguments
  • key - The string used to derive the shift values.

Trait Implementations§

Source§

impl Block for VigenereCipher

Source§

fn block_size(&self) -> usize

Returns the length of the Vigenere key.

Source§

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

Encrypts source bytes into destination buffer using the Vigenere cipher.

This method maps source characters ‘A’-‘Z’ to values 0-25, applies the Vigenere shift from the key, and then maps the result back to uppercase letters. Non-alphabetic characters are currently handled by applying the shift to their raw ASCII value, though most usage expects only ‘A’-‘Z’ input.

§Arguments
  • dst - The destination buffer for the encrypted bytes.
  • src - The source plaintext bytes to encrypt.
§Returns

Returns the number of bytes written to dst.

Source§

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

Decrypts source bytes into destination buffer using the Vigenere cipher.

This method reverses the Vigenere shift by subtracting the key values from the ciphertext values modulo 26.

§Arguments
  • dst - The destination buffer for the decrypted bytes.
  • src - The source ciphertext bytes to decrypt.
§Returns

Returns the number of bytes written to dst.

Source§

impl Debug for VigenereCipher

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.