0

My hashes are different with standard sha256

How can I hash each list number to sha256 with hashlib in python?

you can see my result and other online converter results:

#hash 9999 from https://emn178.github.io/online-tools/sha256.html
    
    888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05
    
#hash 9999 from https://www.online-convert.com/result#j=96f7a8bb-2c97-4c6c-ae6d-7deda4f62e3c

    888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05

#hash 9999 from https://passwordsgenerator.net/sha256-hash-generator/

    888DF25AE35772424A560C7152A1DE794440E0EA5CFEE62828333A456A506E05





my sha256 hash of 9999:

       
    877f59e9e62b9f0bfdc877653856410990e8aba4ac8b55ad06cd8cf5ecdfbc17

this is my code. Anyone can teach me how I can fix that?

import CSV
from hashlib import sha256

hash_dic = {}
numbers = []
count = 1

#make number range between 1 t0 9999
while count <= 9999:
    numbers.append(count)
    count += 1

#make hash sha256 dic
for number in numbers:
    hashed = sha256(bytes(number)).hexdigest()
    hash_dic[number] = hashed


#open csv file and maining hashes
with open("Desktop/passwords.csv") as passwrd:
    reader = csv.reader(passwrd)
    for row in reader:
        csv_hash = row[1]
        
        for key,value in hash_dic.items():
            if csv_hash == value:
                print(f"for {row[0]} password is {key}")
            else:
                pass

print(hash_dic)
#print(number)

1 Answer 1

0

On the online sites you mentioned, you are inputting a string '9999', probably in ASCII or UTF8. You need to pass the same byte array to the hashlib.

import hashlib
hashlib.sha256(str(9999).encode()).hexdigest()
# --> 888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05

If you really want to pass an integer as its byte representation, not as a string, then How to hash int/long using hashlib in Python? will help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.