Answers for "how to caesar cipher in python"

1

python caesar cipher

plaintext = input("Please enter your plaintext: ")
shift = input("Please enter your key: ")
alphabet = "abcdefghijklmnopqrstuvwxyz"
ciphertext = ""

# shift value can only be an integer
while isinstance(int(shift), int) == False:
  # asking the user to reenter the shift value
  shift = input("Please enter your key (integers only!): ")

shift = int(shift)
  
new_ind = 0 # this value will be changed later
for i in plaintext:
  if i.lower() in alphabet:
    new_ind = alphabet.index(i) + shift
    ciphertext += alphabet[new_ind % 26]
  else:
    ciphertext += i    
print("The ciphertext is: " + ciphertext)
Posted by: Guest on June-07-2020

Python Answers by Framework

Browse Popular Code Answers by Language