我有一个哈希表和它们的出现列表.我想获取出现次数(分号后的数字) [英] I have a list of hashes and their occurrences. I want to get the number of occurrences (the number after the semicolon)

查看:23
本文介绍了我有一个哈希表和它们的出现列表.我想获取出现次数(分号后的数字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码.它获取一个已泄漏的哈希列表.我想检查我的密码.我想要它做的是,当它发现它使我退回已泄漏(如果有的话)发生的次数时.如何做到这一点?例如,假设我们的必要哈希恰好是第二个哈希,因此我们要提取数字3.我们已经拥有的是它的哈希值.它被命名为结束".如您在代码中所见.

Here is my code. It gets a list of hashes, which are leaked. I want to check my password against it. What I want it to do, is to, when it finds it to throw me back the number of occurrences it has been leaked, if at all. How can this be accomplished? For example sake, let's say our necessary hash happens to be the 2nd one and thus we want to extract the number 3. What we have already is the hash infront of it. It is named "ending" as you can see in the code.

import hashlib
import requests


password = input("Enter password: ")

encoded_str = password.encode()
hash_obj = hashlib.sha1(encoded_str)
hashed = hash_obj.hexdigest().upper()

beginning = hashed[:5]
ending = hashed[5:].strip()
response = requests.get("https://api.pwnedpasswords.com/range/"+beginning)
output = response.text
listing = output.split()
print(listing)

输出:

<代码> [ '0015711CF2308DD93DC449B888F9805B728:1', '0083F4473656452B43073DF2861FD289F63:3', '0DE17FB8EC56DD673FF3AF94BAB5029BFF2:1', '0DEC778F27B49DECF0E7C3B8AB2DD152990:15', '0E8EEF1620F095A7A26F679388A02EFEA4C:2', '0FD09EF75E6654D1E2FB5FC715A11331B6D:2', '11CFB41389B28F08B74A17851292D086922:1','12A7DE6568963683AA7D21E3FBA1A1B5D39:1' , '12B602E54A280622E21FC57607D70F9E3D6:4', '133B5AFB8798339FF1BF29DBBD068DFB556:2912', '13723F1F53E4468943870CA48E2093C0531:5', '139946DFB7AA0936F96DFB9B27931508AC3:1', '13AB10DBA939781F0416361A25024EF0D8C:4', '13E2A779A5F3F6C4BA21F23A5FB949DE347:2', '52CFB9745616A23A369EA5AD9D480DFE8E9:1',52F07FB24866744C9E7D7460A04C143AAA3:2']

我们的目标输出: 3

推荐答案

尝试使用此代码:

num = 0
for line in listing:
    if ending in line:
        num = line.split(':')[1]
        break
else:
    print("the 'ending' is not in 'listing'")

这篇关于我有一个哈希表和它们的出现列表.我想获取出现次数(分号后的数字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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