Sweet nice tip I love this list.  Thank you.<br><br>Mike<br><br><div class="gmail_quote">On Sat, Oct 24, 2009 at 7:40 PM, Dave Angel <span dir="ltr">&lt;<a href="mailto:davea@ieee.org">davea@ieee.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">Tom Green wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for your reply Dave.  I am capturing the data off the network<br>
(wireshark) and saving it in WinHex for testing.  I am actually building a<br>
socket to decrypt the data, so prior to implementing my logic in the socket,<br>
I figured I would write the algorithm in a quick script.  Here is what I<br>
have so far and it works.<br>
<br>
import struct,binascii<br>
decrypt=[]<br>
data_count=0<br>
key_pos=0<br>
#packed data consists of HEX values<br>
packed_data = binascii.unhexlify(&#39;313B372C2E2C63362E2128&#39;)<br>
#XorKey data consists of HEX values<br>
packed_XorKey=binascii.unhexlify(&#39;41424344&#39;)<br>
while data_count &lt; len(packed_data):<br>
    if key_pos &gt;len(packed_XorKey)-1:<br>
        key_pos=0<br>
<br>
decrypt.append(chr(ord(packed_data[data_count])^ord(packed_XorKey[key_pos])))<br>
    key_pos+=1<br>
    data_count+=1<br>
print &quot;&quot;.join(decrypt)<br>
<br>
This decrypts to Python rock<br>
<br>
This logic seems to work, but I am certain there is a better way.<br>
<br>
Mike<br>
<br>
<br>
On Sat, Oct 24, 2009 at 4:43 PM, Dave Angel &lt;<a href="mailto:davea@ieee.org" target="_blank">davea@ieee.org</a>&gt; wrote:<br>
<br>
  <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Tom Green wrote:<br>
<br>
    <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alan,<br>
<br>
Thanks for your response and hopefully I can clear things up.  I apologize<br>
for not being more clear.<br>
<br>
I obtain the HEX encoded data from Winhex i.e. copy Hex values.  The HEX<br>
encode data is very large and I simply paste it into my Python script<br>
along<br>
with the XOR key.  The data is a string of bytes represented in HEX, as I<br>
showed.<br>
<br>
Here is the problem I ran into.<br>
<br>
Take the 4 byte XOR key.  If I convert them to int with Base 16 it takes<br>
the<br>
4 and converts it to 0x34 when I in turn I actually need 0x41.<br>
<br>
Thanks for your feedback.<br>
<br>
Mike<br>
<br>
On Sat, Oct 24, 2009 at 10:24 AM, Alan Gauld &lt;<a href="mailto:alan.gauld@btinternet.com" target="_blank">alan.gauld@btinternet.com</a><br>
      <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
wrote:<br>
        <br>
</blockquote>
&lt;snip&gt;<br>
<br>
      <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 Encrypted string in hex<br>
<br>
<br>
        <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&quot;313B372C2E2C63362E2128&quot;<br>
<br>
Four byte key<br>
XOR key &quot;41424344&quot;<br>
<br>
<br>
<br>
          <br>
</blockquote>
&lt;snip&gt;<br>
<br>
        <br>
</blockquote>
If by Winhex, you mean the hex editor, then you&#39;re undoubtedly going about<br>
      <br>
</blockquote>
it the long way.  There&#39;s no need to convert the file to printable hex, you<br>
should be able to work on it directly.  Just open the file, read it into a<br>
string (in python2.x), then loop through it, one byte at a time.  Store your<br>
key in a binary string as well.  Now just loop through the two in pairs (use<br>
zip, and cycle) doing a chr of xor of ords.<br>
<br>
<br>
And when you respond, give us your python version, and show us the code<br>
you&#39;ve got (almost) working.<br>
<br>
DaveA<br>
<br>
    <br>
</blockquote>
<br>
  <br>
</blockquote></div></div>
(You top-posted, so your message is out of order)<br>
<br>
Replace your while -- loop with the following simpler version.<br>
<br>
<br>
for byte0, byte1 in itertools.izip(packed_data, itertools.cycle(packed_XorKey)):<br>
   decrypt.append(chr(ord(byte0) ^ ord(byte1)))<br>
<br>
(You&#39;ll need an import itertools, at beginning, of course.)<br>
<br>
itertools.cycle() repeats the pattern of the keys.  itertools.izip() combines two iterables into one.  Then you just loop through that one in the usual way, where byte0 comes from the packed_data, and byte1 comes from the XorKey.<br>

<br>
DaveA<br>
<br>
</blockquote></div><br>