Skip to content

Instantly share code, notes, and snippets.

@jh00nbr
Created July 6, 2015 19:29
Show Gist options
  • Save jh00nbr/42ca35645d2176eb6844 to your computer and use it in GitHub Desktop.
Save jh00nbr/42ca35645d2176eb6844 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#Exemplo encrypt e decrypt by jh00n - Cifra de Cesar
import sys
def encrypt(mensagem):
cifra = ''
mensagem = mensagem.lower()
for letras in mensagem:
if letras in alfabeto:
x = alfabeto.find(letras) + chave
if x >= total:
x -= total
cifra += alfabeto[x]
return cifra
def decrypt(mensagem):
cifra = ''
mensagem = mensagem.lower()
for letras in mensagem:
if letras in alfabeto:
x = alfabeto.find(letras) - chave
cifra += alfabeto[x]
return cifra
if(len(sys.argv) < 4):
print "[+] Modo de uso: ./cifra.py <chave> <mensagem> <--encrypt>"
print "[+] Exemplo: ./cifra.py 3 aka --encrypt"
else:
alfabeto = 'abcdefghijklmnopqrstuvwxyz'
total = 26
chave = int(sys.argv[1])
msg = str(sys.argv[2])
if "--encrypt" in sys.argv[3]:
print "[+] Mensagem: " + encrypt(msg)
elif "--decrypt" in sys.argv[3]:
print "[+] Mensagem: " + decrypt(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment