Exemplo n.º 1
0
def reduce_basis(p1,p2):
	mat_basis = liblll.create_matrix([[p1[0],p2[0]],[p1[1],p2[1]]]) 
	mat_reduced = liblll.lll_reduction(mat_basis)	
	a0 = mat_reduced[0][0].numerator # lll library creates fractions with denominator 1, so grab numerator
	a1 = mat_reduced[0][1].numerator
	b0 = mat_reduced[1][0].numerator
	b1 = mat_reduced[1][1].numerator
	return [[a0,b0],[a1,b1]]
Exemplo n.º 2
0
def reduce_basis(p1, p2):
    mat_basis = liblll.create_matrix([[p1[0], p2[0]], [p1[1], p2[1]]])
    mat_reduced = liblll.lll_reduction(mat_basis)
    a0 = mat_reduced[0][
        0].numerator  # lll library creates fractions with denominator 1, so grab numerator
    a1 = mat_reduced[0][1].numerator
    b0 = mat_reduced[1][0].numerator
    b1 = mat_reduced[1][1].numerator
    return [[a0, b0], [a1, b1]]
def attack_by_lll(msg_cipher, public_key_vector):

    text_clear = ""
    for i in range(0, len(msg_cipher)):
        element_message_cipher = msg_cipher[i]
        base_vector_list = attacking.create_base_vector_list(public_key_vector,element_message_cipher)  
        matrix_to_lll_reduction = liblll.create_matrix(base_vector_list)   
        reduced_matrix = liblll.lll_reduction(matrix_to_lll_reduction)
        deciphered_bit_sequence = attacking.get_first_column_as_bit_sequence(reduced_matrix)       
        bit_to_text = utility.convert_bit_to_text(deciphered_bit_sequence, len(public_key_vector))
        text_clear += bit_to_text
    print("clear-text/cracked-text : => " +str(text_clear))
    write_in_file("text_clear.txt",text_clear)
    return True
Exemplo n.º 4
0
def decipher_as_attacker(ciphered_vector, public_key_vector):
    t = time.process_time()
    print("\nAs an " + constants.bold_attribute + "ATTACKER" + constants.attribute_default +
          ", you own the ciphered vector, public key vector. \n" +
          constants.foreground_colorant_green +
          "So, you can decipher the cipher text with using lattice reduction." + constants.attribute_default + "\n")

    print("Deciphering part is about to start...\n")
    deciphered_text = ""
    print("LLL basis lattice reduction algorithm is about to start...\n")
    for i in range(0, len(ciphered_vector)):
        ciphered_message = ciphered_vector[i]
        base_vector_list = attacking.create_base_vector_list(public_key_vector, ciphered_message)
        if utility.log_enabled:
            print("base_vector_list: " + str(base_vector_list) + "\n")

        matrix_to_lll_reduction = liblll.create_matrix(base_vector_list)
        if utility.log_enabled:
            print("matrix_to_lll_reduction:\n")
            liblll.print_mat(matrix_to_lll_reduction)
            print("\n")
        reduced_matrix = liblll.lll_reduction(matrix_to_lll_reduction)
        if utility.log_enabled:
            print("reduced_matrix:\n")
            liblll.print_mat(reduced_matrix)
            print("\n")

        deciphered_bit_sequence = attacking.get_first_column_as_bit_sequence(reduced_matrix)

        if utility.log_enabled:
            print("deciphered_bit_sequence:\n")
            liblll.print_mat(deciphered_bit_sequence)
            print("\n")
        bit_to_text = utility.convert_bit_to_text(deciphered_bit_sequence, len(public_key_vector))
        deciphered_text += bit_to_text

    print("Lattice reduction algorithm is over.\n")
    print("Finished to decipher the text in " + str(time.process_time()-t) + " ms as an attacker.\n\n" +
          "Original text: " +
          str(deciphered_text))

    return True