Example #1
0
def compute(varsNum):
    count = 0
    lst1 = [1, 3, 6, 7, 9, 16, 17, 18, 19, 22, 25, 26, 27, 29, 31, 32, 35, 37, 38, 40, 41, 42, 46, 49, 50, 51, 53, 55, 59, 60]

    oribitList = finalOribit(varsNum)
    innerProduct = innerProductSelect(varsNum)
    initCondtionNodeList = []
    initCondtionNodeList.append(copy.deepcopy(lst1))
    for ele in conditionList():
        initCondtionNodeList.append(copy.deepcopy(ele))
    while count < 1000:
        count += 1
        lst = alg(varsNum, lst1, oribitList, innerProduct, initCondtionNodeList)
        lst1 = copy.deepcopy(lst)
        if count % 100 == 0 or count == 1:
            print(count)
Example #2
0
def attitute(varsNum, lst):
    OribitList = finalOribit(varsNum)
    dicIndexList = initRSBF(varsNum, lst, OribitList)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    flag = False
    if truthTable == pow(2, varsNum):
        flag = True
    res1 = nonlinearityCompute(varsNum, truthTable, innerProductSelect(varsNum))
    if res1 > 236:
        res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
        with open("gen_res.txt", mode = "a+", encoding="utf-8") as f:
            f.write(str(lst) + "  " + str(res1) + str(flag) + str(res2) + "\n")
    elif flag == True and res1 >= 234:
        res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
        with open("gen_res.txt", mode="a+", encoding="utf-8") as f:
            f.write(str(lst) + "  " + str(res1) + str(flag) + str(res2) + "\n")
Example #3
0
def perprority(varsNum, lst):
    OribitList = finalOribit(varsNum)
    dicIndexList = initRSBF(varsNum, lst, OribitList)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    res1 = nonlinearityCompute(varsNum, truthTable,
                               innerProductSelect(varsNum))
    print(res1)
    if res1 < 230:
        return
    flag = ""
    if truthTable.count(1) == pow(2, varsNum):
        flag = "balanced"
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    with open("best.txt", mode="a+", encoding="utf-8") as f:
        f.write(
            str(lst) + "    nonlinearity = " + str(res1) +
            "    transparency = " + str(res2) + "    " + flag + "\n")
    print("nonlinearity = ", res1)
    print("transparency", res2)
def walshCompute(varsNum, truthTable):
    # print(truthTable)
    innerProductRes = innerProductSelect(varsNum)
    walshTmpResList = []
    tmpList = []
    walshResList = []
    for i in range(len(innerProductRes)):
        tmpList.append(
            (truthTable[i % len(truthTable)] + innerProductRes[i]) % 2)
    # print(tmpList)
    for i in range(len(tmpList)):
        if tmpList[i] == 0:
            walshTmpResList.append(1)
        else:
            walshTmpResList.append(-1)

    for i in range(len(truthTable)):
        tmpRes = 0
        for j in range(len(truthTable)):
            tmpRes = walshTmpResList[j + i * len(truthTable)] + tmpRes
        walshResList.append(tmpRes)

    return walshResList
Example #5
0
def walshCompute(varsNum, truthTable):
    # print(truthTable)
    innerProductRes = innerProductSelect(varsNum)
    walshTmpResList = []
    tmpList = []
    walshResList = []
    for i in range(len(innerProductRes)):
        tmpList.append(
            (truthTable[i % len(truthTable)] + innerProductRes[i]) % 2)
    # print(tmpList)
    for i in range(len(tmpList)):
        if tmpList[i] == 0:
            walshTmpResList.append(1)
        else:
            walshTmpResList.append(-1)

    for i in range(len(truthTable)):
        tmpRes = 0
        for j in range(len(truthTable)):
            tmpRes = walshTmpResList[j + i * len(truthTable)] + tmpRes
        walshResList.append(tmpRes)

    # testResList = []
    # for ele in walshResList:
    #     testResList.append(copy.deepcopy(ele ** 2))
    #
    # testResList2 = []
    # for ele in testResList:
    #     testResList2.append(copy.deepcopy(pow(ele - pow(2, varsNum), 3)))
    #
    # testRes = 0
    # for ele in testResList2:
    #     testRes = ele + testRes
    # print(testRes)
    # print(walshResList)
    return walshResList
Example #6
0
        if TableOribitList[i].count(1) == len(TableOribitList[i]):
            shortList.append(i + 1)
    print(shortList)

    if FlagList.count(True) == len(TableOribitList):
        print("Rotation Symmetric Prove")
    else:
        print("The function is not Rotation Symmetric")


if __name__ == '__main__':
    start = time.time()
    varsNum = 8
    truthTable = functionTruthTable()
    print(truthTable)
    innerProduct = innerProductSelect(varsNum)
    isRotationSymmetric(varsNum, truthTable)
    print(truthTable.count(1))
    alltruthTable = AllTruthTableSelect(varsNum)
    indexDicList = trans(varsNum, truthTable, alltruthTable)
    nonlinearity = nonlinearityCompute(varsNum, truthTable, innerProduct)
    end = time.time()
    transparency = transparencyCompute(varsNum, truthTable, indexDicList)
    print("during time is ", (end - start) / 60)
    print(f"the nonlinearity = {nonlinearity}")
    print(f"the transparency = {transparency}")
    # #

    # varsNum = 9
    # oneNumList = [2, 4, 5, 9, 11, 12, 13, 14, 19, 20, 22, 23, 27, 28, 29, 31, 37, 38, 39, 43, 44, 45, 47, 50, 52, 53, 54, 56, 58, 59]
    # OribitList = finalOribit(varsNum)
            walshTmpResList.append(-1)

    for i in range(len(truthTable)):
        tmpRes = 0
        for j in range(len(truthTable)):
            tmpRes = walshTmpResList[j + i * len(truthTable)] + tmpRes
        walshResList.append(tmpRes)

    return walshResList


'''
    布尔函数非线性度的计算
    :return 布尔函数非线性度的值
'''


def nonlinearityCompute(varsNum, truthTable, innerProduct):
    tmpList = []
    for ele in walshCompute(truthTable, innerProduct):
        tmpList.append(abs(ele))
    # print(tmpList)
    return pow(2, varsNum - 1) - 0.5 * max(tmpList)


if __name__ == '__main__':
    dicIndexList = []
    truthTable = truthTableSelect(3, dicIndexList)
    res = nonlinearityCompute(3, truthTable, innerProductSelect(3))
    print(f"nonlinearity = {res}")