【发布时间】:2021-05-14 18:06:06
【问题描述】:
我是 python 新手,目前正在攻读 IT 硕士学位。我正在从哈希值中解码密码。
这就是我目前的设置方式。我知道这是错误的,任何帮助将不胜感激。
import itertools
import time
from Crypto.Hash import SHA3_512
# Function to brute force the password
def tryPassword(passwordSet):
start = time.time()
# Allowed characters in the password
chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?"
attempts = 0
for value in range(1, 9):
# Build up a string to test against, character by character
for letter in itertools.product(chars, repeat=value):
attempts += 1
letter = ''.join(letter)
hash_object = SHA3_512.new()
hash_object.update((letter).encode("utf-8"))
tmp_hash = hash_object.hexdigest()
print(tmp_hash)
#if the string we are building matches the password given to us, return from the function
if tmp_hash == passwordSet:
end = time.time()
distance = end - start
return (attempts, distance)
password = input("Password >")
tries, timeAmount, = tryPassword(password)
print("The password %s was cracked in %s tries and %s seconds!" % (password, tries, timeAmount))
【问题讨论】:
-
该函数需要将哈希密码作为参数。然后在循环中生成密码后,必须对其进行哈希处理并与参数进行比较。
标签: python hash sha brute-force