def test_position_of_bits_changed_M():
    aes = AES.AES(key)
    c = aes.encrypt_block(message)
    modifiedbits = [0] * 128
    sum = 0
    for i in range(128):
        modifiedMessage = int_to_bytes(bytes_to_int(message) ^ (1 << i), 16)
        ci = aes.encrypt_block(modifiedMessage)
        for j in range(128):
            bitc = (bytes_to_int(c) >> j) % 2
            bitci = (bytes_to_int(ci) >> j) % 2
            if (bitc != bitci):
                modifiedbits[j] += 1
                sum += 1
    print(modifiedbits)
    print("mean = ", sum / 128)
def test_number_bits_changed_M():
    aes = AES.AES(key)
    ciphertext = aes.encrypt_block(message)
    modifiedbits = [0] * 128
    for i in range(128):
        modifiedMessage = int_to_bytes(bytes_to_int(message) ^ (1 << i), 16)
        ci = aes.encrypt_block(modifiedMessage)
        modifiedbits[count_modified_bits(ciphertext, ci)] += 1
    print(modifiedbits)
def test_no_MixColumns():
    aes = AESMixColumns.AES(key)
    ciphertext = aes.encrypt_block(message)
    for i in range(4):
        ci = aes.encrypt_block(
            int_to_bytes(bytes_to_int(message) ^ (1 << i * 32), 16))
        print("Original ciphertext:")
        print_block(ciphertext)
        print("1 bit modified:")
        print_block(ci)
        print()
Example #4
0
def decryptSet(preMasterKeys, coreNum):
    print("set", coreNum, "contains", len(preMasterKeys), "preMasterKeys")
    cipher = open("2019_09_25_17_02_22_joan.marc.pastor.puerta_trasera.enc",
                  'rb').read()
    for preKey in preMasterKeys:
        preKeyInBytes = int_to_bytes(preKey, 16)
        hashkey = bytes_to_int(hashlib.sha256(preKeyInBytes).digest())
        KEY = int_to_bytes(hashkey >> 128, 16)
        IV = int_to_bytes(hashkey & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
                          16)  # 32x F
        aes = AES.new(KEY, AES.MODE_CBC, IV)
        paddedMessage = aes.decrypt(cipher)
        try:
            message = unpad(paddedMessage, AES.block_size,
                            style='pkcs7')  #Rises error if wrong format
            print("possible preMasterKey: ", hex(preKey))
            open('out/' + hex(preKey).replace("0x", "") + '.mp4',
                 'wb').write(message)
        except:
            pass
    print("Core", coreNum, "finished")
def test_no_ByteSub():
    aes = AESByteSub.AES(key)
    ciphertext = aes.encrypt_block(message)
    compleixPropietat = True
    for i in range(128):
        for j in range(128):
            ci = aes.encrypt_block(
                int_to_bytes(bytes_to_int(message) ^ (1 << i), 16))
            cj = aes.encrypt_block(
                int_to_bytes(bytes_to_int(message) ^ (1 << j), 16))
            cij = aes.encrypt_block(
                int_to_bytes(
                    bytes_to_int(message) ^ ((1 << i) ^ (1 << j)), 16))
            if (bytes_to_int(ciphertext) !=
                    bytes_to_int(ci) ^ bytes_to_int(cj) ^ bytes_to_int(cij)):
                compleixPropietat = False
    if (compleixPropietat):
        print("La propietat C = Ci XOR Cj XOR Cij per a tot i, j es compleix.")
    else:
        print(
            "La propietat  C = Ci XOR Cj XOR Cij per a tot i, j no es compleix."
        )
Example #6
0
import aes as AES
from helpers import bytes_to_int, int_to_bytes

key = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
cipher = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

aes = AES.AES(key)
message = aes.decrypt_block(cipher)
print(hex(bytes_to_int(message)))