Пример #1
0
def hammingDistance(hex1, hex2):
    diff = hex_xor(hex1, hex2)
    #print(diff);
    result = 0
    for c in diff:
        result += hexBitCount[chr(c)]
    return result
def hammingDistance(hex1, hex2):
    diff = hex_xor(hex1, hex2);
    #print(diff);
    result = 0;
    for c in diff:
        result += hexBitCount[chr(c)];
    return result;
Пример #3
0
def aes_cbc_dec(rawCipher, rawKey, rawIV):
    cipherBlocks = chunks(rawCipher, 16)
    plain = b""
    for block in cipherBlocks:
        ecbOut = aes_ecb_dec(block, rawKey)
        cbcOut = hexToRaw(hex_xor(rawToHex(ecbOut), rawToHex(rawIV)))
        rawIV = block
        plain += cbcOut
    return plain
Пример #4
0
def aes_cbc_enc(rawPlain, rawKey, rawIV):
    plainBlocks = chunks(rawPlain, 16)
    cipher = b""
    for block in plainBlocks:
        blockIn = hexToRaw(hex_xor(rawToHex(block), rawToHex(rawIV)))
        blockOut = aes_ecb_enc(blockIn, rawKey)
        rawIV = blockOut
        cipher += blockOut
    return cipher
Пример #5
0
def aes_cbc_dec(rawCipher, rawKey, rawIV):
    cipherBlocks = chunks(rawCipher, 16)
    plain = b''
    for block in cipherBlocks:
        ecbOut = aes_ecb_dec(block, rawKey)
        cbcOut = hexToRaw(hex_xor(rawToHex(ecbOut), rawToHex(rawIV)))
        rawIV = block
        plain += cbcOut
    return plain
Пример #6
0
def aes_cbc_enc(rawPlain, rawKey, rawIV):
    plainBlocks = chunks(rawPlain, 16)
    cipher = b''
    for block in plainBlocks:
        blockIn = hexToRaw(hex_xor(rawToHex(block), rawToHex(rawIV)))
        blockOut = aes_ecb_enc(blockIn, rawKey)
        rawIV = blockOut
        cipher += blockOut
    return cipher
Пример #7
0
def aes_cbc_dec(rawCipher, rawKey, rawIV):
    cipherBlocks = chunks(rawCipher, 16);
    plain = b'';
    for block in cipherBlocks:
        ecbOut = aes_ecb_dec(block, rawKey);
        cbcOut = hexToRaw(hex_xor(rawToHex(ecbOut), rawToHex(rawIV)));
        rawIV = block;
        plain += cbcOut;
    return plain;
Пример #8
0
def aes_cbc_enc(rawPlain, rawKey, rawIV):
    plainBlocks = chunks(rawPlain, 16);
    cipher = b'';
    for block in plainBlocks:
        blockIn = hexToRaw(hex_xor(rawToHex(block), rawToHex(rawIV)));
        blockOut = aes_ecb_enc(blockIn, rawKey);
        rawIV = blockOut;
        cipher += blockOut;
    return cipher;
Пример #9
0
def repeating_hex_xor(hex1, hex2):
    if (len(hex1) < len(hex2)):
        shorter = hex1
        longer = hex2
    else:
        shorter = hex2
        longer = hex1
    shorter *= int(1 + (len(longer) / len(shorter)))
    shorter = shorter[:len(longer)]
    return hex_xor(shorter, longer)
Пример #10
0
def repeating_hex_xor(hex1, hex2):
    if (len(hex1) < len(hex2)):
        shorter = hex1
        longer = hex2;
    else:
        shorter = hex2;
        longer = hex1;
    shorter *= int(1 + (len(longer)/len(shorter)));
    shorter = shorter[:len(longer)];
    return hex_xor(shorter, longer);
Пример #11
0
def generateEncryptedAdminProfile():
    # get to a fresh block
    s = 'A' * (16 - (len(prefix) % 16));
    #locate the IV for my block
    myIVBlock = ((len(prefix) + len(s)) // 16) - 1;
    # add a known block value
    s += 'X' * 16;
    # encrypt
    cip = padAndEncryptString(s);
    # extract IV for block of interest
    allBlocks = chunks(cip, 16);
    myIV = allBlocks[myIVBlock];
    # xor in IV with desired value
    hexIV = rawToHex(myIV);
    hexKnown = rawToHex('X'*16);
    hexDesired = rawToHex(";admin=true;XXXX")
    newHexIV = hex_xor(hexIV, hex_xor(hexKnown, hexDesired));
    newIV = hexToRaw(newHexIV);
    # insert "error"
    allBlocks[myIVBlock] = newIV;
    myCipher = b'';
    for b in allBlocks:
        myCipher += b;
    return myCipher;
Пример #12
0
def tryKey(cipher, key):
    fullkey = key * len(cipher);
    fullkey = fullkey[:len(cipher)];
    potential_plain = hex_xor(cipher, fullkey);
    return calculateMG(hexToRaw(potential_plain)), potential_plain;
Пример #13
0
def tryKey(cipher, key):
    fullkey = key * len(cipher)
    fullkey = fullkey[:len(cipher)]
    potential_plain = hex_xor(cipher, fullkey)
    return calculateMG(hexToRaw(potential_plain)), potential_plain