def oneStap(varsNum, oneNumList, nonlinearityBound, CostMin):

    functionTruthTableList = []     # 函数真值表列表
    Dict_ADJcost = {}               # 轨道数i和cost的键值对
    # 获取varsNum元布尔函数的轨道真值表列表(全表)
    OribitList = finalOribit(varsNum)
    # 当前真值表情况下,所有翻转情况的oneNumList
    oneNumResList = randomFlapTruthTable(oneNumList, OribitList)
    for i in range(len(oneNumResList)):
        # 将轨道式短表转换为索引形式
        indexList = initRSBF(varsNum, oneNumResList[i], OribitList)
        # 将索引形式的表转化为长输出真值表
        truthTable = TruthTableSelect(varsNum, indexList)
        # 判断是否为平衡的旋转对称布尔函数
        # if truthTable.count(1) != pow(2, varsNum - 1):
        #     continue
        # print("have a balanced function")
        functionTruthTableList.append(list(indexList))

        nolinearity = nonlinearityCompute(varsNum, truthTable)
        print(nolinearity)
        if nolinearity > nonlinearityBound:
            cost = costFunction2(varsNum, truthTable, indexList)
        else:
            cost = costFunction1(varsNum, truthTable, indexList)
        Dict_ADJcost[i] = cost

        if float(cost) < float(CostMin):
            CostMin = cost
    return Dict_ADJcost, functionTruthTableList
Example #2
0
def nonlinearityAndTransparency(varsNum, lst):
    OribitList = finalOribit(varsNum)
    dicIndexList = initRSBF(varsNum, lst, OribitList)

    truthTable = TruthTableSelect(varsNum, dicIndexList)

    res1 = nonlinearityCompute(varsNum, truthTable)
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)

    return res1, res2, len(dicIndexList)
Example #3
0
def Function():
    varsNum = 8
    hexTruthTable = "18CA9ED8BC4EC1AFE2F4C023FA63E78949455BC59DB873BE79409BAE4B289029"
    truthTable = hexToBinary(hexTruthTable)
    dicIndexList = normalIndexSelect(varsNum, truthTable)
    res1 = nonlinearityCompute(varsNum, truthTable)
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    print("nonlinearity = ", res1)
    print("transparency = ", res2)
    res = non_absolute_indicatorSelect(varsNum, truthTable, dicIndexList)
    print("non_absolute_indicator = ", res)
Example #4
0
def oneProcess(varsNum, pos, oneNumList, oribitList, innerProduct):
    indexList = initRSBF(varsNum, oneNumList, oribitList)
    truthTable = TruthTableSelect(varsNum, indexList)
    nonlinearity = nonlinearityCompute(varsNum, truthTable, innerProduct)
    costDic = {}
    tableDic = {}
    if nonlinearity >= 234:
        cost = costFunction(varsNum, truthTable, indexList, nonlinearity)
        costDic[pos] = cost
        tableDic[pos] = oneNumList
        return costDic, tableDic
Example #5
0
def nonlinearityAndTransparency(varsNum, lst, innerProduct, OribitList):
    dicIndexList = initRSBF(varsNum, lst, OribitList)

    truthTable = TruthTableSelect(varsNum, dicIndexList)
    balanceFlag = ""
    if truthTable.count(1) == pow(2, varsNum - 1):
        balanceFlag = "balanced function"
    else:
        balanceFlag = "unbalanced function"
    res1 = nonlinearityCompute(varsNum, truthTable, innerProduct)
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    # print("nonlinearity = " + str(res1), "  transparency = " + str(res2))
    return res1, res2, balanceFlag
Example #6
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 #7
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)
Example #8
0
def classifier(varsNum, truthTable):
    count = -1
    oneNumList = []
    zeroNumList = []
    for ele in truthTable:
        count = count + 1
        if ele == 1:
            oneNumList.append(count)
        elif ele == 0:
            zeroNumList.append(count)
        else:
            print("fail")

    oneNumdic = {}
    oneNumcount = 0
    for ele in oneNumList:
        oneNumdic[oneNumcount] = ele
        oneNumcount = oneNumcount + 1
    # print(oneNumdic)

    zeroNumdic = {}
    zeroNumcount = 0
    for ele in zeroNumList:
        zeroNumdic[zeroNumcount] = ele
        zeroNumcount = zeroNumcount + 1
    # print(zeroNumdic)

    randList = np.random.randint(0, 128, 64)

    one_zero_list = flipTruthTable(oneNumdic, zeroNumdic, randList)

    newTruthTable = reformTruthtable(varsNum, one_zero_list)

    alltruthTable = EightVars_AllTruthTable()
    indexDicList = trans(8, newTruthTable, alltruthTable)

    nonlinearity = nonlinearityCompute(varsNum, newTruthTable)
    transparency = transparencyCompute(varsNum, newTruthTable, indexDicList)
    if nonlinearity > 110:
        print(f"the nonlinearity = {nonlinearity}")
        print(f"the transparency = {transparency}")
    return newTruthTable
Example #9
0
def possibleTable(varsNum, beginPos, endPos):
    start = time.time()
    count = 0
    allOribit = finalOribit(varsNum)

    for i in range(beginPos, endPos):
        tmp = str(bin(i)).split("0b")
        for elem in tmp:
            if elem == '':
                continue
            tmpList = []
            for element in elem:
                tmpList.append(int(element))

            if len(tmpList) != 36:
                for i in range(36 - len(tmpList)):
                    tmpList.insert(0, 0)

            oribitLocList = oneNumToOribit(tmpList)
            # print(oribitLocList)
            balancedFlag = isBalanced(varsNum, oribitLocList, allOribit)

            if balancedFlag == False:
                break

            indexList = initRSBF(varsNum, oribitLocList, allOribit)
            truthTable = TruthTableSelect(varsNum, indexList)
            nonlinearity = nonlinearityCompute(varsNum, truthTable)
            # print(nonlinearity)
            if nonlinearity >= 112:
                transparency = transparencyCompute(varsNum, truthTable, indexList)
                with open("result/pow_35_" + str(endPos) + "_search.txt", mode = "a+", encoding = "utf-8") as f:
                    f.write(str(oribitLocList) + " " + str(nonlinearity) + " " + str(transparency) + "\n")

        count += 1
        if count % 10000000 == 0:
            print(str(beginPos) + "->" + str(endPos) + "check ", count)
    end = time.time()

    print(str(beginPos) + "->" + str(endPos)  + "during time1 is ", end - start)
    print(count)
Example #10
0
    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)
    # dicIndexList = initRSBF(varsNum, oneNumList, OribitList)
    # truthTable = TruthTableSelect(varsNum, dicIndexList)
    # isRotationSymmetric(9, truthTable)
Example #11
0
    # print(truthTable)

    return truthTable


if __name__ == '__main__':

    start = time.time()
    varsNum = 8
    # oneNumList = [1, 3, 6, 11, 12, 13, 16, 18, 19, 20, 24, 26, 27, 28, 29, 31, 32, 33, 35, 36, 38, 39, 40, 44, 46, 47, 48, 51, 52, 53, 54, 60]
    oneNumList = [
        2, 4, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 29, 30, 31, 34, 35, 36
    ]
    #
    # oneNumList = [1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 18, 19, 20, 22, 23, 24, 28, 29, 35, 36, 38, 39, 41, 43, 44, 45, 47, 51, 53, 54, 55, 56, 62, 66, 67, 68, 70, 71, 72, 74, 75, 79, 81, 83, 88, 89, 93, 94, 98, 99, 100, 101, 106, 107, 108, 109, 110, 111, 113, 116, 118, 119, 120, 121, 128, 130, 133, 138, 139, 140, 141, 142, 149, 152, 153, 155, 156, 159, 160, 161, 163, 164, 167, 168, 169, 171, 173, 176, 177, 179, 180, 182, 186, 187]
    OribitList = finalOribit(varsNum)
    all = AllTruthTableSelect(varsNum)
    print(len(OribitList))
    dicIndexList = initRSBF(varsNum, oneNumList, OribitList)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    # print(len(truthTable))
    # print(truthTable.count(1))
    # truthTable = RSST_to_NormalTable(varsNum, oneNumList, OribitList, all)
    # start = time.time()
    res1 = nonlinearityCompute(varsNum, truthTable)
    # res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    end = time.time()
    print("nonlinearity = ", res1)
    # print("transparency", res2)
    # print("during time is ", end - start)
Example #12
0
def twoStep(varsNum, Dict_ADJcost, functionTruthTableList, F_MIN):
    index_TruthTable = {}
    i = 0
    for ele in Dict_ADJcost.keys():
        index_TruthTable[ele] = functionTruthTableList[i]
        i += 1

    # 对字典依照value值进行排序
    DictSortList = sorted(Dict_ADJcost.items(), key=lambda x : x[1], reverse = True)

    DictSortListLen = len(DictSortList)

    if DictSortListLen > 1:
        for i in range(DictSortListLen):
            indexList = index_TruthTable[DictSortList[DictSortListLen - i - 1][0]]
            tmpDic = {}
            tmpDic[DictSortList[DictSortListLen - i - 1][1]] = indexList
            sortList1 = DictSorted(tmpDic)
            tmpDic[DictSortList[DictSortListLen - i - 1][1]] = sortList1
            if tmpDic not in F_MIN:
                dicTmp = {}
                dicTmp[DictSortList[DictSortListLen - i - 1][1]] = indexList
                sortList2 = DictSorted(dicTmp)
                dicTmp[DictSortList[DictSortListLen - i - 1][1]] = sortList2
                # print(dicTmp)
                F_MIN.append(dicTmp)
                break
    else:
        indexList = functionTruthTableList[0]
        tmpDic = {}
        tmpDic[0] = indexList
        sortList1 = DictSorted(tmpDic)
        tmpDic[DictSortList[0]] = sortList1


        if tmpDic not in F_MIN:
            dicTmp = {}
            dicTmp[DictSortList[0][1]] = indexList
            sortList2 = DictSorted(dicTmp)
            dicTmp[DictSortList[0][1]] = sortList2
            F_MIN.append(dicTmp)


    tmpList = []
    for ele in list(F_MIN[-1].values()):
        for elem in ele:
            tmpList.append(elem)

    if len(tmpList) == pow(2, varsNum - 1):
        info = "balanced boolean function"
    else:
        info = "unbalanced boolean function"


    oneNumList = []
    allOribit = finalOribit(varsNum)
    for ele in tmpList:
        for i in range(len(allOribit)):
            if ele in allOribit[i]:
                oneNumList.append(i + 1)


    dicIndexList = initRSBF(varsNum, list(set(oneNumList)), allOribit)

    truthTable = TruthTableSelect(varsNum, dicIndexList)

    res1 = nonlinearityCompute(varsNum, truthTable)
    if res1 < 980:
        print("no write")
    if res1 >= 980:
        res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
        with open("search_result/nobalanced_nonlinearity_" + str(res1) + "_resFile.txt", mode = "a", encoding= "utf-8") as f:
            f.write(str(list(set(oneNumList))) + "  nonlinearity = " + str(res1) + "  transparency = " + str(res2)  + " " + str(info) + "\n")

    return list(set(oneNumList))
Example #13
0
                    "8 2 E 8 F E 4 B 1 2 E 3 A 3 A 2 E 8 A F 4 E 6 6 8 4 4 A 2 A 0 C "
                    "8 0 E 2 E 9 7 E 5 1 B C 8 B D F F 8 "]
    tmpList = []
    for ele in TruthTableList1:
        tmpList = ele.split(" ")

    binaryListTmp = hexToBinary(tmpList)
    binaryList = []
    for ele in binaryListTmp:
        for elem in ele:
            binaryList.append(elem)
    # print(binaryList)
    return binaryList





if __name__ == '__main__':
    truthTable = functionTruthTable()
    alltruthTable = EightVars_AllTruthTable()
    indexDicList = trans(8, truthTable, alltruthTable)
    # print(indexDicList)
    # print(indexDicList)
    nonlinearity = nonlinearityCompute(8, truthTable)
    transparency = transparencyCompute(8, truthTable, indexDicList)
    #
    print(f"the nonlinearity = {nonlinearity}")
    print(f"the transparency = {transparency}")

Example #14
0
        balanceFlag = "unbalanced function"
    res1 = nonlinearityCompute(varsNum, truthTable, innerProduct)
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    # print("nonlinearity = " + str(res1), "  transparency = " + str(res2))
    return res1, res2, balanceFlag


if __name__ == '__main__':

    # start = time.time()
    varsNum = 9
    oneNumList = [
        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
    ]

    # oneNumList = [2, 4, 5, 11, 13, 14, 16, 18, 19, 20, 22, 27, 29, 31, 32, 34, 36, 38, 41, 43, 47, 50, 51, 52, 53, 56, 58, 59]

    # oneNumList = [1, 2, 3, 5, 10, 11, 12, 13, 14, 16, 17, 18, 20, 21, 33, 34, 35, 36, 38, 42, 43, 44, 46, 47, 48, 52, 56, 59]
    OribitList = finalOribit(varsNum)
    dicIndexList = initRSBF(varsNum, oneNumList, OribitList)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    print(truthTable.count(1))
    res1 = nonlinearityCompute(varsNum, truthTable,
                               innerProductSelect(varsNum))
    res2 = transparencyCompute(varsNum, truthTable, dicIndexList)
    print("nonlinearity = ", res1)
    print("transparency", res2)
    # end = time.time()
    # print("during time is ", end - start)