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
def unbalancedConclusion(varsNum, nonlinearity, address, oribit, allTruthTable): table = fileToList(address) for ele in table: dicIndexList = initRSBF(varsNum, ele[0], oribit) truthTable = TruthTableSelect(varsNum, dicIndexList) x = xiao_messay(varsNum, truthTable, allTruthTable) if x!= 0: with open("unbalanced" + str(nonlinearity) + "_reslisent_" + str(x) + ".txt", mode="a+", encoding="utf-8") as f: f.write(str(ele) + " " +str(x) + "\n")
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 __midProcess(self): if self.longTable != None: truthTable = longTableToTable(self.longTable) dicIndexList = trans(self.varsNum, truthTable, self.__alltruthTable()) return truthTable, dicIndexList else: dicIndexList = initRSBF(self.varsNum, self.shortTable, self.__allOribit()) truthTable = TruthTableSelect(self.varsNum, dicIndexList) return truthTable, dicIndexList
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
def fileToProcess(address, varsNum, oribitList, nonlinearity, ith): tableVec = fileToList1(address) for ele in tableVec: dicIndexList = initRSBF(varsNum, ele[0], oribitList) truthTable = TruthTableSelect(varsNum, dicIndexList) non_absolute = non_absolute_indicatorSelect(varsNum, truthTable, dicIndexList) with open("result/" + str(nonlinearity) + "_" + str(non_absolute) + "_" + str(ith) + ".txt", mode="a+", encoding="utf-8") as f: f.write(str(ele) + " " + str(non_absolute) + "\n")
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")
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)
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))
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
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))