Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dig(l):
- if ord(l) >= ord('A') and ord(l) <= ord('F'):
- return 10 + ord(l) - ord('A')
- return ord(l) - ord('0')
- def from_16(s):
- ar = []
- for i in s:
- ar.append(dig(i))
- ar = ar[::-1]
- tot = 0
- for i in range(len(s)):
- tot += (16**i) * ar[i]
- return tot
- def xor(a, b):
- return a ^ b
- def shift(x):
- s = bin(x)
- t = s[len(s) - 1] + s[:len(s) - 1]
- t = t[3:]
- res = int(t, 2)
- return res
- def K_shift(x, K):
- for i in range(K):
- x = shift(K)
- return x
- def f(a, b, K):
- a = from_16(a)
- b = from_16(b)
- res = xor(a,b)
- res = K_shift(res, K)
- return res
- a = '1A2B'
- b = 'FFFF'
- K = 4
- must = from_16('4E5D')
- print(f(a,b, K), must)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement