예제 #1
0
파일: 17.py 프로젝트: drseilzug/cryptopals
def oracle(ciphertext):
    try:
        aes.cbc_decrypt(ciphertext, key)
    except tools.PaddingError:
        return False
    else:
        return True
예제 #2
0
def is_admin(token):
    cookie = cbc_decrypt(KEY, IV, token).decode('latin-1')
    fields = cookie.split(';')
    items = [(key, unescape(value))
             for key, value in (field.split('=', maxsplit=1)
                                for field in fields if "=" in field)]
    return any([item == ('admin', 'true') for item in items])
예제 #3
0
파일: 17.py 프로젝트: drseilzug/cryptopals
def decrypt(cipertext, iv):
    return aes.cbc_decrypt(cipertext, key, iv)
예제 #4
0
def padding_oracle(iv, ciphertext):
    try:
        cbc_decrypt(KEY, iv, ciphertext)
        return True
    except BadPaddingException:
        return False
예제 #5
0
def padding_oracle(iv, ciphertext):
    try:
        cbc_decrypt(KEY, iv, ciphertext)
        return True
    except BadPaddingException:
        return False
예제 #6
0
파일: 16.py 프로젝트: drseilzug/cryptopals
def is_admin(ciphertext):
    plaintext = aes.cbc_decrypt(ciphertext, key, iv)
    return b';admin=true;' in plaintext
예제 #7
0
def test_cbc_decrypt():
    msg = bytes.fromhex("62cc02dafc6482edf9f2adca6abbb3d2")
    key = bytes.fromhex("000102030405060708090a0b0c0d0e0f")
    iv = bytes.fromhex("00112233445566778899aabbccddeeff")
    decrypted = aes.cbc_decrypt(msg, key, iv).hex()
    assert decrypted == "00112233445566778899aabbccddee"
예제 #8
0
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))