Skip to content

Instantly share code, notes, and snippets.

@AO8
Created March 3, 2018 23:57
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save AO8/3a89ba7c8f032c7a1ff505baa3ce970e to your computer and use it in GitHub Desktop.
Save AO8/3a89ba7c8f032c7a1ff505baa3ce970e to your computer and use it in GitHub Desktop.
Simple Caesar Cipher Python decryption function.
import string
from time import sleep
alphabet = string.ascii_lowercase # "abcdefghijklmnopqrstuvwxyz"
def decrypt():
print("Welcome to Caesar Cipher Decryption.\n")
encrypted_message = input("Enter the message you would like to decrypt: ").strip()
print()
key = int(input("Enter key to decrypt: "))
decrypted_message = ""
for c in encrypted_message:
if c in alphabet:
position = alphabet.find(c)
new_position = (position - key) % 26
new_character = alphabet[new_position]
decrypted_message += new_character
else:
decrypted_message += c
print("\nDecrypting your message...\n")
sleep(2) # give an appearance of doing something complicated
print("Stand by, almost finished...\n")
sleep(2) # more of the same
print("Your decrypted message is:\n")
print(decrypted_message)
decrypt()
@Ndichuh-Consultants
Copy link

Thanks for the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment