使用感叹号使凯撒密码函数加密
Making a Caesar Cipher Function Encrypt With an Exclamation Mark
谁能帮我制作一个加密消息的函数,如果消息中包含感叹号。例如:你好!你好。
截至目前,我的函数 (HOWDY! Hello.) 的输出是
Your translated text is:
MTBIDEEMJQQTE
真正应该的时候:
Your translated text is:
MTBID! Mello.
我的完整代码:
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
message = ""
encryptedmessage = " "
keynumber = 0
def encrypt():
global message
global encryptedmessage
global keynumber
print()
print()
message = str(input("Enter your message:"))
print()
print()
keynumber = int(input("Enter the key number (1-26)"))
print()
print()
for i in message:
position = alphabet.find(i)
newposition = (position+5)%26
encryptedmessage +=alphabet[newposition]
print("Your translated text is:")
print(encryptedmessage)
def decrypt():
global message
global encryptedmessage
global keynumber
message = str(input("Enter your message:"))
keynumber = int(input("Enter the key number (1-26)"))
action = input("Do you wish to encrypt or decrypt a message?")
if action == "encrypt":
encrypt()
if action == "decrypt":
decrypt()
如果 i
不在 alphabet
中,alphabet.find(i)
将是 -1
。发生这种情况时,您应该将 i
复制到加密邮件中,而不是对其进行编码。
position = alphabet.find(i)
if position == -1:
encryptedmessage += i
else:
newPosition = (position + 5) % 26
encryptedmessage += alphabet[newPosition]
谁能帮我制作一个加密消息的函数,如果消息中包含感叹号。例如:你好!你好。 截至目前,我的函数 (HOWDY! Hello.) 的输出是
Your translated text is:
MTBIDEEMJQQTE
真正应该的时候:
Your translated text is:
MTBID! Mello.
我的完整代码:
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
message = ""
encryptedmessage = " "
keynumber = 0
def encrypt():
global message
global encryptedmessage
global keynumber
print()
print()
message = str(input("Enter your message:"))
print()
print()
keynumber = int(input("Enter the key number (1-26)"))
print()
print()
for i in message:
position = alphabet.find(i)
newposition = (position+5)%26
encryptedmessage +=alphabet[newposition]
print("Your translated text is:")
print(encryptedmessage)
def decrypt():
global message
global encryptedmessage
global keynumber
message = str(input("Enter your message:"))
keynumber = int(input("Enter the key number (1-26)"))
action = input("Do you wish to encrypt or decrypt a message?")
if action == "encrypt":
encrypt()
if action == "decrypt":
decrypt()
i
不在 alphabet
中,alphabet.find(i)
将是 -1
。发生这种情况时,您应该将 i
复制到加密邮件中,而不是对其进行编码。
position = alphabet.find(i)
if position == -1:
encryptedmessage += i
else:
newPosition = (position + 5) % 26
encryptedmessage += alphabet[newPosition]