pub fn cbc_bitflipping_attack(k: &[u8], iv: &[u8]) -> Result<bool, crate::Error> {
    let block_size = {
        let unknown_output = encrypt_user_data(&Vec::new(), k, iv).unwrap();
        let mut current_length = unknown_output.len();

        let mut m = Vec::new();
        while current_length == unknown_output.len() {
            m.push(b'A');
            current_length = encrypt_user_data(&m, k, iv).unwrap().len();
        }

        current_length - unknown_output.len()
    };

    // comment1=cooking %20MCs;userdata= 0000000000000000 0000,admin-true; comment2=%20like %20a%20pound%20o f%20bacon
    let mut ciphertext = encrypt_user_data(b"00000000000000000000,admin-true", k, iv).unwrap();

    ciphertext[36] = {
        let mut result = 0;

        for i in 0..=255 {
            if (ciphertext[36] ^ b',') ^ i == b';' {
                result = i;
            }
        }

        result
    };

    ciphertext[42] = {
        let mut result = 0;

        for i in 0..=255 {
            if (ciphertext[42] ^ b'-') ^ i == b'=' {
                result = i;
            }
        }

        result
    };

    decrypt_user_data(&ciphertext, k, iv)
}
/// CBC bitflipping attack
///
/// Solution for problem 8 from set 2: <https://cryptopals.com/sets/2/challenges/16>
CBC bitflipping attack
Solution for problem 8 from set 2.
CBC bitflipping attack Solution for problem 8 from set 2 .
pub fn cbc_bitflipping_attack(k: &[u8], iv: &[u8]) -> Result<bool, crate::Error> {
    let block_size = {
        let unknown_output = encrypt_user_data(&Vec::new(), k, iv).unwrap();
        let mut current_length = unknown_output.len();
        let mut m = Vec::new();
        while current_length == unknown_output.len() {
            m.push(b'A');
            current_length = encrypt_user_data(&m, k, iv).unwrap().len();
        }
        current_length - unknown_output.len()
    };
    // comment1=cooking %20MCs;userdata= 0000000000000000 0000,admin-true; comment2=%20like %20a%20pound%20o f%20bacon
    let mut ciphertext = encrypt_user_data(b"00000000000000000000,admin-true", k, iv).unwrap();
    ciphertext[36] = {
        let mut result = 0;
        for i in 0..=255 {
            if (ciphertext[36] ^ b',') ^ i == b';' {
                result = i;
            }
        }
        result
    };
    ciphertext[42] = {
        let mut result = 0;
        for i in 0..=255 {
            if (ciphertext[42] ^ b'-') ^ i == b'=' {
                result = i;
            }
        }
        result
    };
    decrypt_user_data(&ciphertext, k, iv)
}
pub fn cbc_bitflipping_attack ( k : & [ u8 ] , iv : & [ u8 ] ) -> Result < bool , crate :: Error > { let block_size = { let unknown_output = encrypt_user_data ( & Vec :: new ( ) , k , iv ) . unwrap ( ) ; let mut current_length = unknown_output . len ( ) ; let mut m = Vec :: new ( ) ; while current_length == unknown_output . len ( ) { m . push ( b'A' ) ; current_length = encrypt_user_data ( & m , k , iv ) . unwrap ( ) . len ( ) ; } current_length - unknown_output . len ( ) } ; // comment1=cooking %20MCs;userdata= 0000000000000000 0000,admin-true; comment2=%20like %20a%20pound%20o f%20bacon let mut ciphertext = encrypt_user_data ( b" " , k , iv ) . unwrap ( ) ; ciphertext [ 36 ] = { let mut result = 0 ; for i in 0 ..= 255 { if ( ciphertext [ 36 ] ^ b',' ) ^ i == b';' { result = i ; } } result } ; ciphertext [ 42 ] = { let mut result = 0 ; for i in 0 ..= 255 { if ( ciphertext [ 42 ] ^ b'-' ) ^ i == b'=' { result = i ; } } result } ; decrypt_user_data ( & ciphertext , k , iv ) }
CBC bitflipping attack
Solution for problem 8 from set 2: <https://cryptopals.com/sets/2/challenges/16>
CBC bitflipping attack Solution for problem 8 from set 2 : <https : // cryptopals . com / sets / 2 / challenges / 16 >
k
&[u8]
iv
&[u8]