Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import xor
- def ords(text):
- for char in text:
- yield ord(char)
- def tobits(num):
- for bit in bin(num)[2:]:
- yield int(bit)
- def frombits(stream):
- return int('0b'+''.join(map(str, stream)), 2)
- def bitstream(text):
- out = []
- for num in ords(text):
- out += tobits(num)
- return out
- def cumxor(stream):
- first = stream[0]
- stream = stream[1:]
- last = first
- for i in range(len(stream)):
- stream[i] = stream[i] ^ last
- last = stream[i]
- return [last ^ first] + stream
- def hash(stream):
- first = stream[0]
- stream = stream[1:]
- last = first
- out = []
- for i in range(len(stream)):
- stream[i] = stream[i] ^ last
- last = stream[i]
- out += stream[:i+1]
- out = cumxor(out)
- return out
- def chunks(l, n):
- n = max(1, n)
- return [l[i:i + n] for i in range(0, len(l), n)]
- def digest(h):
- chunked = chunks(h, 128)
- d, m, l = chunked[0], chunked[1:-1], chunked[-1]
- l += d
- l = l[:128]
- m.append(l)
- del l
- for l in m:
- for i in range(len(d)):
- d[i] = xor(d[i],l[i])
- return hex(frombits(cumxor(d)))[2:]
- t = ' '
- a = bitstream(t)
- b = digest(hash(a))
- print(a)
- print(b)
Advertisement
Add Comment
Please, Sign In to add comment