Я пишу в Python 3.4 и до сих пор запрограммирован так:Я строй Цезарь шифра для моего школьного проекта, и хотел бы знать, как дешифровка часть будет работать
plaintext = ""
print ("Do you want to encrypt or decrypt a phrase?")
answer = input("Type e for encrypt or d for decrypt and hit 'Enter'.").lower()
if answer == ("e") or answer == ("encrypt"):
plaintext = input("Enter the phrase you would like to encrypt:")
else:
print("I don't understand")
shift = int(input("How many shifts would you like to make?")
alphabet = "abcdefghijklmnopqrstuvwxyz"
shiftedAlphabet = "jklmnopqrstuvwxyzabcdefghi"
ciphertext = ""
for eachletter in plaintext:
position = alphabet.index(eachletter)
shiftedLetter = shiftedAlphabet[position]
ciphertext = ciphertext + shiftedLetter
print(ciphertext)
if answer == ("d") or answer == ("decrypt")
ciphertext = input("Enter the phrase you would like to decrypt:"
else:
print("mmmm okay")
shiftedAlphabet -
Я не знаю, как к запрограммируйте часть дешифрования (обратите внимание: я хотел бы, чтобы код был относительно простым и хотел бы, чтобы он был аналогичен приведенному выше).
Код будет таким же, как шифрование, за исключением того, что вы просматриваете сдвинутый алфавит и заменяете соответствующую позицию в алфавите. – David