[Tutor] Pack as HEX question

Dave Angel davea at ieee.org
Sat Oct 24 22:43:28 CEST 2009

Tom Green wrote:
> Alan,
> Thanks for your response and hopefully I can clear things up.  I apologize
> for not being more clear.
> I obtain the HEX encoded data from Winhex i.e. copy Hex values.  The HEX
> encode data is very large and I simply paste it into my Python script along
> with the XOR key.  The data is a string of bytes represented in HEX, as I
> showed.
> Here is the problem I ran into.
> 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.
> Thanks for your feedback.
> Mike
> On Sat, Oct 24, 2009 at 10:24 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:
> <snip>
>>  Encrypted string in hex
>>> "313B372C2E2C63362E2128"
>>> Four byte key
>>> XOR key "41424344"
>> <snip>
If by Winhex, you mean the hex editor, then you're undoubtedly going 
about it the long way.  There's no need to convert the file to printable 
hex, you should be able to work on it directly.  Just open the file, 
read it into a string (in python2.x), then loop through it, one byte at 
a time.  Store your key in a binary string as well.  Now just loop 
through the two in pairs (use zip, and cycle) doing a chr of xor of ords.

And when you respond, give us your python version, and show us the code 
you've got (almost) working.


More information about the Tutor mailing list