1use anyhow::Result;
2use colored::*;
3
4use ruscrypt::classical::caesar;
6use ruscrypt::stream::rc4;
7use ruscrypt::block::aes;
8use ruscrypt::asym::rsa;
9use ruscrypt::hash::sha256;
10
11fn main() -> Result<()> {
12 print_quick_start_banner();
13
14 println!("{}", "Let's explore RusCrypt with 5 essential examples!\n".bright_blue());
15
16 println!("{}", "1. π Classical Cryptography (Caesar Cipher)".cyan().bold());
18 quick_classical_example()?;
19
20 println!("\n{}", "2. π Stream Encryption (RC4)".green().bold());
22 quick_stream_example()?;
23
24 println!("\n{}", "3. π‘οΈ Modern Encryption (AES)".blue().bold());
26 quick_block_example()?;
27
28 println!("\n{}", "4. π Public-Key Cryptography (RSA)".purple().bold());
30 quick_asymmetric_example()?;
31
32 println!("\n{}", "5. π’ Secure Hashing (SHA-256)".magenta().bold());
34 quick_hash_example()?;
35
36 print_next_steps();
37
38 Ok(())
39}
40
41fn print_quick_start_banner() {
42 println!("{}", r"
43 ____ ____ _
44 | _ \ _ _ ___ / ___|_ __ _ _ _ __ | |_
45 | |_) | | | / __| | | '__| | | | '_ \| __|
46 | _ <| |_| \__ \ |___| | | |_| | |_) | |_
47 |_| \_\\__,_|___/\____|_| \__, | .__/ \__|
48 |___/|_|
49 ".bright_blue());
50
51 println!("{}", "π RusCrypt Quick Start Guide".bright_blue().bold());
52 println!("{}", "Master cryptography in 5 simple examples".cyan().italic());
53 println!();
54}
55
56fn quick_classical_example() -> Result<()> {
57 println!("{}", " Historical cipher used by Julius Caesar.".white());
58 println!("{}", " π Educational: Shows basic substitution concepts".yellow());
59
60 let message = "HELLO WORLD";
61 let shift = 3;
62
63 let encrypted = caesar::encrypt(message, shift)?;
65 println!(" π Original: {}", message.cyan());
66 println!(" π’ Shift: {} positions", shift.to_string().yellow());
67 println!(" π Encrypted: {} β {}", message.white(), encrypted.green().bold());
68
69 let decrypted = caesar::decrypt(&encrypted, shift)?;
71 println!(" π Decrypted: {} β {}", encrypted.white(), decrypted.blue().bold());
72
73 println!(" β οΈ Security: Educational only - easily broken!");
74 println!(" π‘ Try: {}", "cargo run -- encrypt --caesar".bright_green());
75
76 Ok(())
77}
78
79fn quick_stream_example() -> Result<()> {
80 println!("{}", " Encrypts data byte-by-byte using a keystream.".white());
81 println!("{}", " β οΈ Deprecated: Known vulnerabilities, educational use only".yellow());
82
83 let message = "Secret message!";
84 let key = "mykey123";
85
86 let encrypted = rc4::encrypt(message, key, "base64")?;
88 println!(" π Original: {}", message.cyan());
89 println!(" ποΈ Key: {}", key.yellow());
90 println!(" π Encrypted: {}", encrypted.green().bold());
91
92 let decrypted = rc4::decrypt(&encrypted, key, "base64")?;
94 println!(" π Decrypted: {}", decrypted.blue().bold());
95
96 println!(" π Round-trip: {} = {}", message == decrypted, if message == decrypted { "β
" } else { "β" });
97 println!(" π‘ Try: {}", "cargo run -- encrypt --rc4".bright_green());
98
99 Ok(())
100}
101
102fn quick_block_example() -> Result<()> {
103 println!("{}", " Industry-standard symmetric encryption.".white());
104 println!("{}", " β
Secure: Recommended for modern applications".green());
105
106 let message = "Top secret data!";
107 let password = "strongpassword";
108
109 let encrypted = aes::encrypt(message, password, "256", "CBC", "base64")?;
111 println!(" π Original: {}", message.cyan());
112 println!(" π Password: {}", password.yellow());
113 println!(" π Encrypted (AES-256 CBC): {}", encrypted.green().bold());
114
115 let decrypted = aes::decrypt(&encrypted, password, "256", "CBC", "base64")?;
117 println!(" π Decrypted: {}", decrypted.blue().bold());
118
119 println!(" π‘οΈ Security: Bank-grade encryption!");
120 println!(" π‘ Try: {}", "cargo run -- encrypt --aes".bright_green());
121
122 Ok(())
123}
124
125fn quick_asymmetric_example() -> Result<()> {
126 println!("{}", " Public-key cryptography for secure communication.".white());
127 println!("{}", " π Concept: Different keys for encryption/decryption".yellow());
128
129 let message = "Hello RSA!";
130
131 let (encrypted, private_key) = rsa::encrypt(message, "512", "base64", "n:e")?;
133 println!(" π Original: {}", message.cyan());
134 println!(" π Encrypted: {}...", encrypted[..30].green().bold());
135 println!(" π Private Key: {}...", private_key[..20].yellow());
136
137 let decrypted = rsa::decrypt(&encrypted, &private_key, "base64")?;
139 println!(" π Decrypted: {}", decrypted.blue().bold());
140
141 println!(" π Use case: Secure communication without shared secrets");
142 println!(" π‘ Try: {}", "cargo run -- encrypt --rsa".bright_green());
143
144 Ok(())
145}
146
147fn quick_hash_example() -> Result<()> {
148 println!("{}", " Creates unique fingerprints for any data.".white());
149 println!("{}", " β
Secure: Perfect for data integrity and passwords".green());
150
151 let messages = vec!["Hello", "Hello!", "hello"];
152
153 for (i, message) in messages.iter().enumerate() {
154 let hash = sha256::hash(message)?;
155 println!(" π Input {}: {} β Hash: {}...",
156 (i + 1).to_string().white(),
157 message.cyan(),
158 hash[..16].green().bold()
159 );
160 }
161
162 let test = "consistency";
164 let hash1 = sha256::hash(test)?;
165 let hash2 = sha256::hash(test)?;
166 println!(" π Consistency: {} β {}",
167 if hash1 == hash2 { "β
Always same result" } else { "β Error" },
168 if hash1 == hash2 { "Perfect!" } else { "Failed!" }
169 );
170
171 println!(" β¨ Notice: Small input changes = Completely different hashes!");
172 println!(" π‘ Try: {}", "cargo run -- hash --sha256".bright_green());
173
174 Ok(())
175}
176
177fn print_next_steps() {
178 println!("\n{}", "π Congratulations! You've mastered RusCrypt basics!".bright_green().bold());
179 println!();
180
181 println!("{}", "π Next Steps:".yellow().bold());
182 println!(" β’ Run the full demo: {}", "cargo run --example demo".bright_cyan());
183 println!(" β’ Try the CLI tool: {}", "cargo run -- --help".bright_cyan());
184 println!(" β’ Explore algorithms: {}", "cargo run -- encrypt --help".bright_cyan());
185 println!();
186
187 println!("{}", "π Available Algorithms:".yellow().bold());
188 println!(" Classical: Caesar, Vigenère, Playfair, Rail Fence");
189 println!(" Stream: RC4 (educational)");
190 println!(" Block: AES (secure), DES (educational)");
191 println!(" Asymmetric: RSA, Diffie-Hellman");
192 println!(" Hash: MD5, SHA-1 (legacy), SHA-256 (secure)");
193 println!();
194
195 println!("{}", "π Security Reminder:".red().bold());
196 println!(" β
Production: AES, RSA (β₯2048 bits), SHA-256");
197 println!(" π Education: All classical ciphers, RC4, DES, MD5, SHA-1");
198 println!();
199
200 println!("{}", "Built with β€οΈ using Rust π¦".bright_blue().italic());
201}