Examples: Simplify encryption example
This commit is contained in:
parent
45dd149905
commit
7334c04970
|
@ -3,31 +3,25 @@ use false_bottom::{FB128, FBAlgo};
|
||||||
fn main() {
|
fn main() {
|
||||||
// Input messages
|
// Input messages
|
||||||
let fake_msg = "Weather department warns of heavy rains within the upcoming two days";
|
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_msg = "I have gathered intel regarding the government's illegal spying";
|
||||||
let real_msg2 = "Please meet me at the Paradise hotel at 5:30 PM";
|
|
||||||
|
|
||||||
// Cipher initialization
|
// Cipher initialization
|
||||||
let mut fb = FB128::init(18, 12).unwrap();
|
let mut fb = FB128::init(10, 10).unwrap();
|
||||||
|
|
||||||
// Encryption
|
// Encryption (Adding messages is not limited to 2)
|
||||||
let real_key1 = fb.add(&real_msg1.as_bytes());
|
|
||||||
let real_key2 = fb.add(&real_msg2.as_bytes());
|
|
||||||
let fake_key = fb.add(&fake_msg.as_bytes());
|
let fake_key = fb.add(&fake_msg.as_bytes());
|
||||||
|
let real_key = fb.add(&real_msg.as_bytes());
|
||||||
|
|
||||||
// Decryption
|
// Decryption
|
||||||
let fake_decr = fb.decrypt(&fake_key).unwrap();
|
let fake_decr = fb.decrypt(&fake_key).unwrap();
|
||||||
let real1_decr = fb.decrypt(&real_key1).unwrap();
|
let real_decr = fb.decrypt(&real_key).unwrap();
|
||||||
let real2_decr = fb.decrypt(&real_key2).unwrap();
|
|
||||||
|
|
||||||
let fake_str = String::from_utf8(fake_decr).unwrap();
|
let fake_str = String::from_utf8(fake_decr).unwrap();
|
||||||
let real_str1 = String::from_utf8(real1_decr).unwrap();
|
let real_str = String::from_utf8(real_decr).unwrap();
|
||||||
let real_str2 = String::from_utf8(real2_decr).unwrap();
|
|
||||||
|
|
||||||
println!("Decrypted Contents:");
|
println!("Decrypted Contents:");
|
||||||
println!("Fake Message: {fake_str}");
|
println!("Fake Message: {fake_str}");
|
||||||
println!("Real Message 1: {real_str1}");
|
println!("Real Message: {real_str}");
|
||||||
println!("Real Message 2: {real_str2}");
|
|
||||||
assert_eq!(fake_msg, fake_str);
|
assert_eq!(fake_msg, fake_str);
|
||||||
assert_eq!(real_msg1, real_str1);
|
assert_eq!(real_msg, real_str);
|
||||||
assert_eq!(real_msg2, real_str2);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue