Security and Cryptography in Python - Hash Functions(4)

Security and Cryptography in Python - Hash Functions(4)

Why iterate over hash function and demonstrated by implementation in Python

Code in Python:

import hashlib
import base64


def guess_password(salt, iterations, entropy):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    for c1 in alphabet:
        for c2 in alphabet:
            password = str.encode(c1 + c2)
            value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
            if value == entropy:
                return password
    return "".encode()


iterations = 45454
salt = base64.b64decode("6VuJKkHVTdDelbNMPBxzw7INW2NkYlR/LoW40L7kVAI=".encode())
validation = "SALTED-SHA512-PBKDF2"
entropy = "15KqQ3c+ozUsKvgNZmwU0GNT+De1x/W+/MBkotAgPnMHJ90YDrgYrQRvY4YkCdBhNs+JkStX7EjnCNWAAW5xATANwPlKwBdyFyqrkqnRyxtb+ccd2S2aflf1CwaDOGXl7RKyToGdNjPNzK0gWSaoFX7eSe6Eugnhw51ioPP/OUg=".encode()

password = "??".encode()

password = guess_password(salt, iterations, entropy)
print(password)
value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
print(value)
print(entropy)

Running Result (The password is 'pw'):

image-20210307101612265

posted @ 2021-03-07 09:36  晨风_Eric  阅读(42)  评论(0编辑  收藏  举报