I'm trying to write a program that converts two hex strings to bytes, and from bytes to binary. Once in binary, I want to perform an XOR transposition on them. This having been accomplished, I want to convert the binary strings back to bytes, and again into hex. I already know what the answer should be, it's just a question of getting from A to B.
The code I have so far is as follows:
input1 = "1c0111001f010100061a024b53535009181c"
input2 = "686974207468652062756c6c277320657965"
target = "746865206b696420646f6e277420706c6179"
d = conversions.hexconvert(input1)
e = conversions.hexconvert(input2)
print(d)
print(e)
f = bitstring.BitArray(d)
g = bitstring.BitArray(e)
xor1 = f.bin
xor2 = g.bin
print("xor1 is", xor1)
print("xor2 is", xor2)
xor1, xor2 = xor2, xor1
print("xor1 is now:", xor1)
The function "hexconvert" is comprised of the following code:
import codecs
def hexconvert(input):
output = codecs.decode(input, 'hex')
return(output)
My code is currently spitting out the following:
b'\x1c\x01\x11\x00\x1f\x01\x01\x00\x06\x1a\x02KSSP\t\x18\x1c'
b"hit the bull's eye"
xor1 is : 000111000000000100010001000000000001111100000001000000010000000000000110000110100000001001001011010100110101001101010000000010010001100000011100
xor2 is : 011010000110100101110100001000000111010001101000011001010010000001100010011101010110110001101100001001110111001100100000011001010111100101100101
xor1 is now: 011010000110100101110100001000000111010001101000011001010010000001100010011101010110110001101100001001110111001100100000011001010111100101100101
All good so far. I'd like to know what I can add to the end of this code to convert xor1 to bytes then to hex so that I can compare it to the result it should be. I've been trying to figure out how to use struct, binascii, and even bitstring, but I'm getting nowhere. Any and all suggestions greatly appreciated.
It would also be great if anyone could suggest how to make the code more efficient.
Thanks very much in advance!