有没有办法让一个项目接受资本化和非资本化的投入



正如标题所说,我的程序具有大写功能,但我希望它与非大写和大写输入兼容。它应该以大写加密的形式返回。

decrypted = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ.1234567890 "
encrypted = b"SE2RL.1W5A0Z8D7H4B9M6JX3FTNVQGPUOYCKI "
encrypt_table = bytes.maketrans(decrypted, encrypted)
decrypt_table = bytes.maketrans(encrypted, decrypted)
result = ''
choice = ''
message = ''
while choice != 'X':
choice = input("n Do you want to encrypt or decrypt the message?n E to encrypt, D to decrypt or X to exit program. ")
if choice == 'E':
message = input('nEnter message for encryption: ')
result = message.translate(encrypt_table)
print(result + 'nn')
elif choice == 'D':
message = input('nEnter message to decrypt: ')
result = message.translate(decrypt_table)
print(result + 'nn')
elif choice != 'X':
print('You have entered an invalid input, please try again. nn')

您可以将所有小写字母添加到decrypted字符串中,也可以在用户输入中使用.upper()

此外,从技术上讲,这是一个替代密码。为了使它成为一个真正的";加密";你需要有一把钥匙;解锁";加密文本。参见凯撒密码的一个非常简单的例子(事实上,它本身就是一种替换密码:P(,其中密钥是移位数。或者看看AES,它可以说是迄今为止最好的加密算法。

最新更新