def decrypt(cipher_text, key):
plain_text = ""
for char in cipher_text:
if char.isalpha():
if char.isupper():
plain_text += chr((ord(char) - 65 - key) % 26 + 65) # 大写字母解密
else:
plain_text += chr((ord(char) - 97 - key) % 26 + 97) # 小写字母解密
elif char.isdigit():
plain_text += chr((ord(char) - 48 - key) % 10 + 48) # 数字解密
else:
plain_text += char # 特殊字符保持不变
return plain_text
cipher_text = input("请输入明文或密文:")
for key in range(1, 26):
print("密钥为:", key)
plain_text = decrypt(cipher_text, key)
print("解密为:", plain_text)