Skip to content

Instantly share code, notes, and snippets.

@BrunoMoraes-Z
Created July 3, 2021 22:47
Show Gist options
  • Save BrunoMoraes-Z/4fb155da746ccca592b11686895b9284 to your computer and use it in GitHub Desktop.
Save BrunoMoraes-Z/4fb155da746ccca592b11686895b9284 to your computer and use it in GitHub Desktop.
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