title: How to write to a txt file ascii characters in python?
body: <p>I'm implementing a XOR method, and I want to write the ciphered message to a txt file, but in the way I'm doing it, I get strange characters instead of the message.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>from itertools import cycle
  
  msg = 'RUNNINGFAST'
  key = 'SADSTORY'
  
  cipher = ''.join(chr(ord(c)^ord(k)) for c,k in zip(msg, cycle(key)))
  
  print('%s ^ %s = %s ' % (msg, key, cipher))
  msg = ''.join(chr(ord(c)^ord(k)) for c,k in zip(cipher, cycle(key)))
  print('%s ^ %s = %s ' % (cipher, key, msg))
  
  with open("XOR - Msg_Cipher.txt", "w",) as text_file:
      text_file.write("msg: %s \nCipher: %s" % (msg, cipher))
  </code></pre>
  
  <p>the output looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/cnmj0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cnmj0.png" alt="enter image description here"></a></p>
  
  <p>the txt file looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Ki2ze.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ki2ze.png" alt="enter image description here"></a></p>
  
  <p>How can I get the output inside the txt file?</p>
  
  <p>Thanks for your help</p>