How can i apply the xor of two binary strings that represents the bin of two characters ?
here is a code
def Xor(a,b):
ABytes = a.encode('ascii','strict')
BBytes = b.encode('ascii','strict')
ABinaries = bin(int(binascii.hexlify(ABytes),16))
BBinaries = bin(int(binascii.hexlify(BBytes),16))
#this is what i want to do:
xor = ABinaries ^ BBinaries
return xor
But since the ^ operator does not operate on strings. the code does not work, the problem is that i need to return the binary value of the xor.
And if it worked, how can i get the string value of the xor ?
When you index or iterate
bytesin Python 3, you getintvalues that you canxor:If I wanted this as a bit string for some reason (representation? I certainly wouldn’t calculate with it), I’d use the built-in format, and zero pad each bitstring to 8 bits: