[Tutor] Pack as HEX question

Tom Green xchimeras at gmail.com
Sat Oct 24 21:36:43 CEST 2009

This is what I have so far,

import struct

key = struct.unpack("d", XorKey)
num_ints = len(EncryptString)/11
data = struct.unpack("%dd"% num_ints,EncryptString)

The above code generates an error the my string must be a string length of

When you say I need to determine the number of ints in my data i.e.
EncryptString that value would be 11 right?

I appreciate your help.


On Sat, Oct 24, 2009 at 2:41 PM, ALAN GAULD <alan.gauld at btinternet.com>wrote:

> > 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/cffbbd40/attachment.htm>

More information about the Tutor mailing list