Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created February 13, 2017 18:19
Show Gist options
  • Save AndyNovo/73cce5360495be0b7a307d7a857c050f to your computer and use it in GitHub Desktop.
Save AndyNovo/73cce5360495be0b7a307d7a857c050f to your computer and use it in GitHub Desktop.
import binascii, hashlib
k = "secretkey"
msg = "forge this punks"
kplus = k + "\x00"*(64-len(k))
ipad = "\x36"*64
opad = "\x5C"*64
def XOR(raw1, raw2):
return binascii.unhexlify(format(int(binascii.hexlify(raw1), 16) ^ int(binascii.hexlify(raw2), 16), 'x'))
tag = hashlib.sha256(XOR(kplus, opad) + hashlib.sha256(XOR(kplus, ipad) + msg).digest()).digest()
print binascii.hexlify(tag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment