CaesarCipher

Struct CaesarCipher 

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

A Caesar cipher implementation.

This struct maintains the shift key for the uppercase English alphabet (A-Z). Characters not in the alphabet are left unchanged.

§Fields

  • enc - Encryption lookup table mapping A-Z (0-25) to ciphertext
  • dec - Decryption lookup table mapping A-Z (0-25) to plaintext

Implementations§

Source§

impl CaesarCipher

Source

pub fn new(key: i32) -> Self

Creates a new Caesar cipher with the specified shift key.

The key represents how many positions each letter should be shifted in the alphabet.

§Arguments
  • key - The shift value for the cipher (typically 0-25, but any integer works)
§Returns

A new CaesarCipher instance ready for encryption and decryption operations.

§Examples
use old_crypto_rs::CaesarCipher;

let cipher = CaesarCipher::new(3); // Classic Caesar cipher with shift of 3

Trait Implementations§

Source§

impl Block for CaesarCipher

Source§

fn block_size(&self) -> usize

Returns the block size for the Caesar cipher.

The Caesar cipher operates on single characters, so the block size is 1.

Source§

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

Encrypts the source data into the destination buffer.

Each byte in the source is shifted by the key value. Characters not in the alphabet (A-Z) are copied unchanged.

§Arguments
  • dst - Destination buffer for encrypted data (must be at least as large as src)
  • src - Source data to encrypt
§Returns

The number of bytes written to the destination buffer (equal to src.len()).

Source§

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

Decrypts the source data into the destination buffer.

Each byte in the source is shifted back by the key value. Characters not in the alphabet (A-Z) are copied unchanged.

§Arguments
  • dst - Destination buffer for decrypted data (must be at least as large as src)
  • src - Source data to decrypt
§Returns

The number of bytes written to the destination buffer (equal to src.len()).

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.