- #1
NihalRi
- 134
- 12
I had recently upgraded my version of python from 2 to 3. I had a program that encrypted a text file by converting a character to its Unicode value, altering it and then changing it back to a character using the ord() and chr() methods. This does not seem to work with python 3 and I was wondering how I could use encoding="utf-8" to make it work without altering too much of my code. Below is what my code looks like.for x in range(0, len(content)):
output = chr(ord(content[x])+ord(key[x])%256)
crypt = crypt + output
new.write(crypt)Ther error I would get isTraceback (most recent call last):
File "C:\Users\\Desktop\programing\Python Files\Encryptor and Decryptor\encryption.py", line 26, in <module>
new.write(crypt)
File "C:\Users\\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x93' in position 0: character maps to <undefined>
output = chr(ord(content[x])+ord(key[x])%256)
crypt = crypt + output
new.write(crypt)Ther error I would get isTraceback (most recent call last):
File "C:\Users\\Desktop\programing\Python Files\Encryptor and Decryptor\encryption.py", line 26, in <module>
new.write(crypt)
File "C:\Users\\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x93' in position 0: character maps to <undefined>