Examples: Simplify encryption example

This commit is contained in:
K Shiva Kiran 2024-04-09 22:14:51 +05:30
parent 45dd149905
commit 7334c04970
1 changed files with 8 additions and 14 deletions

View File

@ -3,31 +3,25 @@ use false_bottom::{FB128, FBAlgo};
fn main() {
// Input messages
let fake_msg = "Weather department warns of heavy rains within the upcoming two days";
let real_msg1 = "I have obtained intel regarding the government's illegal spying";
let real_msg2 = "Please meet me at the Paradise hotel at 5:30 PM";
let real_msg = "I have gathered intel regarding the government's illegal spying";
// Cipher initialization
let mut fb = FB128::init(18, 12).unwrap();
let mut fb = FB128::init(10, 10).unwrap();
// Encryption
let real_key1 = fb.add(&real_msg1.as_bytes());
let real_key2 = fb.add(&real_msg2.as_bytes());
// Encryption (Adding messages is not limited to 2)
let fake_key = fb.add(&fake_msg.as_bytes());
let real_key = fb.add(&real_msg.as_bytes());
// Decryption
let fake_decr = fb.decrypt(&fake_key).unwrap();
let real1_decr = fb.decrypt(&real_key1).unwrap();
let real2_decr = fb.decrypt(&real_key2).unwrap();
let real_decr = fb.decrypt(&real_key).unwrap();
let fake_str = String::from_utf8(fake_decr).unwrap();
let real_str1 = String::from_utf8(real1_decr).unwrap();
let real_str2 = String::from_utf8(real2_decr).unwrap();
let real_str = String::from_utf8(real_decr).unwrap();
println!("Decrypted Contents:");
println!("Fake Message: {fake_str}");
println!("Real Message 1: {real_str1}");
println!("Real Message 2: {real_str2}");
println!("Real Message: {real_str}");
assert_eq!(fake_msg, fake_str);
assert_eq!(real_msg1, real_str1);
assert_eq!(real_msg2, real_str2);
assert_eq!(real_msg, real_str);
}