Beispiel #1
0
def crack(top_letter, en_top_letter, encrypted_hex):
    decoding_key = ''
    p_key = crack_key(en_top_letter, top_letter)
    bin_key = hex_to_binary(p_key)
    # print('key: {}'.format(hex_to_ascii(p_key)))
    # print('key bin: {}'.format(bin_key))

    hex_clear_text = ''
    for i in range(0, len(encrypted_hex), 2):
        enc_hex = encrypted_hex[i:i + 2]
        hex_clear_text += binary_to_hex(
            inverse_bitwise_xor(bin_key, hex_to_binary(enc_hex)))

    return hex_clear_text, p_key
Beispiel #2
0
def crack_repeating_key_xor(raw_bin_enc):
    min_key_size = 2
    max_key_size = 100
    distances = {}
    for i in range(min_key_size, max_key_size, 1):
        distances[str(i)] = norm_avg_hamm_dist(raw_bin_enc, i)

    distances = sorted(distances.iteritems(), key=lambda (k, v): (v, k))
    # print(distances)
    hex_enc = binary_to_hex(raw_bin_enc)
    for dis in distances[:4]:
        key_size = int(dis[0])
        # print('Trying key_size = {}'.format(key_size))
        blocks = get_blocks(hex_enc, key_size)
        #print(blocks)
        final_key, final_ct = solve_blocks(blocks)
        if final_key and final_ct:
            # print('final_key', final_key)
            # print('final_ct', final_ct)
            return final_key, final_ct

    return None, None
Beispiel #3
0
def base64_to_hex(bs64_str):
    return binary_to_hex(base64_to_binary(bs64_str))
Beispiel #4
0
def crack_key(top_letter, en_top_letter):
    bin_top_l = hex_to_binary(top_letter)
    bin_top_en = hex_to_binary(en_top_letter)
    bin_key = inverse_bitwise_xor(bin_top_en, bin_top_l)
    return binary_to_hex(bin_key)
Beispiel #5
0
def ascii_letter_to_hex(l):
    return binary_to_hex(decimal_to_binary(ASCII.find(l), 8))