# 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()))
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] print(var, value_nonl(array), nn_array_mod) else: print('Is not bijective!') if max(non_sbox) > limit: with open('data/part-1/'+getfilename(), 'a') as f: