#!/usr/bin/python import string import sys class cifra_cesar(object): alfabeto = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] def __init__(self): self.menu() def menu(self): while(1): print "1. Criptografar\n2. Descriptografar\n3. Sair\n: \r" try: opcao = int(raw_input()) if opcao > 3: continue elif opcao == 3: break return break except: continue print "Digite o texto: " texto = string.lower(raw_input()) while(1): print "Digite o k: " try: k = int(raw_input()) break except: continue if opcao == 1: print self.crypt_descrypt("c", texto, k) elif opcao == 2: print self.crypt_descrypt("d", texto, k) def crypt_descrypt(self, opcao, texto, k): nova_frase = "" for letra in texto: j = 0 for carac in self.alfabeto: j += 1 if letra == " ": nova_frase += " " break elif letra == carac: if opcao == "c": posicao = j+k-1 while(1): if posicao >= self.alfabeto.__len__(): posicao = posicao - int(self.alfabeto.__len__()) else: break nova_frase += str(self.alfabeto[posicao]) else: posicao = j-k-1 while(1): if posicao >= self.alfabeto.__len__(): posicao = posicao + int(self.alfabeto.__len__()) else: break nova_frase += str(self.alfabeto[posicao]) break elif carac == self.alfabeto[int(self.alfabeto.__len__()) -1]: nova_frase += letra return nova_frase[::-1] def main(): c = cifra_cesar() exit if __name__ == "__main__": main()