Last active
July 19, 2016 20:37
-
-
Save eduardoedson/4b53c26b997496e398b8fe8099e43e09 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
# -*- coding: utf-8 -*- | |
import os | |
alfabeto = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
def criptografar(normal, chave): | |
cifrado = '' | |
normal = normal.upper() | |
for letra in normal: | |
if letra in alfabeto: | |
idx = alfabeto.find(letra) + chave | |
if idx >= 26: | |
idx -= 26 | |
cifrado += alfabeto[idx] | |
return cifrado | |
def descriptografar(frase, chave): | |
normal = '' | |
frase = frase.upper() | |
for ch in frase: | |
if ch in alfabeto: | |
idx = alfabeto.find(ch) - chave | |
normal += alfabeto[idx] | |
return normal.lower() | |
# ====================================================================== | |
function = raw_input('[1] - Criptografar\n[2] - Descriptografar\n') | |
frase = raw_input('\nQual a frase?\n') | |
chave = raw_input('\nQual a chave?\n') | |
os.system('clear') | |
if int(function) == 1: | |
print('Frase: ' + frase) | |
print('Frase Cripografada: ' + criptografar(frase, int(chave))) | |
elif int(function) == 2: | |
print('Frase Cripografada: ' + frase) | |
print('Frase: ' + descriptografar(frase, int(chave))) | |
else: | |
print('Opção inválida') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment