I'm using Python 3.6 to do a program in which the person types an MD5 hash, so the program saves the hash in a variable, reads a txt file and plays the contents inside a list, where each name separated by ,
is an item in that list.
After that, the program goes into a loop where it encrypts to list item (txt) and compares to the hash entered. If the comparison is True
, then it finds the word that is there in the hash.
Follow 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 end prints to see how the output is, since the if
comparison is not working.
I noticed that when I give a print(item)
the output is the worldlist
item correctly, but when I use print(item.encode("utf-8"))
a b
is added in front of the item, thus: b'fulano'
. So, I guess that's why the comparison never works, it compares fulano
to b'fulano'
. (Encrypted, of course!)
I would like to know if anyone can help me make it work and also give some touches to the code, because I am learning.