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 ciphertextdec- Decryption lookup table mapping A-Z (0-25) to plaintext
Implementations§
Source§impl CaesarCipher
impl CaesarCipher
Sourcepub fn new(key: i32) -> Self
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 3Trait Implementations§
Source§impl Block for CaesarCipher
impl Block for CaesarCipher
Source§fn block_size(&self) -> usize
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
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 assrc)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
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 assrc)src- Source data to decrypt
§Returns
The number of bytes written to the destination buffer (equal to src.len()).