Exemplo n.º 1
0
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
Exemplo n.º 2
0
def conclusion():
    varsNum = 8
    # lst = [6, 7, 8, 9, 10, 14, 16, 17, 18, 19, 20, 22, 24, 25, 26, 32, 34]
    allTruthTable = AllTruthTableSelect(varsNum)
    oribit = finalOribit(varsNum)
    for i in range(1, 33):
        res = fileToList("116_" + str(16) + ".txt")
        for ele in res:
            dicIndexList = initRSBF(varsNum, ele[0], oribit)
            truthTable = TruthTableSelect(varsNum, dicIndexList)
            x = xiao_messay(varsNum, truthTable, allTruthTable)
            with open("relisent.txt", mode="a+", encoding="utf-8") as f:
                f.write(str(ele) + str(x) + "\n")
        print("check")
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def isRotationSymmetric(varsNum, truthTable):
    oribitList = finalOribit(varsNum)
    print(len(oribitList))
    nineTable = AllTruthTableSelect(varsNum)
    shortTableOribitList = []
    for ele in oribitList:
        tmpList = []
        for i in range(len(nineTable)):
            if nineTable[i] in ele:
                tmpList.append(i)
        shortTableOribitList.append(copy.deepcopy(tmpList))

    TableOribitList = []
    for ele in shortTableOribitList:
        tmpList = []
        for elem in ele:
            tmpList.append(truthTable[elem])
        TableOribitList.append(copy.deepcopy(tmpList))
    '''
        判断是否为旋转对称布尔函数
    '''
    FlagList = []
    for ele in TableOribitList:
        if ele.count(0) == len(ele) or ele.count(1) == len(ele):
            FlagList.append(True)
        else:
            FlagList.append(False)
    '''
        此处可获得短表
    '''
    shortList = []
    for i in range(len(TableOribitList)):
        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")
Exemplo n.º 7
0
 def __allOribit(self):
     return finalOribit(self.varsNum)
Exemplo n.º 8
0
    for ele in zeroVec:
        truthTableVec.append(allTruthTable[ele].count(1))
    # print(oneNumStatic)
    # print(truthTableVec)
    oneNumStatic.pop(0)
    autoDeg = 0
    for k, v in oneNumStatic.items():
        if truthTableVec.count(k) == v:
            autoDeg = k
        else:
            break
    return autoDeg


if __name__ == '__main__':
    varsNum = 8
    # # lst = [6, 7, 8, 9, 10, 14, 16, 17, 18, 19, 20, 22, 24, 25, 26, 32, 34]
    allTruthTable = AllTruthTableSelect(varsNum)

    RSST = [
        3.0, 10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 21.0, 24.0,
        25.0, 26.0, 27.0, 30.0, 34.0
    ]
    # tmp = (sorted(RSST))
    # print(tmp)
    oribit = finalOribit(varsNum)
    dicIndexList = initRSBF(varsNum, RSST, oribit)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    print(truthTable)
    print(xiao_messay(varsNum, truthTable, allTruthTable))
Exemplo n.º 9
0
def divProcess(ith):
    varsNum = 8
    oribitList = finalOribit(varsNum)
    fileToProcess("divData/" + "114" + "_" + str(ith) + ".txt", varsNum,
                  oribitList, 114, ith)
    print(str(ith) + " check")
Exemplo n.º 10
0
def oneNUmberNoAbsolute(varsNum, oneNumList, OribitList):
    dicIndexList = initRSBF(varsNum, oneNumList, OribitList)
    truthTable = TruthTableSelect(varsNum, dicIndexList)
    non_absolute = non_absolute_indicatorSelect(varsNum, truthTable,
                                                dicIndexList)
    return non_absolute


if __name__ == '__main__':
    varsNum = 9
    oneNumList = [
        4, 6, 7, 8, 9, 10, 11, 14, 15, 18, 19, 21, 22, 24, 26, 27, 32, 33, 34,
        40, 41, 45, 46, 48, 49, 51, 52, 57, 59
    ]
    oribitList = finalOribit(varsNum)
    print(oneNUmberNoAbsolute(varsNum, oneNumList, oribitList))

    # for i in range(32):
    #     p1 = Process(target=divProcess, args=(i ,))  # args为创建进程的传参方式
    #     p1.start()

    # varsNum = 8
    # allThTable = AllTruthTableSelect(varsNum)
    # oribitList = finalOribit(varsNum)
    # nonlinearity = 116
    # for i in range(1, 33):
    #     fileToProcess("divData/" + str(nonlinearity) + "_" + str(i) + ".txt", varsNum, oribitList, nonlinearity)
    #
    # nonlinearity = 114
    # for i in range(1, 33):
Exemplo n.º 11
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))