Implement challenge 10.

This commit is contained in:
2022-04-17 21:36:14 -04:00
parent 766a36e790
commit 9f3eb1356c
4 changed files with 159 additions and 10 deletions

View File

@@ -1,4 +1,7 @@
#![allow(dead_code)]
use crate::bytes::Bytes;
use crate::bytes_base64::BytesBase64;
use crate::cbs;
pub fn challenge9() {
let mut bytes = Bytes::from_utf8("YELLOW SUBMARINE");
@@ -7,5 +10,26 @@ pub fn challenge9() {
}
pub fn challenge10() {
println!("[TBD] Challenge 10: TBD");
fn read(path: &str) -> Bytes {
let s = std::fs::read_to_string(path).unwrap();
BytesBase64::from_base64(&s).to_bytes()
}
let iv = Bytes(vec![0; 16]);
let key = Bytes::from_utf8("YELLOW SUBMARINE");
let text = Bytes::from_utf8("aaaabbbbccccddddeeeeffffgggghhhh");
let ciphertext = cbs::encrypt(&key, &iv, &text);
let roundtrip = cbs::decrypt(&key, &iv, &ciphertext);
if text == roundtrip {
let ciphertext = read("data/10.txt");
let cleartext = cbs::decrypt(&key, &iv, &ciphertext);
let output = cleartext.to_utf8()[..10].to_string();
println!("[okay] Challenge 10: {}", output);
} else {
println!("[fail] Challenge 10: rountrip failed");
}
}
pub fn challenge11() {
println!("[tbd] Challenge 11: TBD!");
}