python-3.x - 在 Python 3.0 中使用 encoding="utf-8" 加密文本
问题描述
我已经将我的 python 版本从 2 升级到了 3,我用来加密文本文件的程序不再工作了。下面是我的代码片段
for x in range(0, len(content)):
output = chr(ord(content[x])+ord(key[x])%256)
crypt = crypt + output
new.write(crypt)
我知道 python 不再使用 ASCII,但新系统似乎有点复杂,难以用于我的目的。有什么方法可以使用 encoding="utf-8" 使我的程序工作而不会过度复杂或过多地更改我的代码?我会很感激所有的答案。以下是我得到的错误
Traceback (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>
解决方案
推荐阅读
- button - 如何在vuetify中制作具有相同宽度的不同文本长度的2个按钮?
- python - Python Regex - 从字符串末尾抓取一块空白
- windows - 我在这个批处理文件中的代码是有意义的,但它不能正常工作
- ruby - 如何在ruby中压缩包含子文件夹的文件夹
- swiftui - 悬停自定义按钮时的矩形叠加
- python - 使用python 3.6版在jetbrains pycharm中安装wordcloud失败
- c# - 将 2 个转换为 int 的数组字符串加在一起时出现我不明白的错误
- google-app-engine - 如何查看 App Engine 上的每日实例使用情况?
- git - 如何压缩来自将另一个 repo 集成到分支中的旧提交?
- java - 在 JAVA 中将无效字符串传递给 SimpleDateFormat 时引发异常