pub fn attack_two_cbc_blocks(
    block_size: usize,
    first: &[u8],
    second: &[u8],
    k: &[u8],
    iv: &[u8],
) -> Vec<u8> {
    let mut plaintext_prior_xor = Vec::new();
    let mut plaintext = Vec::new();

    for b in (0..block_size).rev() {
        let padding_byte = (block_size - b) as u8;

        let mut block = Vec::from(first);
        block.extend_from_slice(second);

        for j in 0..plaintext_prior_xor.len() {
            block[j + b + 1] = plaintext_prior_xor[j] ^ padding_byte;
        }

        for i in 0..=255 as u8 {
            block[b] = i;

            if !decrypt_random_chosen_msg(&block, k, iv).unwrap() {
                continue;
            }

            plaintext.insert(0, (padding_byte ^ i) ^ first[b]);
            plaintext_prior_xor.insert(0, padding_byte ^ i);
            break;
        }
    }

    plaintext
}
/// attack_two_cbc_blocks decrypts the second block.
/// Help source: <https://en.wikipedia.org/wiki/Padding_oracle_attack>
/// Solution for problem 1 from set 3: <https://cryptopals.com/sets/3/challenges/17>
attack_two_cbc_blocks decrypts the second block.
Help source:
Solution for problem 1 from set 3.
attack_two_cbc_blocks decrypts the second block . Help source : Solution for problem 1 from set 3 .
pub fn attack_two_cbc_blocks(
    block_size: usize,
    first: &[u8],
    second: &[u8],
    k: &[u8],
    iv: &[u8],
) -> Vec<u8> {
    let mut plaintext_prior_xor = Vec::new();
    let mut plaintext = Vec::new();
    for b in (0..block_size).rev() {
        let padding_byte = (block_size - b) as u8;
        let mut block = Vec::from(first);
        block.extend_from_slice(second);
        for j in 0..plaintext_prior_xor.len() {
            block[j + b + 1] = plaintext_prior_xor[j] ^ padding_byte;
        }
        for i in 0..=255 as u8 {
            block[b] = i;
            if !decrypt_random_chosen_msg(&block, k, iv).unwrap() {
                continue;
            }
            plaintext.insert(0, (padding_byte ^ i) ^ first[b]);
            plaintext_prior_xor.insert(0, padding_byte ^ i);
            break;
        }
    }
    plaintext
}
pub fn attack_two_cbc_blocks ( block_size : usize , first : & [ u8 ] , second : & [ u8 ] , k : & [ u8 ] , iv : & [ u8 ] , ) -> Vec < u8 > { let mut plaintext_prior_xor = Vec :: new ( ) ; let mut plaintext = Vec :: new ( ) ; for b in ( 0 .. block_size ) . rev ( ) { let padding_byte = ( block_size - b ) as u8 ; let mut block = Vec :: from ( first ) ; block . extend_from_slice ( second ) ; for j in 0 .. plaintext_prior_xor . len ( ) { block [ j + b + 1 ] = plaintext_prior_xor [ j ] ^ padding_byte ; } for i in 0 ..= 255 as u8 { block [ b ] = i ; if ! decrypt_random_chosen_msg ( & block , k , iv ) . unwrap ( ) { continue ; } plaintext . insert ( 0 , ( padding_byte ^ i ) ^ first [ b ] ) ; plaintext_prior_xor . insert ( 0 , padding_byte ^ i ) ; break ; } } plaintext }
attack_two_cbc_blocks decrypts the second block.
attack_two_cbc_blocks decrypts the second block .
block_size
usize
first
&[u8]
second
&[u8]
k
&[u8]
iv
&[u8]