~kf5jwc/cryptopals-challenges

b362616a6dde493174162040f9bcc1a2f26ee421 — Kyle Jones 1 year, 8 days ago 6093e1e master challenge-18
Challenge 18, CTR decryption
1 files changed, 23 insertions(+), 0 deletions(-)

A aes/src/bin/challenge-18.rs
A aes/src/bin/challenge-18.rs => aes/src/bin/challenge-18.rs +23 -0
@@ 0,0 1,23 @@
use aes::oracles::{
    CTROracle,
    CTRRound,
};
use crypto::symmetriccipher::SymmetricCipherError;

// YELLOW SUBMARINE
const KEY:  &[u8] = &[89, 69, 76, 76, 79, 87, 32, 83, 85, 66, 77, 65, 82, 73, 78, 69];
const CIPHERTEXT: &str = &"L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==";

fn main() -> Result<(), SymmetricCipherError> {
    let input: Vec<u8> = base64::decode(CIPHERTEXT).expect("Provided string, should be valid.");
    let mut oracle = CTROracle::new(KEY, &0u64, &0u64);
    let plaintext: Vec<u8> = {
        let mut ret = vec![];
        for block in input.chunks(aes::BLOCK_SIZE) {
            ret.extend(&oracle.round(block)?);
        }
        ret
    };
    println!("{}", String::from_utf8_lossy(&plaintext));
    Ok(())
}