Advertisement
JkSoftware

Day 8 - Caesar Cipher.2

Nov 12th, 2021
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. alphabet = ['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', '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']
  2.  
  3. direction = input("Type 'encode' to encrypt, type 'decode' to decrypt: ").lower()
  4. text = input("Type your message: ").lower()
  5. shift = int(input("Type the shift number:"))
  6.  
  7. def caesar(direction_, text_, shift_):
  8.     end_text = ""
  9.     if direction == "decode":
  10.         shift_ *= -1
  11.     for letter in text_:
  12.         position = alphabet.index(letter)
  13.         new_position = position + shift_
  14.         end_text += alphabet[new_position]
  15.     print(f"The {direction}d text is {end_text}")
  16.  
  17. caesar(direction, text, shift)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement