Last active
December 20, 2015 20:28
-
-
Save NickBeeuwsaert/6190392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import sys | |
import time | |
import string | |
import random | |
import hashlib | |
import os | |
out = "ERROR: No argument was given or the given argument was invalid." | |
try: | |
elp = time.time()#int(time.time() * 1000) | |
psw = sys.argv[3] | |
ins = sys.argv[2] | |
slt = int(sys.argv[1]) | |
anp = list(string.lowercase + string.uppercase + string.digits + string.punctuation) | |
out = "" | |
# I guess it is recommended that the salt size be at least the size of the hash | |
if slt % 8 != 0: | |
out = "ERROR: Salt length not a multiple of 8" | |
raise Exception | |
if ins.lower() in hashlib.algorithms: | |
h = hashlib.new(ins.lower()); | |
else: | |
out = "ERROR: Unsupported Algorithm." | |
raise Exception | |
if slt == 0: | |
slt = h.digest_size() | |
print("No salt length given, generating a %d size hash"%(slt, )); | |
h.update(psw) | |
if slt != 0: | |
slt = os.urandom(slt); | |
h.update(slt); | |
print("String Hashed......: %s" % psw) | |
print("Salt Generated(hex): %s" % slt.encode("hex")) | |
#print("Regular Digest: %s" % h.digest()) | |
print("Hex Digest.........: %s" % h.hexdigest()) | |
print("Digest Size........: %d bytes" % int(h.digest_size()) | |
print("Block Size.........: %d bytes" % int(h.block_size()) | |
print(" ") | |
out = "Time Elapsed.......: %d" % int((time.time()-elp) * 1000) | |
finally: | |
sys.exit(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment