python - 使用自己的密码字典加密

标签 python python-3.x dictionary encryption python-3.4

这是我的代码:

dictionary = {'A':'3',
'B':'u',
'C':'t',
'D':'5',
'E':'b',
'F':'6',
'G':'7',
'H':'8',
'I':'/',
'J':'9',
'K':'0',
'L':'-',
'M':'o',
'N':'i',
'O':';',
'P':'}',
'Q':'c',
'R':'n',
'S':'4',
'T':'m',
'U':'.',
'V':'y', 
'W':'v',
'X':'r', 
'Y':',',
'Z':'e',
}
print(dictionary)
inp = input(str("What do you want me to encode?").upper()).upper()
li = list(inp)
print(li)
for letter in inp:
    pass

我想问如何使用这个字典来加密通过输入的任何消息。就像“你好,我的名字是杰瑞”会变成:(没有短语)“8b--;” o,i3ob/4 9bnn,'。 有人可以帮我解决这个问题吗?我见过其他类似的问题 - 但他们使用 PyCrypto。我不想经历安装它的麻烦。有人可以帮助我吗?

谢谢, 杰瑞

最佳答案

您需要将用户输入的每个字符通过字典传递以获取密码值。

# removed the first .upper() here
inp = input(str("What do you want me to encode?")).upper()
li = list(inp)
print(li)

# create a list of letters passed through the dictionary
out = [dictionary[letter] for letter in inp]

# using ''.join makes the new list a single string
print(''.join(out))

关于python - 使用自己的密码字典加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41819062/

相关文章:

python - 如何在 python 中打印二叉搜索树?

python - 使用请求和 BeautifulSoup 在页面上找不到元素

python - 是否有自动检测数据类型的 argparse 模块

python - 使用组合迭代多个字典

python - 索引错误 : list assignment index out of range in python

python - 如何将 Python 字典写入 csv 文件?

python - 使用 python 或 shell 解析原始文本数据并将其插入 mysql 数据库

python - 如何在 Python 中组合重叠的矩形

python - GTK3绘图区教程好像没有?

python - 在所有 python 对象上注入(inject)辅助函数?