title: XOR function differences between Python 3 and Python 2?
body: <p>Running in IDLE, Python 3.6.5 and Python 2.7.15 I have a strange problem with XOR. I get the correct answer with Python 2.7, and rubbish with Python 3.6. The Python 3.6 and 2.7 are not agreeing on a simple XOR. This is not an IDLE issue, since the behavior is the same in cygwin.</p>
  
  <pre><code>&gt;&gt;&gt; ciphertext
  
  '466d06ece998b7a2fb1d464fed2ced7641ddaa3cc31c9941cf110abbf409ed39598005b3399ccfafb61d0315fca0a314be138a9f32503bedac8067f03adbf3575c3b8edc9ba7f537530541ab0f9f3cd04ff50d66f1d559ba520e89a2cb2a83'
  </code></pre>
  
  <p>Python 2.7</p>
  
  <pre><code>&gt;&gt;&gt; ciphertext.decode('hex')
  'Fm\x06\xec\xe9\x98\xb7\xa2\xfb\x1dFO\xed,\xedvA\xdd\xaa&lt;\xc3\x1c\x99A\xcf\x11\n\xbb\xf4\t\xed9Y\x80\x05\xb39\x9c\xcf\xaf\xb6\x1d\x03\x15\xfc\xa0\xa3\x14\xbe\x13\x8a\x9f2P;\xed\xac\x80g\xf0:\xdb\xf3W\\;\x8e\xdc\x9b\xa7\xf57S\x05A\xab\x0f\x9f&lt;\xd0O\xf5\rf\xf1\xd5Y\xbaR\x0e\x89\xa2\xcb*\x83'
  &gt;&gt;&gt; for x, y in zip(ciphertext.decode('hex'), ' '*10):
      print "ord(x): " + chr(ord(x))
      print "ord(y): " + chr(ord(y))
      print(chr(ord(x) ^ ord(y)))
  
  
  ord(x): F
  ord(y):  
  f
  ord(x): m
  ord(y):  
  M
  ord(x): 
  ord(y): 
  &amp;
  ord(x): ì
  ord(y):  
  Ì
  ord(x): é
  ord(y):  
  É
  ord(x): ˜
  ord(y):  
  ¸
  ord(x): ·
  ord(y):  
  —
  ord(x): ¢
  ord(y):  
  ‚
  ord(x): û
  ord(y):  
  Û
  ord(x): 
  ord(y):  
  =
  </code></pre>
  
  <p>Python 3.6</p>
  
  <pre><code> &gt;&gt;&gt; bytes.fromhex(ciphertext)
  
     b'Fm\x06\xec\xe9\x98\xb7\xa2\xfb\x1dFO\xed,\xedvA\xdd\xaa&lt;\xc3\x1c\x99A\xcf\x11\n\xbb\xf4\t\xed9Y\x80\x05\xb39\x9c\xcf\xaf\xb6\x1d\x03\x15\xfc\xa0\xa3\x14\xbe\x13\x8a\x9f2P;\xed\xac\x80g\xf0:\xdb\xf3W\\;\x8e\xdc\x9b\xa7\xf57S\x05A\xab\x0f\x9f&lt;\xd0O\xf5\rf\xf1\xd5Y\xbaR\x0e\x89\xa2\xcb*\x83'
  &gt;&gt;&gt; for x, y in zip(bytes.fromhex(ciphertext), ' '*10):
      print("x: ", chr(x))
      print("ord(y): ", chr(ord(y)))
      print(chr(x^ord(y)))
  
  
  x:  F
  ord(y):   
  f
  x:  m
  ord(y):   
  M
  x:  
  ord(y):   
  &amp;
  x:  ì
  ord(y):   
  Ì
  x:  é
  ord(y):   
  É
  x:  
  ord(y):   
  ¸
  x:  ·
  ord(y):   
  &lt;- different value
  x:  ¢
  ord(y):   
  &lt;- different value
  x:  û
  ord(y):   
  Û
  x:  
  ord(y):   
  =
  
  In a cygwin window I get the following:
  $ ./python2_test.py
  Fm▒阷▒▒FO▒,▒vAݪ&lt;▒▒A▒
  f▒▒Y▒R▒▒▒*▒▒▒9▒ϯ▒▒▒▒▒▒▒2P;▒g▒:▒▒W\;▒ܛ▒▒7SA▒▒&lt;▒O▒
  ord(x): F
  ord(y):
  f
  ord(x): m
  ord(y):
  M
  ord(x):
  ord(y):
  &amp;
  ord(x): ▒
  ord(y):
  ▒
  ord(x): ▒
  ord(y):
  ▒
  ord(x): ▒
  ord(y):
  ▒
  ord(x): ▒
  ord(y):
  ▒
  ord(x): ▒
  ord(y):
  ▒
  ord(x): ▒
  ord(y):
  ▒
  ord(x):
  ord(y):
  =
  $ ./python3_test.py
  b'Fm\x06\xec\xe9\x98\xb7\xa2\xfb\x1dFO\xed,\xedvA\xdd\xaa&lt;\xc3\x1c\x99A\xcf\x11\n\xbb\xf4\t\xed9Y\x80\x05\xb39\x9c\xcf\xaf\xb6\x1d\x03\x15\xfc\xa0\xa3\x14\xbe\x13\x8a\x9f2P;\xed\xac\x80g\xf0:\xdb\xf3W\\;\x8e\xdc\x9b\xa7\xf57S\x05A\xab\x0f\x9f&lt;\xd0O\xf5\rf\xf1\xd5Y\xbaR\x0e\x89\xa2\xcb*\x83'
  x:  F
  ord(y):
  f
  x:  m
  ord(y):
  M
  x:
  ord(y):
  &amp;
  x:  ì
  ord(y):
  Ì
  x:  é
  ord(y):
  É
  x:  
  ord(y):
  ¸
  x:  ·
  ord(y):
  &lt;- missing
  x:  ¢
  ord(y):
  &lt;- missing
  x:  û
  ord(y):
  Û
  x:
  ord(y):
  =
  </code></pre>
  
  <p>Any help in sorting this out, would be greatly appreciated.
  Cheers.</p>