Created
March 2, 2020 10:54
-
-
Save etp404/fe0ceba52476a210eb8c0a15b7fcc5a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alphabet="abcdefghijklmnopqrstuvwxyz" | |
def getLetter(index): | |
return alphabet[index] | |
def getIndex(letter): | |
return alphabet.find(letter) | |
def getEncryptedLetter(letter, key): | |
letterIndex = getIndex(letter) | |
if (letterIndex == -1): | |
return letter | |
newPosition = (letterIndex + key) % 26 | |
encryptedLetter = getLetter(newPosition) | |
print(letter, " to ", encryptedLetter) | |
return encryptedLetter | |
def encryptMessage(message, key): | |
encryptedMessage = "" | |
for letter in message: | |
encryptedMessage = encryptedMessage + getEncryptedLetter(letter, key) | |
return encryptedMessage | |
message = """ | |
what did the t-rex use to build his house? | |
dino-saw | |
""" | |
print(encryptMessage(message, 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment