Implement challenge 18 CTR cipher mode.
This commit is contained in:
14
src/set3.rs
14
src/set3.rs
@@ -97,10 +97,20 @@ pub fn challenge17() {
|
||||
|
||||
pub fn challenge18() {
|
||||
let key = Bytes::from_utf8("YELLOW SUBMARINE");
|
||||
|
||||
let cleartext = Bytes::from_utf8("Let's see if we can get the party started hard my friends.");
|
||||
let cipher = ctr::encrypt(&key, 42351234, &cleartext);
|
||||
let roundtrip = ctr::encrypt(&key, 42351234, &cipher);
|
||||
assert_eq!(cleartext, roundtrip);
|
||||
|
||||
let cipher = BytesBase64::from_base64(
|
||||
"L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==",
|
||||
)
|
||||
.to_bytes();
|
||||
let cleartext = ctr::decrypt(&key, &cipher).to_utf8();
|
||||
println!("[xxxx] Challenge 18: {cleartext}");
|
||||
let cleartext = ctr::decrypt(&key, 0, &cipher).to_utf8();
|
||||
println!("[okay] Challenge 18: {cleartext}");
|
||||
}
|
||||
|
||||
pub fn challenge19() {
|
||||
println!("[xxxx] Challenge 19: TBD");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user