title: Xor encryption/decryption of a file with Python 3
body: <p>I need to encrypt / decrypt a file using xor with Python 3, I have a code that works fine in Python 2, but when trying to adapt it to Python 3, gives me some errors that I can't solve.</p>
  
  <p>This code works fine in Python 2.7:</p>
  
  <pre><code>from itertools import cycle
  
  
  def xore(data, key):
      return ''.join(chr(ord(a) ^ ord(b)) for (a, b) in zip(data, cycle(key)))
  
  with open('inputfile.jpg', 'rb') as encry, open('outputfile.jpg', 'wb') as decry:
      decry.write(xore(encry.read(), 'anykey'))
  </code></pre>
  
  <p>The error when trying to run unchanged in python 3:</p>
  
  <pre><code>Traceback (most recent call last):
    File "ask.py", line 8, in &lt;module&gt;
      decry.write(xore(encry.read(), 'anykey'))
    File "ask.py", line 5, in xore
      return ''.join(chr(ord(a) ^ ord(b)) for (a, b) in zip(data, cycle(key)))
    File "ask.py", line 5, in &lt;genexpr&gt;
      return ''.join(chr(ord(a) ^ ord(b)) for (a, b) in zip(data, cycle(key)))
  TypeError: ord() expected string of length 1, but int found
  </code></pre>
  
  <p>Please if someone could explain and help me adapt this code to Python 3.</p>