如何从SHA3-512哈希值生成密码? [英] How can I generate a password from SHA3-512 hash value?

查看:87
本文介绍了如何从SHA3-512哈希值生成密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出此SHA3-512哈希值的密码:11af05af85d7656ee0f2e3260760bccdc2af88dee449f682ab2e367003856166edc045c4164a4d543ea4a43d6dd022d3c290866f2d2a7a92a38400bd3a5f7ab0.我遇到的问题是,当我运行代码时,它仍然返回哈希值.我的问题是生成密码需要更改什么代码?这是运行我的代码的结果的一些屏幕截图.

I am trying to figure out the password for this SHA3-512 hash value: 11af05af85d7656ee0f2e3260760bccdc2af88dee449f682ab2e367003856166edc045c4164a4d543ea4a43d6dd022d3c290866f2d2a7a92a38400bd3a5f7ab0. The issue I am having is that when I run my code it still returns the hash value. My question is what do I need to change in my code to produce the password? Here are some screenshots of the results from running my code.

import itertools
import time
import hashlib
from binascii import hexlify
import shutil
import os

data = input("Enter Password:")
data1 = data.encode('utf-8')
sha3_512 = hashlib.sha3_512(data1)
sha3_512_digest = sha3_512.digest()
sha3_512_hex_digest = sha3_512.hexdigest()
print(sha3_512_hex_digest)


# 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, 800):
        # Build up a string to test against, character by character
        for letter in itertools.product(chars, repeat=value):
            attempts += 1
            letter = ''.join(letter)

            #if the string we are building matches the password given to us, return from the function
            if letter == passwordSet:
                end = time.time()
                distance = end - start
                return (attempts, distance)



tries, timeAmount = tryPassword(data)
print("The password %s was cracked in %s tries and %s seconds!" % (data, tries, timeAmount))

推荐答案

您的代码当前未使用哈希来查找密码.取而代之的是,您当前在字母上进行迭代以匹配您也输入的密码.

Your code currently doesn't use the hash to find the password. Instead you currently iterate over your alphabet to match the password that you've also put in.

您需要将散列的密码而不是实际的密码传递到您的 tryPassword 函数中.此外,在函数内部,您需要对生成的密码候选者进行哈希处理,并将其与传入的哈希进行比较.

You need to pass in the hashed password instead of the actual password into your tryPassword function. Additionally, inside of the function, you need to hash your generated password candidate and compare it to the passed in hash.

这是完整的代码.我已经更改了一些变量名称以使其清晰可见.

Here is the full code. I've changed some variable names to make it clear what they are.

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, tries, timeAmount))

这篇关于如何从SHA3-512哈希值生成密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆