flag = 3 if S_array[iterate] - lol < S_array[temp3]: temp = theta[S_array[temp3]]; theta[S_array[temp3]] = theta[S_array[i]]; theta[S_array[iterate]] = temp; flag = 2 i = i+1 print theta print flag print test.value_nonl(theta) # print temp
# empty_array[i] = int(math.floor(empty_array[i])) # for i in range(256): # count = empty_array.count[i] # for j in range(i): length = len(empty_array) # print length print empty_array print is_bijective(empty_array) print test.value_nonl(empty_array) #print('the random number is',x) #x=81; # for iterate in range(user_iter): # t = theta[node] + nutrientsfunc(theta,flag,node,last); # f = theta[node+x] + nutrientsfunc(theta,flag,node+x,last); # diffrence = f - t; # # iterate = iterate + 1;
# count = empty_array.count[i] # for j in range(i): length = len(empty_array) # print length print empty_array print is_bijective(empty_array) print test.value_nonl(empty_array) #print('the random number is',x) #x=81; # for iterate in range(user_iter): # t = theta[node] + nutrientsfunc(theta,flag,node,last); # f = theta[node+x] + nutrientsfunc(theta,flag,node+x,last); # diffrence = f - t; # # iterate = iterate + 1;
# List of Columns p = "\nS-BOX " for i in range(16): p += "%02x" % i + " " p += "\n" for i in range(70): p += "-" p += "\n" # Row for i in range(16): p += "%02x" % i + " | " # Entries for j in range(16): p += "%02x" % sbox[16 * i + j] + " " p += "\n" return p.upper() if __name__ == "__main__": print("Initial Sbox is : ") print(pretty(gen())) print("Is initial Sbox bijective:", is_bijective(gen())) print("Nonlinearity of Initial Sbox:", value_nonl(gen()))
--------- set_Vertices : set A set of vertices of graph. node : int The vertex to which we need minimum cost. """ cost_path = 0 for node in range(len(set_Vertices)-1): cost_path += dist(graph, set_Vertices[node], set_Vertices[node+1]) return cost_path if __name__ == '__main__': graphs = [] initial_non = value_nonl(gen()) # dict conatining sbox non_sbox = {initial_non: gen()} all_perms = list(per(range(8))) array = gen() if is_bijective(array): for var in range(10): array_mod = [] for num in range(32): array_mod, graph = substitution( all_perms, array, array_mod, num) graphs.append(graph) # calculate non-linearity of modified Sbox nn_array_mod = value_nonl(array_mod) if nn_array_mod > limit1: non_sbox[nn_array_mod] = [array_mod, graphs]
import math import random from random import randint import test threshold = 0; flag = 0; flag1 = 0; last =255; theta = [205, 78, 47, 165, 239, 178, 9, 175, 233, 123, 251, 216, 58, 26, 96, 199, 220, 15, 206, 83, 154, 235, 143, 245, 64, 79, 210, 63, 42, 82, 69, 134, 111, 50, 227, 229, 159, 156, 160, 145, 197, 124, 72, 228, 55, 77, 2, 189, 10, 18, 209, 122, 100, 20, 226, 129, 34, 37, 137, 200, 31, 240, 242, 62, 87, 136, 91, 59, 7, 106, 90, 135, 198, 27, 179, 158, 139, 241, 138, 144, 104, 211, 97, 148, 19, 108, 125, 192, 118, 46, 230, 12, 109, 161, 195, 221, 93, 246, 248, 196, 99, 225, 52, 120, 49, 188, 73, 67, 238, 207, 119, 163, 232, 43, 35, 254, 215, 21, 126, 127, 113, 41, 61, 75, 94, 172, 141, 89, 71, 219, 110, 45, 150, 234, 36, 112, 171, 131, 11, 237, 102, 32, 250, 54, 208, 4, 213, 29, 180, 243, 168, 60, 169, 201, 214, 13, 114, 116, 223, 23, 244, 185, 181, 84, 190, 247, 53, 28, 255, 6, 193, 253, 149, 167, 202, 17, 66, 22, 57, 191, 186, 44, 130, 14, 170, 1, 81, 105, 48, 88, 236, 155, 95, 25, 152, 166, 252, 38, 217, 5, 0, 157, 65, 176, 16, 140, 103, 76, 40, 121, 249, 173, 218, 24, 115, 183, 147, 68, 153, 231, 142, 3, 224, 187, 107, 177, 86, 51, 146, 132, 74, 133, 212, 56, 164, 174, 98, 203, 182, 30, 70, 39, 117, 80, 128, 33, 184, 8, 85, 222, 162, 194, 204, 151, 101, 92] non_li = test.value_nonl(theta) print non_li fo = open("substitution.txt", "wb") iterate = 0; def nutrientsfunc(theta,flag,first,last): i = 0 if flag==1: J=0; else: