title: How can I decrypt RC4 using hex values?
body: <p>I found a couple RC4 scripts online for python. I used one from <a href="http://www.joonis.de/en/code/rc4-algorithm" rel="nofollow">http://www.joonis.de/en/code/rc4-algorithm</a> that I simplified and am using just for decrypting files that have been encrypted with RC4 with a 40byte key.</p>
  
  <pre><code>testFile = 'input.xml'
  
  key = 'Utood9dRzY2ugHYi9jl9ug2UNytIIxjk6Ptouaig'
  
  out=file('output.xml','wb')
  
  with open (testFile, "rb") as f:
      data = f.read()
      S = range(256)
      j = 0
  
      for i in range(256):
          j = (j + S[i] + ord(key[i % len(key)])) % 256
          S[i] , S[j] = S[j] , S[i]
  
      for char in data:
          i = 0
          j = 0      
          i = ( i + 1 ) % 256
          j = ( j + S[i] ) % 256
          S[i] , S[j] = S[j] , S[i]
          out.write(chr(ord(char) ^ S[(S[i] + S[j]) % 256]))
  
  out.close()
  </code></pre>
  
  <p>I know what the result should be because I have successfully decrypted the input.xml file @ <a href="http://rc4.online-domain-tools.com/" rel="nofollow">http://rc4.online-domain-tools.com/</a> but when I do it through the script the output is wrong.</p>
  
  <p>I'm kind of at a loss of where the problem may lie. If anybody can tell me what I'm doing wrong I'd highly appreciate it!</p>
  
  <p>I want to say I may need to find out how to code the algorithm to work with hex values vs integers but it seems pythons already has it hex. I'm not too sure though.</p>
  
  <p>Link to testfile = <a href="http://bayfiles.net/file/1kPgD/bVuyGw/input.xml" rel="nofollow">http://bayfiles.net/file/1kPgD/bVuyGw/input.xml</a></p>