Я разработал программу шифрования Цезаря, но мне было интересно, могу ли я сделать ее более эффективной?Как я могу сделать свой шифр Цезаря более эффективным?
#A Caesar cipher program
##Defines the alphabet
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
##Collects the infomation from the user
task = input("Would you like to encrypt or decrypt?: ")
word = input("Please enter your word: ")
offset = int(input("Please enter your offset: ")) % 26
##The function to work out the answer
def workout(offset):
final = []
for i in word:
try:
if i.isupper():
final.append(abc[abc.index(i.lower()) + offset].upper())
else:
final.append(abc[abc.index(i.lower()) + offset])
except:
final.append(i)
print(''.join(final))
##Displays the final result
if task == "encrypt":
workout(offset)
else:
workout(-offset)
Я ценю все ответы :) Спасибо!
'помощь (str.translate)' ' –