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

Issue

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)



q1()

this is the list of words:

https://inst-fs-iad-prod.inscloudgate.net/files/a405f779-7d37-41fe-ac80-30712573f273/dict.txt?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NjM0MDA0MjcsInVzZXJfaWQiOiIxMTgxMDAwMDAwMDE0OTEzOSIsInJlc291cmNlIjoiL2ZpbGVzL2E0MDVmNzc5LTdkMzctNDFmZS1hYzgwLTMwNzEyNTczZjI3My9kaWN0LnR4dCIsImp0aSI6ImE0NGQ4MjEyLTcwM2MtNGYwZC04ZmNiLTRmOTJjMzMyNGEzMSIsImhvc3QiOiJmaXUuaW5zdHJ1Y3R1cmUuY29tIiwib3JpZ2luYWxfdXJsIjoiaHR0cHM6Ly9hMTE4MS0yMzQ2NzQ1NS5jbHVzdGVyODUuY2FudmFzLXVzZXItY29udGVudC5jb20vY291cnNlcy8xMTgxfjE0MTc3NC9maWxlcy8xMTgxfjIzNDY3NDU1L2NvdXJzZSUyMGZpbGVzL2RpY3QudHh0P2NvbnRleHRfaWQ9MTE4MX4xNDE3NzRcdTAwMjZjb250ZXh0X3R5cGU9Q291cnNlXHUwMDI2ZG93bmxvYWQ9MVx1MDAyNmlkPTExODEwMDAwMDIzNDY3NDU1XHUwMDI2aW5saW5lPTFcdTAwMjZub19jYWNoZT10cnVlXHUwMDI2cmVkaXJlY3Q9dHJ1ZSIsImV4cCI6MTY2MzQ4NjgyN30.VL380_FMQhjjUMatFJNHkJSW-e__o6fS7idrpcCSA94atgpTQVAQtMZmm-YxX2pJYm3OaxP1bUej8GgY4nvxMg



Solution

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?