Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python3 hashlib
#1
Quote:Hello, I'm trying to read and compare from an online list, through a given hash, but I'm getting this error:
Quote:Does anybody can help me please?

Error:
Traceback (most recent call last): File "c:\Users\Orlando\Documents\SandBox\MasterHckPython\hack\bruteforce1.py", line 23, in <module> main() File "c:\Users\Orlando\Documents\SandBox\MasterHckPython\hack\bruteforce1.py", line 16, in main z = hashlib.md5(p).encode() TypeError: Strings must be encoded before hashing
Quote:Used Hash: 21232f297a57a5a743894a0e4a801fc3

import hashlib
import urllib.request


def main():
    hashpass = input('Hash: ')
    req = urllib.request.urlopen('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt')
    
    passwordlist = req.read().decode('utf-8')
    print(type(passwordlist))
    for p in passwordlist.split('\n'):        
        z = hashlib.md5(p).hexdigest()
        if z == hashpass:
            print('Password: {}     HASH: {}'.format(p,z))
    
    

if __name__ == '__main__':
    main()
Quote:Regards!
Reply
#2
hashlib most have bytes as input.
line 12:
z = hashlib.md5(p.encode()).hexdigest()
I would write it like this using Requests then get correct encoding back,and in general i never use urllib.
Can drop read() as just loop over text.
import requests
import hashlib

def hash_test(hashpass):
    req = requests.get('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt')
    for password in req.text.split('\n'):
        hash_md5 = hashlib.md5(password.encode()).hexdigest()
        if hash_md5 == hashpass:
            print(f'Password: {password:<8} HASH: {hash_md5}')

if __name__ == '__main__':
    hashpass = input('Hash: ')
    hash_test(hashpass)
Test.
G:\div_code\answer
λ python hash_test.py
Hash: 81dc9bdb52d04dc20036dbd8313ed055
Password: 1234     HASH: 81dc9bdb52d04dc20036dbd8313ed055
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] How to crack hash with hashlib Milan 0 1,399 Mar-09-2023, 08:25 PM
Last Post: Milan
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,887 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  how can I generate a password in hashlib go127a 20 8,590 May-19-2019, 09:26 AM
Last Post: buran
  Confusion about Hashlib Vysero 2 2,980 Jun-25-2018, 04:05 PM
Last Post: DeaD_EyE
  Using SHA3 (keccak) from Hashlib CryptoFlo 0 7,673 Mar-14-2018, 10:56 AM
Last Post: CryptoFlo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020