Implement challenge 18 CTR cipher mode.

This commit is contained in:
2022-07-09 11:54:55 -04:00
parent 1304ff2144
commit e70c6c470c
3 changed files with 31 additions and 28 deletions

View File

@@ -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");
}