Expand description
Core Caesar cipher encryption and decryption functionality
§Caesar Cipher Module
Provides easy-to-use Caesar cipher encryption and decryption. Set text and shift number to encrypt or decrypt.
§Basic vs safe APIs
| Function | Shift | Empty / whitespace-only text |
|---|---|---|
[encrypt] / [decrypt] | Any i16 (normalized mod 26) | Allowed |
[encrypt_safe] / [decrypt_safe] | -25 to 25 only | Returns [CipherError::EmptyText] |
§Usage
use caesar_cipher_enc_dec::caesar_cipher::{encrypt, decrypt, encrypt_safe, decrypt_safe};
let text = "I Love You";
let enc_text = encrypt(&text, 3);
let dec_text = decrypt(&enc_text, 3);
let dec_text_2 = encrypt(&enc_text, -3);
// Safe versions with error handling
match encrypt_safe(&text, 3) {
Ok(encrypted) => println!("Encrypted: {}", encrypted),
Err(e) => println!("Error: {}", e),
}§Brute Force Example
You can use this encrypt code for brute force decryption:
use caesar_cipher_enc_dec::caesar_cipher::encrypt;
let text = "I Love You";
for i in 0..26 {
encrypt(&text, i);
}Enums§
- Cipher
Error - Error enum for Caesar cipher operations
Functions§
- decrypt
- Decrypts text using Caesar cipher
- decrypt_
safe - Decrypts text using Caesar cipher with error handling
- encrypt
- Encrypts text using Caesar cipher
- encrypt_
safe - Encrypts text using Caesar cipher with error handling