Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Created July 30, 2018 02:11
Show Gist options
  • Save toshvelaga/825dbf168e9aa5aeb72fe1ef870fb09e to your computer and use it in GitHub Desktop.
Save toshvelaga/825dbf168e9aa5aeb72fe1ef870fb09e to your computer and use it in GitHub Desktop.
CS50 Ceaser python
from cs50 import cs50
alphabet = "abcdefghijklmnopqrstuvwxyz"
alphabetcap = alphabet.upper()
cyphertext = ""
word = input("Please enter in a word to be encrypted: ")
key = int(input("Please enter a numnber to use as the encryption key: "))
for letter in word:
if letter in alphabet:
newposition = (alphabet.find(letter) + key) % 26
cyphertext += alphabet[newposition]
elif letter in alphabetcap:
newposition = (alphabetcap.find(letter) + key) % 26
cyphertext += alphabetcap[newposition]
else:
cyphertext += letter
print(cyphertext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment