使用Python在字典中进行简单比较

问题描述 投票:0回答:1
import hashlib
import csv
with open ('C:\Python\Test\Hash.csv') as hash_file:
    # file_reader = csv.DictReader(hash_file)
    file_reader = csv.reader(hash_file)
    # counter = 0
    mydict = dict(filter(None,csv.reader(hash_file)))
    for i in range(1000,10000):
        bank_of_hash = hashlib.sha256(str(i).encode()).hexdigest()
        bank_of_hash={i:bank_of_hash}
    for counter in range(1,11):
        # counter +=1
        if mydict.values() == bank_of_hash.values():     
           print("This is your %s hash and this is the $a your decode" %(i,row))
        else:
            print("Password Not Found!!!")

大家好,首先,谢谢您对我的帮助。其次,它是如此简单,我不知道为什么它不起作用。

1-I导入库。2将其打开为hash_file3-这是我的hash.csv文件

  • Jadi,9553627933b214db60798fe40d2b4f8497781d024f53d62dc1b12469b7d53784Jafar,58763bceaddcad6777063dd590cb8e50211b6bb7a11272110fef4060142ded20Jobra,08f88745513481cad0adf1ae0b225d6167ec690c2bc6d38558cb8ae399ce3bdb彼得,99b057c8e3461b97f8d6c461338cf664bc84706b9cc2812daaebf210ea1b9974Noroozi,996d7e2bc68410d18cf83438acaf9f8c81db7f7e4dd1c1116b52a1da57beaee3Sam,d70ada757917455ce5a436e921854e35871e9e368050c3681c94ca9435c71c66MahdimRa,1076c5957d3ea9ffad332d1a3785b90bc658dab676c9ba822c8fe55a3e6c23b4Saghi,2876370ec5a463a2b84a7512e3dae1229460b5fe6c31b83ffabf2be977f7247bNavid,85432a9890aa5071733459b423ab2aff9f085f56ddfdb26c8fae0c2a04dce84c

4-我阅读了CSV文件,然后将其转换为字典5-我知道我的哈希值是1000-100006-用键和值制作了一个哈希字典7-I我唯一想做的就是两个字典之间的简单比较。

python dictionary encryption hash comparison
1个回答
0
投票

我已经尝试运行您的代码,但是无法将哈希文件中的数据解析为字典,因此我将代码修改为此并工作:

import hashlib

hash_data = dict()

with open ('C:\Python\Test\Hash.csv') as hash_file:
    for line in hash_file.read().split():
        hash_data[line.split(',')[0]] = line.split(',')[1]

for i in range(1000,10000):
    bank_of_hash = hashlib.sha256(str(i).encode()).hexdigest()

    for key in hash_data:
        if hash_data[key] == bank_of_hash:
            print(key, ':', i)
© www.soinside.com 2019 - 2024. All rights reserved.