Example #1
0
def encryption_oracle(msg):
    # Append 5-10 bytes randomly before and 5-10 bytes after
    # 0.5 ecb 0.5 cbc
    ecb = randrange(2) == 1
    msg = bytes(random_aes_key()[0:randrange(10)] + msg + bytes(random_aes_key()[0:randrange(10)]))
    if ecb:
        return encrypt_aes_ecb(random_aes_key(), pad_pkcs7(msg, 16)), Mode.ECB
    else:
        return encrypt_aes_cbc(random_aes_key(), msg, 16, random_aes_key()), Mode.CBC
def encryption_oracle(msg):
    secret = base64.decodebytes(
        bytes(
            b'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg' +
            b'aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq'
            b'dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK'
        ))
    msg = random_prefix + msg + secret
    return encrypt_aes_ecb(key, pad_pkcs7(msg, 16))
Example #3
0
def encrypt_aes_cbc(key, msg, block_size, iv):
    msg = pad_pkcs7(msg, block_size)
    ct_prev, ct, i = iv, [], 0
    while i < len(msg) / block_size:
        ct_block = encrypt_aes_ecb(
            key, xor(ct_prev, msg[i * block_size:(i + 1) * block_size]))
        ct.append(ct_block)
        ct_prev = ct_block
        i += 1
    return b''.join(ct)
Example #4
0
def encrypt(key, profile):
    return encrypt_aes_ecb(key, pad_pkcs7(bytes(profile, 'utf-8'), 16))