예제 #1
0
def f(x):
    if type(x) == str:
        x = bytearray(x, 'utf-8')
    unknown_str_b64 = "Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK"
    unknown_str = b64_to_bytes(unknown_str_b64)
    new_pt = pkcs7_pad(x + unknown_str, BLK_SZ)
    return encrypt_aes_ecb(new_pt, KEY)
예제 #2
0
def aes_cbc_encrypt(pt, key, iv):
    # pad if needed
    pt_padded = pkcs7_pad(pt, BLK_SZ)
    pt_chunks = chunk(pt_padded, BLK_SZ)

    prev_blk = iv
    ct_blks = []
    for pt_blk in pt_chunks:
        # xor with prev blk
        pt_xored = xor(prev_blk, pt_blk)

        # ECB encrypt
        ct_blk = encrypt_aes_ecb(pt_xored, key)
        ct_blks.append(ct_blk)

        # store as prev blk
        prev_blk = ct_blk

    ct_s = functools.reduce(lambda a, b: a + b, ct_blks)

    return ct_s
예제 #3
0
def encryption_oracle(x):
    if type(x) == str:
        x = bytearray(x, "utf-8")
    bytes_append_len = 5 + secrets.randbelow(6)
    bytes_prepend_len = 5 + secrets.randbelow(6)

    bytes_appended = bytearray(secrets.token_bytes(bytes_append_len))
    bytes_prepended = bytearray(secrets.token_bytes(bytes_prepend_len))

    pt = pkcs7_pad(bytes_prepended + x + bytes_appended, 16)

    encryption_scheme = secrets.randbelow(2)

    if (encryption_scheme == ECB_MODE):
        # do ECB
        ct = encrypt_aes_ecb(pt, gen_aes_key())
    elif (encryption_scheme == CBC_MODE):
        # do CBC
        ct = aes_cbc_encrypt(pt, gen_aes_key(), secrets.token_bytes(BLK_SZ))

    return ct, encryption_scheme
예제 #4
0
def profile_for(x):
    x = x.replace("&", "")
    x = x.replace("=", "")
    d = {'email': x, 'uid': 10, 'role': 'user'}

    return encrypt_aes_ecb(pkcs7_pad(obj_to_qs(d), BLK_SZ), KEY)