예제 #1
0
def startsearch(tool_parameters):
    """
    Starts the search tool for the given parameters
    """

    cipher_suite = {
        "craft": craft.CraftCipher(),
        "craftrtk": craftrtk.CraftCipherRTK(),
        "craftrtk1": craftrtk1.CraftCipherRTK1(),
        "craftrtk2": craftrtk2.CraftCipherRTK2(),
        "craftrtk3": craftrtk3.CraftCipherRTK3(),
        "craftlinear": craftlinear.CraftCipherLinear(),
        "ein_even": ein_even.EinEven(),
        "em_even": em_even.EmEven(),
        "eout_even": eout_even.EoutEven(),
        "ein_odd": ein_odd.EinOdd(),
        "em_odd": em_odd.EmOdd(),
        "eout_odd": eout_odd.EoutOdd(),
        "ein_even_6r": ein_even_6r.EinEven6r()
    }

    cipher = None

    if tool_parameters["cipher"] in cipher_suite:
        cipher = cipher_suite[tool_parameters["cipher"]]
    else:
        print("Cipher not supported!")
        return

    # Handle program flow
    if tool_parameters["mode"] == 0:
        search.findMinWeightCharacteristic(cipher, tool_parameters)
    elif tool_parameters["mode"] == 1:
        search.searchCharacteristics(cipher, tool_parameters)
    elif tool_parameters["mode"] == 2:
        search.findAllCharacteristics(cipher, tool_parameters)
    elif tool_parameters["mode"] == 3:
        search.findBestConstants(cipher, tool_parameters)
    elif tool_parameters["mode"] == 4:
        search.computeProbabilityOfDifferentials(cipher, tool_parameters)

    return
예제 #2
0
def startsearch(tool_parameters):
    """
    Starts the search tool for the given parameters
    """

    cipher_suite = {
        "craft": craft.CraftCipher(),
        "craftrtk": craftrtk.CraftCipherRTK(),
        "craftrtk1": craftrtk1.CraftCipherRTK1(),
        "craftrtk2": craftrtk2.CraftCipherRTK2(),
        "craftrtk3": craftrtk3.CraftCipherRTK3(),
        "craftlinear": craftlinear.CraftCipherLinear(),
        "ein_even": ein_even.EinEven(),
        "em_even": em_even.EmEven(),
        "eout_even": eout_even.EoutEven(),
        "ein_odd": ein_odd.EinOdd(),
        "em_odd": em_odd.EmOdd(),
        "eout_odd": eout_odd.EoutOdd(),
        "ein_even_6r": ein_even_6r.EinEven6r()
    }

    cipher = None

    if tool_parameters["cipher"] in cipher_suite:
        cipher = cipher_suite[tool_parameters["cipher"]]
    else:
        print("Cipher not supported!")
        return

    # Handle program flow
    if tool_parameters["mode"] == 0:
        search1.findMinWeightCharacteristic(cipher, tool_parameters)
    elif tool_parameters["mode"] == 1:
        search1.searchCharacteristics(cipher, tool_parameters)
    elif tool_parameters["mode"] == 2:
        search1.findAllCharacteristics(cipher, tool_parameters)
    elif tool_parameters["mode"] == 3:
        search1.findBestConstants(cipher, tool_parameters)
    elif tool_parameters["mode"] == 4:
        fileobj = open("odd_possible_ios.txt", 'r')
        possible_inputs = fileobj.readlines()
        fileobj.close()
        fileobj = open("result_eout_odd_5r.txt", "w")
        distribution = [0] * len(possible_inputs)
        tool_parameters_backup = tool_parameters.copy()
        number_of_possible_trails = 0

        stweight = int(tool_parameters["sweight"])
        endweight = int(tool_parameters["endweight"])
        ntrails = [[0] for i in range(len(possible_inputs))]

        for i in range(len(possible_inputs)):
            tool_parameters = tool_parameters_backup.copy()
            tool_parameters["fixedVariables"]["z0"] = possible_inputs[i][0:-1]
            input_disp = "Input[%d]: %s" % (i, possible_inputs[i][0:-1])
            print(input_disp)
            fileobj.write(input_disp)
            fileobj.write("\n")
            pr, ntrails[i] = search1.computeProbabilityOfDifferentials(
                cipher, tool_parameters)
            distribution[i] = pr
            if pr > 0.0:
                prob_disp = "Probability: 2^(" + str(math.log(pr, 2)) + ")"
                print(prob_disp)
                fileobj.write(prob_disp)
                fileobj.write("\n")
                number_of_possible_trails += 1
            else:
                print("Probability: 0")
                fileobj.write("Probability: 0\n")
            trails = "#Trails: %s" % ntrails[i]
            print(trails)
            fileobj.write(trails)
            fileobj.write("\n\n")
    fileobj.write("Distribution : %s\n" % distribution)

    for w in range(stweight, endweight):
        fileobj.write("#Trails of weigth %d: [" % w)
        temp = [0] * (len(possible_inputs))
        for t in range(len(possible_inputs)):
            temp[t] = str(ntrails[t][w])
        fileobj.write(", ".join(temp))
        fileobj.write("]\n")

    fileobj.write("\nNumber of possible trails : %d out of %d" %
                  (number_of_possible_trails, 100))
    fileobj.close()
    return