I am using Python 2.7. I have an alphanumeric string, on which I want to perform a encryption/decryption. Whatever I do should remain 2-way and the result shoul
How strict is the alphanumeric requirement?
How about base64 encoding the result of your existing encryption function? You might end up with a few stray '=' padding characters, but you could trim these and calculate and handle the extra padding.
def xor_crypt_string(plaintext, key):
ciphertext = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(plaintext, cycle(key)))
return ciphertext.encode('base64')
def xor_decrypt_string(ciphertext, key):
ciphertext = ciphertext.decode('base64')
return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(ciphertext, cycle(key)))