どのように動作するかを知っていただきたいと思い、この:私はどのようにしないでくださいは、私は私の学校のプロジェクトのためのシーザー暗号を構築していますし、復号化部分は、私は、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