如何解决如何从 SHA3-512 哈希值生成密码?
我正在尝试找出这个 SHA3-512 哈希值的密码:11af05af85d7656ee0f2e3260760bccdc2af88dee449f682ab2e367003856166edc045c4164a4d53206d30a2a2a28d20a30a30d30a2a2a2a30d4a2a2a3d2e3260760bccdc2 我遇到的问题是,当我运行我的代码时,它仍然返回哈希值。我的问题是我需要在代码中更改什么才能生成密码?以下是运行我的代码的结果的一些屏幕截图。
python.reg
解决方法
您的代码目前不使用哈希来查找密码。相反,您当前遍历字母表以匹配您输入的密码。
您需要将经过哈希处理的密码而不是实际密码传入您的 tryPassword
函数。此外,在函数内部,您需要对生成的候选密码进行散列,并将其与传入的散列进行比较。
这是完整的代码。我已经更改了一些变量名称以明确它们是什么。
import itertools
import time
import hashlib
from binascii import hexlify
import shutil
import os
pw = input("Enter Password:")
pw = pw.encode('utf-8')
pwHashHex = hashlib.sha3_512(pw).hexdigest()
print(pwHashHex)
# Function to brute force the password
def tryPassword(pwHashHex):
start = time.time()
# Allowed characters in the password
alphabet = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?"
attempts = 0
for value in range(1,800):
# Build up a string to test against,character by character
for pwCandidate in itertools.product(alphabet,repeat=value):
attempts += 1
pwCandidate = ''.join(pwCandidate)
#if the string we are building matches the password given to us,return from the function
if hashlib.sha3_512(pwCandidate).hexdigest() == pwHashHex:
end = time.time()
distance = end - start
return (pwCandidate,attempts,distance)
pwFound,tries,timeAmount = tryPassword(pwHashHex)
print("The password %s was cracked in %s tries and %s seconds!" % (pwFound,timeAmount))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。