Find a word in a file with a given SHA-256 hex digest Python


This Content is from Stack Overflow. Question asked by Michael Garrido

I’m trying to find a word whose ASCII encoding has the following SHA-256 hex digest:
“69d8c7575198a63bc8d97306e80c26e04015a9afdb92a699adaaac0b51570de7” using the hashlib.

With my code a accomplished to sort through the file and return the digest that matches but i need it into an actual word , i know that hash cant be decrypted so i need help with the logic on how to print the actual word.

here is my code:

import hashlib

def q1 ():

    file = open("words.txt","r")
    for x in file : 
        x = x.strip('n')
        x = (hashlib.sha256(x.encode("ascii", "ignore")).hexdigest())
        wordFound ="69d8c7575198a63bc8d97306e80c26e04015a9afdb92a699adaaac0b51570de7"

        if x == wordFound:
            print (x)


this is the list of words:


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?