pub fn prefix_length<T: DeterministicOracle>(oracle: &T) -> Result<usize> {
    let offset = full_prefix_blocks_count(oracle)? * BLOCK_SIZE;
    let helper = |k: u8| -> Result<usize> {
        let constant_block = vec![k; BLOCK_SIZE];
        let initial = &oracle.encrypt(&constant_block)?[offset..(offset + BLOCK_SIZE)];
        for i in 0..BLOCK_SIZE {
            let cur = oracle.encrypt(&constant_block[i + 1..])?;
            if cur.len() < offset + BLOCK_SIZE || initial != &cur[offset..(offset + BLOCK_SIZE)] {
                return Ok(i);
            }
        }
        Ok(BLOCK_SIZE)
    };

    Ok(offset + std::cmp::min(helper(0)?, helper(1)?))
}
// We look at the first block C not fully occupied by the prefix and fill it with a
// constant block B, say consisting of 0's.
// This part of the cleartext in oracle looks as follows:
//
//                               <------ B ------->
// prefix[?] prefix[?] prefix[?] 0 0 ... 0 || 0 0 0 suffix[0] suffix[1]
// <---------- C ------------------------>
//
// We then successively reduce the length of B until the ciphertext of C
// changes. This happens as soon as the cleartext in oracle looks as follows:
//
//                               <-- B -->
// prefix[?] prefix[?] prefix[?] 0 0 ... 0 suffix[0] || suffix[1]
// <---------- C ---------------------------------->
//
// This gives us the length of the prefix in C.
//
// We need to do this with two different constants because suffix[0] might accidentally
// coincide with the constant we have chosen.
We look at the first block C not fully occupied by the prefix and fill it with a
constant block B, say consisting of 0's.
This part of the cleartext in oracle looks as follows.



We then successively reduce the length of B until the ciphertext of C
changes. This happens as soon as the cleartext in oracle looks as follows.



This gives us the length of the prefix in C.

We need to do this with two different constants because suffix[0] might accidentally
coincide with the constant we have chosen.
We look at the first block C not fully occupied by the prefix and fill it with a constant block B say consisting of 0 ' s . This part of the cleartext in oracle looks as follows . We then successively reduce the length of B until the ciphertext of C changes . This happens as soon as the cleartext in oracle looks as follows . This gives us the length of the prefix in C . We need to do this with two different constants because suffix [ 0 ] might accidentally coincide with the constant we have chosen .
pub fn prefix_length<T: DeterministicOracle>(oracle: &T) -> Result<usize> {
    let offset = full_prefix_blocks_count(oracle)? * BLOCK_SIZE;
    let helper = |k: u8| -> Result<usize> {
        let constant_block = vec![k; BLOCK_SIZE];
        let initial = &oracle.encrypt(&constant_block)?[offset..(offset + BLOCK_SIZE)];
        for i in 0..BLOCK_SIZE {
            let cur = oracle.encrypt(&constant_block[i + 1..])?;
            if cur.len() < offset + BLOCK_SIZE || initial != &cur[offset..(offset + BLOCK_SIZE)] {
                return Ok(i);
            }
        }
        Ok(BLOCK_SIZE)
    };
    Ok(offset + std::cmp::min(helper(0)?, helper(1)?))
}
pub fn prefix_length < T : DeterministicOracle > ( oracle : & T ) -> Result < usize > { let offset = full_prefix_blocks_count ( oracle ) ? * BLOCK_SIZE ; let helper = | k : u8 | -> Result < usize > { let constant_block = vec ! [ k BLOCK_SIZE ] ; let initial = & oracle . encrypt ( & constant_block ) ? [ offset .. ( offset + BLOCK_SIZE ) ] ; for i in 0 .. BLOCK_SIZE { let cur = oracle . encrypt ( & constant_block [ i + 1 .. ] ) ? ; if cur . len ( ) < offset + BLOCK_SIZE || initial != & cur [ offset .. ( offset + BLOCK_SIZE ) ] { return Ok ( i ) ; } } Ok ( BLOCK_SIZE ) } ; Ok ( offset + std :: cmp :: min ( helper ( 0 ) ? , helper ( 1 ) ? ) ) }
We look at the first block C not fully occupied by the prefix and fill it with a
constant block B, say consisting of 0's.
We look at the first block C not fully occupied by the prefix and fill it with a constant block B say consisting of 0 ' s .
oracle
&T
oracle
&T