python相同的字符串但不同?

问题描述 投票:0回答:1

我不知道为什么这样无法按照我希望的方式工作。我有一个带有一些常用密码的文本文件(例如,password,00001111),我想用一个盐对它们进行哈希处理。但是使用

a = hashlib.sha3_256('AlwaysUseADifferentSalt00001111'.encode('utf-8')).hexdigest()
print(a)
>>>6008992e30a56dbab6825064078ca585ad1b981a4c461ffb46dbd088377ac3ae

salt = 'AlwaysUseADifferentSalt'
password = '00001111'
key = salt + password
a = hashlib.sha3_256(key.encode('utf-8')).hexdigest()
print(a)
>>>d6fdd92f39dd760bd372c035f76a7253b58d176b3f1e74d293218d2801d1b701

即使key = AlwaysUseADifferentSalt00001111,也会给我不同的结果

编辑:为了澄清一些事情,我正在尝试使用盐和给定的密码来重建哈希]

import hashlib
counter = 1

sha3_pass = 'b998c2aeb78ed8948976a7c8e3317b16ba8a7ad45764520a672c684929f51f90'
sha3_file = open("Top12Thousand.txt")
salt = 'AlwaysUseADifferentSalt'

for password in sha3_file:
    key = salt + password
    hash_obj = hashlib.sha3_256(key.encode('utf-8')).hexdigest()
    #print("Trying Password %d : %s " % (counter,password.strip()))
    counter += 1

    if hash_obj == sha3_pass:
        print("\nPassword Found!!! Password Is : %s " % password)
        break
    #else:
        #print("\n password Not Found")

带有https://raw.githubusercontent.com/berzerk0/Probable-Wordlists/master/Real-Passwords/Top12Thousand-probable-v2.txt中的列表由于我无法弄清楚脚本为何无法正常工作,因此我检查了盐值,如果我在看到一些差异的情况下插入了整个字符串,则会得到盐值

python string hash error-handling logic
1个回答
0
投票

这应该起作用:

import hashlib
counter = 1

sha3_pass = 'b998c2aeb78ed8948976a7c8e3317b16ba8a7ad45764520a672c684929f51f90'
sha3_file = open("testfile.txt")
salt = 'AlwaysUseADifferentSalt'

for password in sha3_file:
    key = salt + password.strip()
    hash_obj = hashlib.sha3_256(key.encode('utf-8')).hexdigest()
    #print("Trying Password %d : %s " % (counter,password.strip()))
    counter += 1

    if hash_obj == sha3_pass:
        print("\nPassword Found!!! Password Is : %s " % password)
        break
    #else:
        #print("\n password Not Found")

您可以看到,唯一的变化是在第9行(key = salt + password.strip())上删除了密码

© www.soinside.com 2019 - 2024. All rights reserved.