Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=====================================#
- #==============MODULES================#
- #=====================================#
- import hashlib
- #=====================================#
- #==============VARIABLES==============#
- #=====================================#
- chunk_size = 8192
- menu = ["(1) MD5 ", "(2) MD4 ", "(3) SHA-1 ", "(4) SHA-224", "(5) SHA-256", "(6) SHA-384", "(7) SHA-512", "(8) RIPEMD ", "(9) Exit "]
- #=====================================#
- #==============FUNCTIONS==============#
- #=====================================#
- #creates hash menu
- def hash_menu(menu):
- print "+================+"
- print "| HASH MENU |"
- print "+================+"
- for word in menu:
- print "| %s |" % word
- print "|----------------|"
- print
- #reads in file to hash | creates new file and saves hash to file | prints hash to screen
- def hash_file(filename, hash_type, var):
- with open(filename, 'rb') as f:
- for data in iter(lambda: f.read(chunk_size), b''):
- hash_type.update(data)
- output = hash_type.hexdigest()
- print
- saved_file = str(var) + "_hash_" + filename
- print "Saved %s hash to %s" % (var, saved_file)
- print
- file = open(saved_file, "w")
- file.write(filename + ": " + var + ": " + output)
- file.close()
- print "Hash Written Successfully!"
- print
- print "%s: %s" % (var, output)
- print
- #=====================================#
- #=============MAIN PROGRAM============#
- #=====================================#
- def main():
- print "This program hashes a file with a hashing function."
- print
- print
- #display hash menu
- hash_menu(menu)
- #user select hash type
- choice = input("Please select a hash type (1-9): "
- #user defines file to hash
- filename = raw_input("Please enter a file to hash: ")
- #MD5
- if choice == 1:
- var = "MD5"
- hash_type = hashlib.md5()
- hash_file(filename, hash_type, var)
- return
- #MD4
- elif choice == 2:
- var = "MD4"
- hash_type = hashlib.new('md4')
- hash_file(filename, hash_type, var)
- return
- #SHA-1
- elif choice == 3:
- var = "SHA-1"
- hash_type = hashlib.sha1()
- hash_file(filename, hash_type, var)
- return
- #SHA-224
- elif choice == 4:
- var = "SHA-224"
- hash_type = hashlib.sha224()
- hash_file(filename, hash_type, var)
- return
- #SHA-256
- elif choice == 5:
- var = "SHA-256"
- hash_type = hashlib.sha256()
- hash_file(filename, hash_type, var)
- return
- #SHA-384
- elif choice == 6:
- var = "SHA-384"
- hash_type = hashlib.sha384()
- hash_file(filename, hash_type, var)
- return
- #SHA-512
- elif choice == 7:
- var = "SHA-512"
- hash_type = hashlib.sha512()
- hash_file(filename, hash_type, var)
- return
- #RIPEMD
- elif choice == 8:
- var = "RIPEMD"
- hash_type = hashlib.new('ripemd160')
- hash_file(filename, hash_type, var)
- return
- #Exit
- elif choice == 9:
- print "Goodbye. Ending Program..."
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement