The Cryptopals Crypto Challenges
02 Fixed XOR
st4rbuucks
2018. 10. 13. 02:03
Challenge
Write a function that takes two equal-length buffers and produces
their XOR combination.
Script
def xor(a,b): if len(a) != len(b): return -1 c = '' for i in range(len(a)): c += chr(ord(a[i]) ^ ord(b[i])) return c if __name__ == '__main__': s1 = '1c0111001f010100061a024b53535009181c'.decode('hex') s2 = '686974207468652062756c6c277320657965'.decode('hex') result = xor(s1, s2) print result.encode('hex')