Last active
May 21, 2018 17:50
-
-
Save diogomartino/909c2877529ae00d7a4411c7d8b1e748 to your computer and use it in GitHub Desktop.
Caesar Cipher Python (Cifra de César)
This file contains hidden or 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
lista = [" ", "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","w","z"] | |
def encode(text, offset): | |
encodedText = "" | |
for i in range(len(text)): | |
letterIndex = -1 | |
for a in range(len(lista)): | |
if lista[a] == text[i]: | |
letterIndex = a | |
if letterIndex + offset > len(lista) + 1: | |
resto = int(letterIndex + offset - (len(lista) + 1)) | |
encodedText += lista[resto] | |
else : | |
encodedText += lista[letterIndex + offset] | |
return encodedText | |
def decode(text, offset): | |
decodedText = "" | |
for i in range(len(text)): | |
letterIndex = 0 | |
for a in range(len(lista)): | |
if lista[a] == text[i]: | |
letterIndex = a | |
decodedText += lista[letterIndex - offset] | |
return decodedText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment