#!/usr/bin/env python
# Hash-generator
import hashlib
import random

def main():
    q = 2
    while q != 10:
        print "Enter 1 to run a MD5    hash on your password"
        print "Enter 2 to run a SHA1   hash on your password"
        print "Enter 3 to run a SHA224 hash on your password"
        print "Enter 9 to get a new randomy password"
        print "Enter 10 to run away...  he he he\n"
        q = input("Enter your choice here> ")
        if q == 1:
            md_five()
        elif q == 2:
            sha_one()
        elif q == 3:
            sha_224()
        elif q == 9:
            new_pass()

def md_five():
        print "Enter a password and find the MD5 hash"
        passwd = raw_input("Enter your password for testing: ")
        m = hashlib.md5()
        m.update(passwd)
        print passwd, " | ", m.digest(), "\n hash in hex. | ", m.hexdigest()
        print ""

def sha_one():
        print "Enter a password and find the SHA1 hash"
        passwd = raw_input("Enter your password for testing: ")
        m = hashlib.sha1()
        m.update(passwd)
        print passwd, " | ", m.digest(), "\n hash in hex. | ", m.hexdigest()
        print ""


def sha_224():
        print "Enter a password and find the SHA1 hash"
        passwd = raw_input("Enter your password for testing: ")
        m = hashlib.sha224()
        m.update(passwd)
        print passwd, " | ", m.digest(), "\n hash in hex. | ", m.hexdigest()
        print ""

def new_pass():
    series = ['`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', \
              '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', \
              'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', \
              'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|', \
              'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", \
              'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', \
              'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', \
              'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?']
    passwd = []
    p = input("Enter the length you want your password to be: ")
              # length of password
    for i in range(p):
        r = random.randint(0, 94)
        passwd.append(series[r]) # Append a random char from series[] to passwd
    #print passwd
    #print passwd[0], passwd[1], passwd[2], passwd[3]
    print ""
    print "".join(map(str, passwd)), " is your new password. \n"
    
     

    # TODO - complete modules for sha256(), sha384(), and sha512()
    # Constructors for hash algorithms that are always
    # present in the hashlib module are
    # md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
    
main()
