CifraMe

Iniciado por [Z]tuX, Abril 13, 2013, 01:50:06 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Un proyecto que dejé pendiente hace tiempo, ahora con mejoras en el código y ahora trabaja bajo Python 3.x
Código: python

#!/usr/bin/env python3

#It Works with Python 3.x.x
# -*- coding:UTF-8 -*-

import sys, base64, hashlib, hmac

name = "CifraMe"
ver = "2.7"
author = "@_ZtuX_"

listHash=["-md5","-sha","-sha256","-sha384","-sha512","-hmac","-b64","-db64"]

def banner():
    print ("""
___ _________   _            __   __   
|  _|___  /_  | | |           \ \ / /   
| |    / /  | | | |_   _   _   \ V /     
| |   / /   | | | __| | | | |  /   \     
| | ./ /___ | | | |_  | |_| | / /^\ \   
| |_\_____/_| |  \__|  \__,_| \/   \/   
|___|     |___|                       
    """)

class CifraMe:
    def __init__(self,string,hash):
        self.string=string
        self.hash=hash
    def md5(self):       
        return (hashlib.md5((self.string).encode()).hexdigest())
    def sha(self):
        return hashlib.sha1((self.string).encode()).hexdigest()
    def sha256(self):
        return hashlib.sha256((self.string).encode()).hexdigest()
    def sha384(self):
        return hashlib.sha384((self.string).encode()).hexdigest()
    def sha512(self):
        return hashlib.sha512((self.string).encode()).hexdigest()
    def Hmac(self):
        return hmac.new((self.string).encode()).hexdigest()
    def code_base64(self):
        new = base64.b64encode((self.string).encode('ascii'))
        return (new.decode())
    def decode_base64(self):
        new = " "
        try:
            new = base64.b64decode((self.string).encode('ascii'))
        except:
            print ("Palabra erronea")
        return (new.decode())
    @property
    def tamanioString(self):
        return len(self.string)
     
         
def showHelp():
    print ("""
      _  __           ______  ___    ___
     (_)/ _|         |  _|  \/  |   |_  |
  ___ _| |_ _ __ __ _| | | .  . | ___ | |
/ __| |  _| '__/ _` | | | |\/| |/ _ \| |
| (__| | | | | | (_| | | | |  | |  __/| |
\___|_|_| |_|  \__,_| |_\_|  |_/\___|| |
                     |___|          |___|   
==============================================
   Visita: http://ztux.blogspot.com/
==============================================
[+] Modo de uso: %s [Palabra] [Hash]
[+] Ejemplo: %s Cifrar_esto -md5
   
-h         Muestra esto en pantalla
-v         Muestra la Version del Programa
   
-md5       Cifrar en MD5
-sha       Cifrar en sha1
-sha256    Cifrar en sha256
-sha384    Cifrar en sha384
-sha512    Cifrar en sha512
-hmac      Cifrar en hmac
 
-b64       Codifica en base64
-db64      Decodifica en base64
"""%(sys.argv[0],sys.argv[0]))

def main():
    if (len(sys.argv)==1) or sys.argv[1].lower()=="-h" or sys.argv[1].lower()=="--help":
        showHelp()
    elif (len(sys.argv) > 3):
        print ("ERROR...\nModo de uso: %s [Palabra] [Hash]"%(sys.argv[0]))
    elif (sys.argv[1].lower()=='-v' or sys.argv[1].lower()=='--version'):
        print ("%s version: %s\nAutor: %s"% (name,ver,author))
    elif (sys.argv[1].lower()=='-b'):
        banner()
    elif (len(sys.argv)==3):
        """Si hay tres argumentos entonces podemos cifrar a gusto"""
        #Checks if second argument is correct
        hash = sys.argv[1].lower()
        string = sys.argv[2]
        if (hash in listHash):
            cadena = CifraMe(string,hash)
            #Identify Hash
            pos = listHash.index(hash)
            if (pos==0):
                print (cadena.md5())
            elif (pos==1):
                print (cadena.sha())
            elif (pos==2):
                print (cadena.sha256())
            elif (pos==3):
                print (cadena.sha384())
            elif (pos==4):
                print (cadena.sha512())
            elif (pos==5):
                print (cadena.Hmac())
            elif (pos==6):
                print (cadena.code_base64())
            elif (pos==7):
                print (cadena.decode_base64())
            return (0)
        else:
            print ("La hash %s no es valida" % (hash) )
            return (-1)
    else:
        print ("Error: usa -h o --help para mas información")
         
if __name__ == '__main__':
main()


Captura:

Salud[OS]

Tiempo sin verte por el foro bro!
Excelente aporte! Muchas gracias!


You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Tiempo sin verte por el foro bro!
Excelente aporte! Muchas gracias!

Si verdad, pues por acá estaremos de nuevo =)
Un Saludo

El viejo ztux por acá ;D muy bueno brot, en un rato me pongo a jugar :P
Zalu2
Sólo el conocimiento te hace libre.

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
El viejo ztux por acá ;D muy bueno brot, en un rato me pongo a jugar :P
Zalu2
Gracias bro! Tiempo sin estar por acá!
Un saludo!!  8)