[Tutor] Pack as HEX question
alan.gauld at btinternet.com
Sat Oct 24 20:41:28 CEST 2009
> Take the 4 byte XOR key. If I convert them to int with Base 16
> it takes the 4 and converts it to 0x34 when I in turn I actually need 0x41.
OK, thats because int is for converting strings. You need to use struct.unpack
to convert the 4 bytes into an int.
You also need to figure out how many ints you have in your data and
construct a format string with that many ints to struct unpack the data.
Them apply the xor to each int using the key
key = struct.unpack("d", keydata)
num_ints = len(raw_data)/len(int)
data = struct.unpack("%dd" % num_ints, raw_data)
result = [n^key for n in data]
(untested pseudo code!)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor