Created
July 3, 2021 22:47
-
-
Save BrunoMoraes-Z/4fb155da746ccca592b11686895b9284 to your computer and use it in GitHub Desktop.
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
import string | |
alfabetoMinusculo = string.ascii_lowercase | |
alfabetoMaiusculo = string.ascii_uppercase | |
def encode(message, decode=False): | |
result = '' | |
for l in message: | |
if l in alfabetoMinusculo or l in alfabetoMaiusculo: | |
posicao = getLetterPosition(l) | |
posicao = ((posicao + 4) if decode else (posicao - 4)) % 26 | |
result = result + (alfabetoMaiusculo[posicao].upper() if l.isupper() else alfabetoMinusculo[posicao]) | |
else: | |
result = result + l | |
return result | |
def getLetterPosition(letter): | |
return alfabetoMinusculo.find(letter) if letter.islower() else alfabetoMaiusculo.find(letter) | |
msg = 'testando mensagem para ser cifrada' | |
print(msg) | |
print(encode(msg)) | |
print(encode(encode(msg), True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment