Last active
February 11, 2019 13:02
-
-
Save junquera/4b630871824dc8981776d2d13983c432 to your computer and use it in GitHub Desktop.
Generación de hashes
This file contains hidden or 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
import hashlib | |
def sha1(i): | |
return hashlib.sha1(i).hexdigest() | |
def scrypt(i, sal): | |
''' | |
n = CPU/memory cost parameter | |
r = tamaño del bloque | |
p = paralelización | |
''' | |
return hashlib.scrypt(i, salt=sal, n=1024, r=100, p=10).hex() | |
def pbkdf2(i, sal): | |
return hashlib.pbkdf2_hmac('sha1', i, sal, 10000).hex() | |
def md5(i): | |
return hashlib.md5(i).hexdigest() | |
def sha256(i): | |
return hashlib.sha256(i).hexdigest() | |
import random | |
def gen_salt(): | |
return random.randint(0, 2**(8*4)).to_bytes(4, 'big') | |
def gen_pepper(): | |
return random.randint(0, 2**(8*2)).to_bytes(2, 'big') | |
with open('passwords.txt') as f: | |
passwords = f.read().split('\n') | |
import time | |
# padded_password = "password" + " "*(20-len("password")) | |
# print(padded_password + "\tmd5\t\t\t\t\tsha1\t\t\t\t\tsha256\t\t\t\t\t\t\t\t\t\t\t\t\tpbkdf2\t\t\t\t\t\t\tscrypt") | |
for password in passwords: | |
if len(password) <= 0: | |
continue | |
print("- Password: %s" % password) | |
password_aux = password.encode() | |
pimienta = gen_pepper() | |
sal = gen_salt() | |
t0 = time.time() | |
md5_hash = md5(password_aux) | |
t = time.time() - t0 | |
print("\t- md5 (%0.4fs): %s" % (t, md5_hash)) | |
t0 = time.time() | |
sha1_hash = sha1(password_aux) | |
t = time.time() - t0 | |
print("\t- sha1 (%0.4fs): %s" % (t, sha1_hash)) | |
t0 = time.time() | |
sha256_hash = sha256(password_aux) | |
t = time.time() - t0 | |
print("\t- sha256 (%0.4fs): %s" % (t, sha256_hash)) | |
t0 = time.time() | |
pbkdf2_hash = pbkdf2(password_aux, pimienta) | |
t = time.time() - t0 | |
print("\t- pbkdf2 (%0.4fs): %s" % (t, pbkdf2_hash)) | |
t0 = time.time() | |
scrypt_hash = scrypt(password_aux, sal) | |
t = time.time() - t0 | |
print("\t- scrypt (%0.4fs): %s" % (t, scrypt_hash)) | |
# padded_password = password + " "*(20-len(password)) | |
# print("%s\t%s\t%s\t%s\t%s\t%s" % (padded_password, md5_hash, sha1_hash, sha256_hash, pbkdf2_hash, scrypt_hash)) |
This file contains hidden or 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
Password | |
1967 | |
Matusalem | |
JuanPerez | |
JuanPerez2 | |
ElEnterrador17 | |
123456 | |
123456789 | |
111111 | |
password | |
qwerty | |
abc123 | |
12345678 | |
password1 | |
1234567 | |
123123 | |
JjeupLjRD-N?4_9h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment