从这些图片中可以看出,这个程序对于大小写是通用的。
刚学了一学期python,目前感觉很肝很好玩^_^
alphabet="abcdefghijklmnopqrstuvwxyz"
ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encryption():
global key
step=alphabet.index(key)
textout=""
for i in range(len(textin)):
if textin in alphabet:
letter = alphabet[(alphabet.index(textin)+step)%26]
textout = textout + letter
elif textin in ALPHABET:
letter = ALPHABET[(ALPHABET.index(textin)+step)%26]
textout = textout + letter
else:
textout = textout + textin
print(textout)
def decryption():
global key
step=alphabet.index(key)
textout=""
for i in range(len(textin)):
if textin in alphabet:
letter = alphabet[(alphabet.index(textin)-step)%26]
textout = textout + letter
elif textin in ALPHABET:
letter = ALPHABET[(ALPHABET.index(textin)-step)%26]
textout = textout + letter
else:
textout = textout + textin
print(textout)
while True:
answer=int(input("Please select the mode: Encryptionion mode - 1, Decryption mode - 2, Stop the program - 3"))
if answer == 1:
textin=input("Please type the text to be encrypted:")
key = input("Please input the key: a=? (a to z)")
if key in alphabet:
encryption()
else:
print("Invalid Key!")
continue
elif answer == 2:
textin =input("Please type the text to be decrypted:")
answer2=int(input("Do you know the key? Yes-1, No-2"))
if answer2 ==1:
key = input("Please input the key: a=? (a to z)")
if key in alphabet:
decryption()
else:
print("Invalid Key!")
continue
elif answer2 == 2:
print("Then all the possible answers will be shown.")
for key in alphabet:
decryption()
else:
continue
elif answer == 3:
break
else:
continue