Xor operation inversion python
<p>I have a string and a key. I'm converting each character into a number and corresponding character in key also to a number and performing XOR, then converting back into a character.</p>

<p>How can I invert it, since sometimes the XOR of a single character returns multiple characters?</p>

<pre><code>def xor(plain):
    master = open('encrypt.py', 'r')
    key = master.readline()
    cipher = ""
    for x in range(0, len(plain)):
        cipher += chr(ord(plain[x]) ^ ord(key[x]))
    return cipher
</code></pre>