pub fn decrypt(&self, ciphertext: &[u8], iv: &[u8]) -> Result<Vec<u8>, PadbusterError> {
        info!("Starting Decrypt Mode");
        info!("Attempting to decrypt {:?} bytes", ciphertext);

        if ciphertext.len() % (self.block_size as usize) != 0 {
            return Err(PadbusterError::ValidationError(
                "Ciphertext not of block size",
            ));
        }

        if iv.is_empty() && ciphertext.len() < (self.block_size as usize) * 2 {
            return Err(PadbusterError::ValidationError(
                "Ciphertext not at least 2 * block size",
            ));
        }

        let mut used_iv = iv.to_owned();
        let mut ctext = ciphertext.to_owned();
        if iv.is_empty() {
            used_iv = ciphertext[..(self.block_size as usize)].to_vec();
            ctext = ciphertext[(self.block_size as usize)..].to_vec();
        }

        let mut decrypted = vec![0u8; ctext.len()];

        let mut n = 0;
        while !ctext.is_empty() {
            info!("*** Starting Block {} ***\n", n / self.block_size);
            let mut block = ctext[0..(self.block_size as usize)].to_vec();
            ctext = ctext[(self.block_size as usize)..].to_vec();
            let next_iv = block.clone();

            let current_block = block.clone();

            let intermediate_bytes = match self.bust(&mut block) {
                Err(e) => return Err(e),
                Ok(r) => r,
            };
            let current_intermediate_bytes = intermediate_bytes.clone();

            let mut decrypted_block = xor_data(intermediate_bytes, used_iv);
            let current_decrypted_block = decrypted_block.clone();
            decrypted.append(&mut decrypted_block);

            used_iv = next_iv;
            n += self.block_size;

            info!(
                "Block {} Results:
            [+] New Cipher Text (HEX): {}
            [+] Intermediate Bytes (HEX): {}
            [+] Plain Text: {}",
                n / self.block_size,
                hex::encode(current_block),
                hex::encode(current_intermediate_bytes),
                std::str::from_utf8(&current_decrypted_block).unwrap()
            );
        }

        info!(
            "*** Finished ***
        [+] Decrypted value (ASCII): {}
        [+] Decrypted value (HEX): {}
        [+] Decrypted value (Base64): {}",
            std::str::from_utf8(&decrypted).unwrap(),
            hex::encode(&decrypted),
            base64::encode(&decrypted)
        );

        Ok(decrypted)
    }
/// Decrypt the given ciphertext & iv using oracle
///
/// # Arguments
///
/// * `ciphertext` - Ciphertext to use.
/// * `iv` - IV to use if known empty Vec<u8> if not.
///
Decrypt the given ciphertext & iv using oracle
Decrypt the given ciphertext & iv using oracle
pub fn decrypt(&self, ciphertext: &[u8], iv: &[u8]) -> Result<Vec<u8>, PadbusterError> {
        info!("Starting Decrypt Mode");
        info!("Attempting to decrypt {:?} bytes", ciphertext);
        if ciphertext.len() % (self.block_size as usize) != 0 {
            return Err(PadbusterError::ValidationError(
                "Ciphertext not of block size",
            ));
        }
        if iv.is_empty() && ciphertext.len() < (self.block_size as usize) * 2 {
            return Err(PadbusterError::ValidationError(
                "Ciphertext not at least 2 * block size",
            ));
        }
        let mut used_iv = iv.to_owned();
        let mut ctext = ciphertext.to_owned();
        if iv.is_empty() {
            used_iv = ciphertext[..(self.block_size as usize)].to_vec();
            ctext = ciphertext[(self.block_size as usize)..].to_vec();
        }
        let mut decrypted = vec![0u8; ctext.len()];
        let mut n = 0;
        while !ctext.is_empty() {
            info!("*** Starting Block {} ***\n", n / self.block_size);
            let mut block = ctext[0..(self.block_size as usize)].to_vec();
            ctext = ctext[(self.block_size as usize)..].to_vec();
            let next_iv = block.clone();
            let current_block = block.clone();
            let intermediate_bytes = match self.bust(&mut block) {
                Err(e) => return Err(e),
                Ok(r) => r,
            };
            let current_intermediate_bytes = intermediate_bytes.clone();
            let mut decrypted_block = xor_data(intermediate_bytes, used_iv);
            let current_decrypted_block = decrypted_block.clone();
            decrypted.append(&mut decrypted_block);
            used_iv = next_iv;
            n += self.block_size;
            info!(
                "Block {} Results:
            [+] New Cipher Text (HEX): {}
            [+] Intermediate Bytes (HEX): {}
            [+] Plain Text: {}",
                n / self.block_size,
                hex::encode(current_block),
                hex::encode(current_intermediate_bytes),
                std::str::from_utf8(&current_decrypted_block).unwrap()
            );
        }
        info!(
            "*** Finished ***
        [+] Decrypted value (ASCII): {}
        [+] Decrypted value (HEX): {}
        [+] Decrypted value (Base64): {}",
            std::str::from_utf8(&decrypted).unwrap(),
            hex::encode(&decrypted),
            base64::encode(&decrypted)
        );
        Ok(decrypted)
    }
pub fn decrypt ( & self , ciphertext : & [ u8 ] , iv : & [ u8 ] ) -> Result < Vec < u8 > , PadbusterError > { info ! ( " " ) ; info ! ( " " ciphertext ) ; if ciphertext . len ( ) % ( self . block_size as usize ) != 0 { return Err ( PadbusterError :: ValidationError ( " " , ) ) ; } if iv . is_empty ( ) && ciphertext . len ( ) < ( self . block_size as usize ) * 2 { return Err ( PadbusterError :: ValidationError ( " " , ) ) ; } let mut used_iv = iv . to_owned ( ) ; let mut ctext = ciphertext . to_owned ( ) ; if iv . is_empty ( ) { used_iv = ciphertext [ .. ( self . block_size as usize ) ] . to_vec ( ) ; ctext = ciphertext [ ( self . block_size as usize ) .. ] . to_vec ( ) ; } let mut decrypted = vec ! [ 0u8 ctext len ( ) ] ; let mut n = 0 ; while ! ctext . is_empty ( ) { info ! ( " \n " n self block_size ) ; let mut block = ctext [ 0 .. ( self . block_size as usize ) ] . to_vec ( ) ; ctext = ctext [ ( self . block_size as usize ) .. ] . to_vec ( ) ; let next_iv = block . clone ( ) ; let current_block = block . clone ( ) ; let intermediate_bytes = match self . bust ( & mut block ) { Err ( e ) => return Err ( e ) , Ok ( r ) => r , } ; let current_intermediate_bytes = intermediate_bytes . clone ( ) ; let mut decrypted_block = xor_data ( intermediate_bytes , used_iv ) ; let current_decrypted_block = decrypted_block . clone ( ) ; decrypted . append ( & mut decrypted_block ) ; used_iv = next_iv ; n += self . block_size ; info ! ( " " n self block_size hex encode ( current_block ) hex encode ( current_intermediate_bytes ) std str from_utf8 ( current_decrypted_block ) unwrap ( ) ) ; } info ! ( " " std str from_utf8 ( decrypted ) unwrap ( ) hex encode ( decrypted ) base64 encode ( decrypted ) ) ; Ok ( decrypted ) }
Decrypt the given ciphertext & iv using oracle
Decrypt the given ciphertext & iv using oracle
&self
ciphertext
&[u8]
iv
&[u8]
&self
ciphertext
&[u8]
iv
&[u8]