<s> from ssl import RAND_bytes <EOL> from prob10 import aes_cbc_enc , aes_ecb_enc <EOL> from prob8 import chunks <EOL> from prob9 import addPKCS7Padding <EOL> def generateAESKey ( ) : <EOL> return RAND_bytes ( <NUM_LIT:16> ) ; <EOL> def getOneRandomByte ( ) : <EOL> byte = RAND_bytes ( <NUM_LIT:1> ) ; <EOL> return byte [ <NUM_LIT:0> ] ; <EOL> def encryption_oracle ( rawInput ) : <EOL> key = generateAESKey ( ) ; <EOL> iv = generateAESKey ( ) ; <EOL> prependAmount = <NUM_LIT:5> + ( getOneRandomByte ( ) % <NUM_LIT:6> ) ; <EOL> appendAmount = <NUM_LIT:5> + ( getOneRandomByte ( ) % <NUM_LIT:6> ) ; <EOL> plaintext = ( b'<STR_LIT:x>' * prependAmount ) + rawInput + ( b'<STR_LIT:y>' * appendAmount ) ; <EOL> if ( ( getOneRandomByte ( ) & <NUM_LIT> ) ) : <EOL> return aes_ecb_enc ( addPKCS7Padding ( plaintext , <NUM_LIT:16> ) , key ) ; <EOL> else : <EOL> return aes_cbc_enc ( addPKCS7Padding ( plaintext , <NUM_LIT:16> ) , key , iv ) ; <EOL> def detectMode ( ) : <EOL> plaintext = b'<STR_LIT:A>' * <NUM_LIT> ; <EOL> cipher = encryption_oracle ( plaintext ) ; <EOL> blocks = chunks ( cipher , <NUM_LIT:16> ) ; <EOL> if ( blocks [ <NUM_LIT:1> ] == blocks [ <NUM_LIT:2> ] ) : <EOL> print ( "<STR_LIT>" ) ; <EOL> else : <EOL> print ( "<STR_LIT>" ) ; <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> detectMode ( ) ; </s>
