Skip to main content

Module caesar_cipher

Module caesar_cipher 

Source
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

FunctionShiftEmpty / whitespace-only text
[encrypt] / [decrypt]Any i16 (normalized mod 26)Allowed
[encrypt_safe] / [decrypt_safe]-25 to 25 onlyReturns [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§

CipherError
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