Skip to content

Instantly share code, notes, and snippets.

@GuiMarthe
Created September 19, 2017 21:06
Show Gist options
  • Select an option

  • Save GuiMarthe/57ff9daced41a1bf20c055f8cc67e39f to your computer and use it in GitHub Desktop.

Select an option

Save GuiMarthe/57ff9daced41a1bf20c055f8cc67e39f to your computer and use it in GitHub Desktop.
Implementando uma simples cifra de cesar mostrando compreensões de lista e dicionários + alguns métodos de string
import string
letras = string.ascii_lowercase
texto = input('Digite o seu texto: ').lower()
k = int(input('Digite a quantidade de vezes que o seu texto se deslocará: '))
chave = {letra:letras[(i + k) % len(letras)] for i, letra in enumerate(letras + ' ')}
mensagem_codificada = ''.join([chave[letra] for letra in texto])
print('A sua mensagem encriptada é: \n{}'.format(mensagem_codificada))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment