Implement challenge 9 pkcs 7 padding.

This commit is contained in:
2022-04-13 21:42:42 -04:00
parent 415baedd78
commit 766a36e790
3 changed files with 22 additions and 0 deletions

View File

@@ -67,6 +67,14 @@ impl Bytes {
r r
} }
pub fn pad_pkcs7(&mut self, block_size: usize) -> () {
let Bytes(v) = self;
let padding_value = (block_size - v.len() % block_size) as u8;
for _ in 0..padding_value {
v.push(padding_value);
}
}
pub fn xor(Bytes(a): &Bytes, Bytes(b): &Bytes) -> Bytes { pub fn xor(Bytes(a): &Bytes, Bytes(b): &Bytes) -> Bytes {
Bytes( Bytes(
Iterator::zip(a.iter(), b.iter()) Iterator::zip(a.iter(), b.iter())

View File

@@ -1,6 +1,7 @@
mod bytes; mod bytes;
mod bytes_base64; mod bytes_base64;
mod set1; mod set1;
mod set2;
fn main() { fn main() {
set1::challenge1(); set1::challenge1();
@@ -11,4 +12,6 @@ fn main() {
set1::challenge6(); set1::challenge6();
set1::challenge7(); set1::challenge7();
set1::challenge8(); set1::challenge8();
set2::challenge9();
set2::challenge10();
} }

11
src/set2.rs Normal file
View File

@@ -0,0 +1,11 @@
use crate::bytes::Bytes;
pub fn challenge9() {
let mut bytes = Bytes::from_utf8("YELLOW SUBMARINE");
bytes.pad_pkcs7(20);
println!("[okay] Challenge 9: {:?}", bytes.to_utf8());
}
pub fn challenge10() {
println!("[TBD] Challenge 10: TBD");
}