@@ -0,0 +1,1314 @@
+from crypto_library import cbc_aes_encrypt, ecb_aes, BLOCKSIZE%0Afrom string import printable%0Aimport random%0A%0A%0Adef generate_random_string(length):%0A    return ''.join(random.choice(printable) for _ in range(length))%0A%0A%0Adef cbc_encryption(plaintext, key):%0A    iv = generate_random_string(BLOCKSIZE)%0A    return cbc_aes_encrypt(plaintext, iv, key)%0A%0A%0Adef ecb_encryption(plaintext, key):%0A    return ecb_aes(plaintext, key)%0A%0A%0Adef encryption_oracle(plaintext):%0A    encryption_schemes = %5Bcbc_encryption, ecb_encryption%5D%0A%0A    key = generate_random_string(16)%0A%0A    padding_before = generate_random_string(random.randrange(5, 11))%0A    padding_after = generate_random_string(random.randrange(5, 11))%0A%0A    ciphertext = encryption_schemes%5Brandom.randrange(0, 2)%5D(''.join((padding_before, plaintext, padding_after)), key)%0A%0A    return ciphertext%0A%0A%0Adef distinguish_encryption_mode(ciphertext):%0A    blocks = %5Bciphertext%5Bi*BLOCKSIZE:(i+1)*BLOCKSIZE%5D for i in range(len(ciphertext)/BLOCKSIZE)%5D%0A    if len(blocks) %3C 4:%0A        return 'Insufficient input'%0A    if blocks%5B1%5D == blocks%5B2%5D:%0A        return 'ecb'%0A    return 'cbc'%0A%0A%0Adef main():%0A    plaintext = '0'*100%0A%0A    ciphertext = encryption_oracle(plaintext)%0A    adversary_output = distinguish_encryption_mode(ciphertext)%0A%0A    print adversary_output%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add problem 11