Esempio n. 1
0
def fixed_xor(hex_value_1, hex_value_2):
    byte_array_1 = hex_to_byte_array(hex_value_1)
    byte_array_2 = hex_to_byte_array(hex_value_2)

    xor_byte_array = [byte_1 ^ byte_2 for (byte_1, byte_2) in zip(byte_array_1, byte_array_2)]

    return byte_array_to_hex(xor_byte_array)
Esempio n. 2
0
def break_single_byte_xor_cipher(hexed):
    text = hex_to_byte_array(hexed)
    possible_keys = range(256)
    scores = { candidate: score(decrypt_single_byte_xor_cipher(candidate, text))
               for candidate in possible_keys }

    key = max(scores, key=scores.get)
    return decrypt_single_byte_xor_cipher(key, text)