2
I’m using Python 3.6 to make a program in which the person types an MD5 hash, then the program saves the hash in a variable, reads a txt file and plays the content inside a list, where each name separated by , is an item on that list.
After that, the program enters a loop where it encrypts to list item (txt) and compares with the hash typed. If the comparison is True, then he discovers the word that is there in the hash.
Follows the code:
passmd5 = input("Digite o hash MD5: ") #dega a hash desejada
lista = open('worldlist.txt', "r") #abre o arquivo txt
worldlist = lista.read() #ler todo conteúdo como uma string
worldlist = worldlist.split(", ") #Quebra a string por palavras separadas por ', '
descripto = hashlib.md5() #Variável que será utilizada para criptografar cada item da lista
for item in worldlist: #loop que percorre cada item da lista
descripto.update(item.encode('utf-8')) #caso eu nao use o encode, o python retorna o seguinte erro: Unicode-objects must be encoded before hashing
if descripto.hexdigest() == passmd5: #Verifico se o item criptografado é igual ao hash passado, se sim, descubro a palavra
print ("-----------------------------------")
print ("Sua Hash MD5: ", passmd5)
print ("Hash Descriptograda: ", item)
print (descripto.hexdigest())
print (item)
I use the two prints of the end to see how the output is, because the comparison of the if is not working.
I realized that when I give one print(item) output is the item of worldlist correctly, but when I use the print(item.encode("utf-8")) one b is added in front of the item, getting like this: b'fulano'. So I guess that’s why the comparison never works out, he compares fulano with b'fulano'. (Encrypted, of course!)
I wonder if someone can help me make it work and also give a few touches on the code, because I’m learning.
A hint is to use
withwhen manipulating files, it closes the file automatically: https://www.pythonforbeginners.com/files/with-statement-in-python– hkotsubo