def test_ecb_encrypt(enc_tests): for test in enc_tests: ctx = aes.build_encryption_context(bytes.fromhex(test.key)) buffer = bytes.fromhex(test.plaintext) aes.ecb_encrypt(buffer, ctx) if buffer.hex() == test.ciphertext: print("Encryption test {} ... PASS".format(test.count)) else: print("Encryption test {} ... FAIL".format(test.count))
def encryption_oracle(input_): key = urandom(16) iv = urandom(16) prefix = random.randint(5, 10) suffix = random.randint(5, 10) plaintext = urandom(prefix) + input_ + urandom(suffix) use_cbc = random.choice([True, False]) encrypted = (cbc_encrypt(key, iv, plaintext) if use_cbc else ecb_encrypt( key, plaintext)) answer = "CBC" if use_cbc else "ECB" return (encrypted, answer)
def encryption_oracle(input_): key = urandom(16) iv = urandom(16) prefix = random.randint(5, 10) suffix = random.randint(5, 10) plaintext = urandom(prefix) + input_ + urandom(suffix) use_cbc = random.choice([True, False]) encrypted = (cbc_encrypt(key, iv, plaintext) if use_cbc else ecb_encrypt(key, plaintext)) answer = "CBC" if use_cbc else "ECB" return (encrypted, answer)
def oracle(input_): return ecb_encrypt(KEY, PREFIX + input_ + SECRET)
def oracle(email): return ecb_encrypt(key, profile_for(email).encode('ascii'))
def oracle(input_): return ecb_encrypt(key, input_ + secret)
from aes import ecb_encrypt, ecb_decrypt, cbc_encrypt, cbc_decrypt from base64 import b64decode key = "YELLOW SUBMARINE" test_block = bytes([0x40] * 16) assert (test_block == ecb_decrypt(key, ecb_encrypt(key, test_block))) with open("10.txt") as f: ciphertext = b64decode(''.join([line.strip() for line in f.readlines()])) iv = bytes([0x00] * 16) decrypted = cbc_decrypt(key, iv, ciphertext) print(decrypted.decode('ascii')) assert (ciphertext == cbc_encrypt(key, iv, decrypted))