【问题标题】:How can I generate a password from SHA3-512 hash value?如何从 SHA3-512 哈希值生成密码?
【发布时间】:2021-02-06 22:30:38
【问题描述】:

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

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))

【问题讨论】:

    标签: python-3.x hash python-3.7 sha brute-force


    【解决方案1】:

    您的代码目前不使用哈希来查找密码。相反,您当前会遍历您的字母表以匹配您也输入的密码。

    您需要将散列密码而不是实际密码传递给您的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, tries, timeAmount))
    

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 2017-10-15
      • 2016-02-06
      相关资源
      最近更新 更多