from sys import argv key1 = eval(argv[1]) # list of function selectors aka the key1 key2 = eval(argv[2]) # list of function selectors aka the key2 r = len(key1) # nmbr rounds implied by keys v = eval(argv[3]) # moving vector bo = int(argv[4]) # nmbr of bits out pt = int(argv[5]) # the plaintext def round(s, key1, key2, bo): s = s ^ key1 s = key2 * s % 2 ** bo return s def encrypt(pt, key1, key2, r, bo): ct = pt for i in range(r): ct = round(ct, key1[i], key2[i], bo) ct = bin(ct) ct = ct[2:] if len(ct) < bo: d = 2 ** (bo - len(ct)) d = bin(d) d = d[3:] ct = d + ct b = ct[v[i]:] a = ct[:v[i]] ct = b + a ct = int(ct, 2) return ct print encrypt(pt, key1, key2, r, bo)