use anyhow::Result;
use colored::*;
use ruscrypt::classical::caesar;
use ruscrypt::stream::rc4;
use ruscrypt::block::aes;
use ruscrypt::asym::rsa;
use ruscrypt::hash::sha256;
fn main() -> Result<()> {
print_quick_start_banner();
println!("{}", "Let's explore RusCrypt with 5 essential examples!\n".bright_blue());
println!("{}", "1. π Classical Cryptography (Caesar Cipher)".cyan().bold());
quick_classical_example()?;
println!("\n{}", "2. π Stream Encryption (RC4)".green().bold());
quick_stream_example()?;
println!("\n{}", "3. π‘οΈ Modern Encryption (AES)".blue().bold());
quick_block_example()?;
println!("\n{}", "4. π Public-Key Cryptography (RSA)".purple().bold());
quick_asymmetric_example()?;
println!("\n{}", "5. π’ Secure Hashing (SHA-256)".magenta().bold());
quick_hash_example()?;
print_next_steps();
Ok(())
}
fn print_quick_start_banner() {
println!("{}", r"
____ ____ _
| _ \ _ _ ___ / ___|_ __ _ _ _ __ | |_
| |_) | | | / __| | | '__| | | | '_ \| __|
| _ <| |_| \__ \ |___| | | |_| | |_) | |_
|_| \_\\__,_|___/\____|_| \__, | .__/ \__|
|___/|_|
".bright_blue());
println!("{}", "π RusCrypt Quick Start Guide".bright_blue().bold());
println!("{}", "Master cryptography in 5 simple examples".cyan().italic());
println!();
}
fn quick_classical_example() -> Result<()> {
println!("{}", " Historical cipher used by Julius Caesar.".white());
println!("{}", " π Educational: Shows basic substitution concepts".yellow());
let message = "HELLO WORLD";
let shift = 3;
let encrypted = caesar::encrypt(message, shift)?;
println!(" π Original: {}", message.cyan());
println!(" π’ Shift: {} positions", shift.to_string().yellow());
println!(" π Encrypted: {} β {}", message.white(), encrypted.green().bold());
let decrypted = caesar::decrypt(&encrypted, shift)?;
println!(" π Decrypted: {} β {}", encrypted.white(), decrypted.blue().bold());
println!(" β οΈ Security: Educational only - easily broken!");
println!(" π‘ Try: {}", "cargo run -- encrypt --caesar".bright_green());
Ok(())
}
fn quick_stream_example() -> Result<()> {
println!("{}", " Encrypts data byte-by-byte using a keystream.".white());
println!("{}", " β οΈ Deprecated: Known vulnerabilities, educational use only".yellow());
let message = "Secret message!";
let key = "mykey123";
let encrypted = rc4::encrypt(message, key, "base64")?;
println!(" π Original: {}", message.cyan());
println!(" ποΈ Key: {}", key.yellow());
println!(" π Encrypted: {}", encrypted.green().bold());
let decrypted = rc4::decrypt(&encrypted, key, "base64")?;
println!(" π Decrypted: {}", decrypted.blue().bold());
println!(" π Round-trip: {} = {}", message == decrypted, if message == decrypted { "β
" } else { "β" });
println!(" π‘ Try: {}", "cargo run -- encrypt --rc4".bright_green());
Ok(())
}
fn quick_block_example() -> Result<()> {
println!("{}", " Industry-standard symmetric encryption.".white());
println!("{}", " β
Secure: Recommended for modern applications".green());
let message = "Top secret data!";
let password = "strongpassword";
let encrypted = aes::encrypt(message, password, "256", "CBC", "base64")?;
println!(" π Original: {}", message.cyan());
println!(" π Password: {}", password.yellow());
println!(" π Encrypted (AES-256 CBC): {}", encrypted.green().bold());
let decrypted = aes::decrypt(&encrypted, password, "256", "CBC", "base64")?;
println!(" π Decrypted: {}", decrypted.blue().bold());
println!(" π‘οΈ Security: Bank-grade encryption!");
println!(" π‘ Try: {}", "cargo run -- encrypt --aes".bright_green());
Ok(())
}
fn quick_asymmetric_example() -> Result<()> {
println!("{}", " Public-key cryptography for secure communication.".white());
println!("{}", " π Concept: Different keys for encryption/decryption".yellow());
let message = "Hello RSA!";
let (encrypted, private_key) = rsa::encrypt(message, "512", "base64", "n:e")?;
println!(" π Original: {}", message.cyan());
println!(" π Encrypted: {}...", encrypted[..30].green().bold());
println!(" π Private Key: {}...", private_key[..20].yellow());
let decrypted = rsa::decrypt(&encrypted, &private_key, "base64")?;
println!(" π Decrypted: {}", decrypted.blue().bold());
println!(" π Use case: Secure communication without shared secrets");
println!(" π‘ Try: {}", "cargo run -- encrypt --rsa".bright_green());
Ok(())
}
fn quick_hash_example() -> Result<()> {
println!("{}", " Creates unique fingerprints for any data.".white());
println!("{}", " β
Secure: Perfect for data integrity and passwords".green());
let messages = vec!["Hello", "Hello!", "hello"];
for (i, message) in messages.iter().enumerate() {
let hash = sha256::hash(message)?;
println!(" π Input {}: {} β Hash: {}...",
(i + 1).to_string().white(),
message.cyan(),
hash[..16].green().bold()
);
}
let test = "consistency";
let hash1 = sha256::hash(test)?;
let hash2 = sha256::hash(test)?;
println!(" π Consistency: {} β {}",
if hash1 == hash2 { "β
Always same result" } else { "β Error" },
if hash1 == hash2 { "Perfect!" } else { "Failed!" }
);
println!(" β¨ Notice: Small input changes = Completely different hashes!");
println!(" π‘ Try: {}", "cargo run -- hash --sha256".bright_green());
Ok(())
}
fn print_next_steps() {
println!("\n{}", "π Congratulations! You've mastered RusCrypt basics!".bright_green().bold());
println!();
println!("{}", "π Next Steps:".yellow().bold());
println!(" β’ Run the full demo: {}", "cargo run --example demo".bright_cyan());
println!(" β’ Try the CLI tool: {}", "cargo run -- --help".bright_cyan());
println!(" β’ Explore algorithms: {}", "cargo run -- encrypt --help".bright_cyan());
println!();
println!("{}", "π Available Algorithms:".yellow().bold());
println!(" Classical: Caesar, Vigenère, Playfair, Rail Fence");
println!(" Stream: RC4 (educational)");
println!(" Block: AES (secure), DES (educational)");
println!(" Asymmetric: RSA, Diffie-Hellman");
println!(" Hash: MD5, SHA-1 (legacy), SHA-256 (secure)");
println!();
println!("{}", "π Security Reminder:".red().bold());
println!(" β
Production: AES, RSA (β₯2048 bits), SHA-256");
println!(" π Education: All classical ciphers, RC4, DES, MD5, SHA-1");
println!();
println!("{}", "Built with β€οΈ using Rust π¦".bright_blue().italic());
}