def generate_simon_version(n, rounds, a=8, b=1, c=2): simon = CipherDescription(2*n) for i in range(n): input_1 = "s{}".format((i-a)%n+n) input_2 = "s{}".format((i-b)%n+n) product = "t{}".format(2*i) simon.apply_and(input_1, input_2, product) input_3 = "s{}".format((i-c)%n+n) xor = "t{}".format(2*i+1) simon.apply_xor(product, input_3, xor) right_side = "s{}".format(i) simon.apply_xor(xor, right_side, right_side) for i in range(n): right_side = "s{}".format(i) left_side = "s{}".format(i+n) simon.apply_permutation( (right_side, left_side) ) simon.set_rounds(rounds) return simon
# Update State acorn.apply_xor("s289", "s235", "t1") acorn.apply_xor("t1", "s230", "s289") acorn.apply_xor("s230", "s196", "t1") acorn.apply_xor("t1", "s193", "s230") acorn.apply_xor("s193", "s160", "t1") acorn.apply_xor("t1", "s154", "s193") acorn.apply_xor("s154", "s111", "t1") acorn.apply_xor("t1", "s107", "s154") acorn.apply_xor("s107", "s66", "t1") acorn.apply_xor("t1", "s61", "s107") acorn.apply_xor("s61", "s23", "t1") acorn.apply_xor("t1", "s0", "s61") # Compute Feedback Bit # f = s0 + ~s107 + maj(s244, s23, s160) + ch(s230, s111, s66) + s196 + k maj(acorn, "s244", "s23", "s160", "tmaj2") ch(acorn, "s230", "s111", "s66", "tch") acorn.apply_xor("s0", "s107", "t1") # TODO: Add not to second parameter acorn.apply_xor("t1", "tmaj2", "t2") acorn.apply_xor("t2", "tch", "t3") acorn.apply_xor("t3", "s196", "t4") acorn.apply_xor("t4", "tk", "s0") # s0 gets feedback bit # Shift everything permutation = tuple("s{}".format(i) for i in range(292, -1, -1)) acorn.apply_permutation(permutation) acorn.set_rounds(1536)
from cipher_description import CipherDescription trivium = CipherDescription(288) trivium.apply_xor("s65", "s92", "t1") trivium.apply_xor("s161", "s176", "t2") trivium.apply_xor("s242", "s287", "t3") trivium.apply_and("s90", "s91", "tand1") trivium.apply_and("s174", "s175", "tand2") trivium.apply_and("s285", "s286", "tand3") trivium.apply_xor("t1", "tand1", "t1") trivium.apply_xor("t1", "s170", "s92") trivium.apply_xor("t2", "tand2", "t2") trivium.apply_xor("t2", "s263", "s176") trivium.apply_xor("t3", "tand3", "t3") trivium.apply_xor("t3", "s68", "s287") switch_last_bits = ("s92", "s176", "s287") trivium.apply_permutation(switch_last_bits) permutation_1 = tuple("s{}".format(i) for i in range(93)) permutation_2 = tuple("s{}".format(i) for i in range(93, 177)) permutation_3 = tuple("s{}".format(i) for i in range(177, 288)) trivium.apply_permutation(permutation_1) trivium.apply_permutation(permutation_2) trivium.apply_permutation(permutation_3) trivium.set_rounds(1152)
from cipher_description import CipherDescription bivium = CipherDescription(177) bivium.apply_xor("s65", "s92", "t0") bivium.apply_and("s90", "s91", "t1") bivium.apply_xor("t0", "t1", "t2") bivium.apply_xor("t2", "s170", "s92") bivium.apply_xor("s161", "s176", "t3") bivium.apply_and("s174", "s175", "t4") bivium.apply_xor("t3", "t4", "t5") bivium.apply_xor("t5", "s68", "s176") switch_last_bits = ("s92", "s176") bivium.apply_permutation(switch_last_bits) permutation_1 = tuple("s{}".format(i) for i in range(93)) permutation_2 = tuple("s{}".format(i) for i in range(93, 177)) bivium.apply_permutation(permutation_1) bivium.apply_permutation(permutation_2) bivium.set_rounds(708)