这是我的代码:
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/