Created
September 1, 2018 18:49
-
-
Save math77/e48eea08c3ba26b8f968f94e84045d5f to your computer and use it in GitHub Desktop.
Exemplo de criptografia utilizando a Cifra de César.
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
from string import ascii_lowercase as lower | |
tam = len(lower) | |
def criptografar(palavra, salto): | |
cifra = [] | |
for letra in palavra: | |
cifra.append(lower[(lower.index(letra) + salto) % tam]) | |
return ''.join(cifra) | |
def descriptografar(palavra, salto): | |
cifra = [] | |
for letra in palavra: | |
cifra.append(lower[(lower.index(letra) - salto) % tam]) | |
return ''.join(cifra) | |
cripto = criptografar("matheus", 3) | |
descr = descriptografar(cripto, 3) | |
print("Criptografada: {}".format(cripto)) | |
print("Descriptografada: {}".format(descr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment