Implement conversion from base64 into bytes.

This commit is contained in:
2022-03-26 19:14:38 -04:00
parent b490b67d55
commit 1e84f2cb58
3 changed files with 57 additions and 33 deletions

View File

@@ -72,12 +72,12 @@ pub fn challenge5() {
}
pub fn challenge6() {
fn read(path: &str) -> BytesBase64 {
fn read(path: &str) -> Bytes {
let s = std::fs::read_to_string(path).unwrap();
BytesBase64::from_base64(&s)
BytesBase64::from_base64(&s).to_bytes()
}
fn write(path: &str, bytes_base64: &BytesBase64) {
fn _write(path: &str, bytes_base64: &BytesBase64) {
let width = 60;
let bytes = bytes_base64.to_string();
let mut output_vec = vec![];
@@ -88,12 +88,19 @@ pub fn challenge6() {
}
output_vec.push(*e.0);
}
output_vec.push('\n' as u8);
let mut f = std::fs::File::create(path).unwrap();
f.write(&output_vec).unwrap();
}
let bytes_base64 = read("data/6.txt");
write("data/6_out.txt", &bytes_base64);
println!("[open] Challenge 6");
fn _test_roundtrip() {
// Test that conversion from to bytes and back works
let bytes = read("data/6.txt");
let bytes_base64 = BytesBase64::from_bytes(bytes);
_write("data/6.txt", &bytes_base64);
}
_test_roundtrip();
let _bytes = read("data/6.txt");
println!("[open] Challenge 6: {}", 0);
}