def random_minicipher(n): res = [] for k in xrange(2**n): p = range(2**n) shuffle(p) res.append(tuple(p)) return tuple(res)
def random_involution(n): print 'WARNING: too low number of fixed points! not a uniform distribution' pairs = range(2**n) shuffle(pairs) s = [0] * 2**n while pairs: if len(pairs) == 1 or randint(1, len(pairs)) == 1: a = b = pairs.pop() else: a, b = pairs.pop(), pairs.pop() s[a] = b s[b] = a return s
def generate_FN(funcpool, nr): shuffle(funcpool) fs = funcpool[:nr] s = SBox2.gen.feistel_network_xor(funcs=fs) return fs, s
def generate_FN_two_last(funcpool, nr): shuffle(funcpool) fs = funcpool[:nr] s = SBox2.gen.feistel_network_xor(funcs=fs) spre = SBox2.gen.feistel_network_xor(funcs=fs[:-1]) return fs, s, spre
def random_permutation(n, h**o=False): res = range(1 if h**o else 0, 2**n) shuffle(res) return ([0] if h**o else []) + res