[Tutor] Pack as HEX question
ALAN GAULD
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
something like
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!)
HTH,
Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091024/4ca5b082/attachment-0001.htm>
More information about the Tutor
mailing list