Esempio n. 1
0
def rand_encrypt(key, secret):
    block_size = 16

    secret = pad(pad_rand(secret), block_size)

    if randint(0, 1):
        return encrypt_ECB(key, secret)
    else:
        return encrypt_CBC(key, secret)
Esempio n. 2
0
def encrypt_CBC(key, text):
    block_size = 16
    
    text_blocks = generate_blocks(pad(text), block_size)
    initialisation_vector = b'\x00' * block_size

    cipher_blocks = [initialisation_vector]
    for i in range(len(text_blocks)):
        xor = fixed_xor(cipher_blocks[i], text_blocks[i])
        cipher_blocks.append(encrypt_ECB(key, xor, add_padding=False))

    return "".join(cipher_blocks[1:])
Esempio n. 3
0
def get_encryption_oracle(unknown_string):
    unknown_key = rand_key()
    return lambda s: encrypt_ECB(unknown_key, s + unknown_string)