Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Created November 16, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/5299aa48e2389fce93ecee25b108cab1 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/5299aa48e2389fce93ecee25b108cab1 to your computer and use it in GitHub Desktop.
caesar python version
import sys
if len(sys.argv) != 2:
print("Usage: python3 caesar.py key")
sys.exit(0)
key = int(sys.argv[1])
message = input("enter a secret message: ")
def cipher(letter, key):
if not letter.isalpha():
return letter
offset = 65 if letter.isupper() else 97
return chr(((ord(letter) - offset) + key) % 26 + offset)
print(f"userinput: {message}")
print("decoded_text: " + ''.join([cipher(letter, key * -1) for letter in message]))
print("coded_text: " + ''.join([cipher(letter, key) for letter in message]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment