Implement challenge 10.
This commit is contained in:
26
src/set2.rs
26
src/set2.rs
@@ -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!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user