Unhashing a hashed (MD5) email address

Viewed 407

I know that in hashing you, by definition, lose information. However, as email addresses can be restricted - such as with the information available I would know a potential domain of the email, and that it must have an @. Do these constraints change anything about the problem? Or is the best way to simply make a guess and see if the hash is the same? Also MD5 is no longer as secure as it once was.

Thanks

1 Answers

That is the point of Md5 hashing that even a minute change in the string can change the hash completely. So these constraints change nothing about the problem.

However since you said that its an email and that you know about the potential domain then you can try this technique.

  1. Generate a list of potential emails it will be within 26 letters and lets say of maximum size 10.

Then you can generate an md5 for all of these possibilities and check if it is equal to the one you have.

import hashlib
from itertools import combinations
import time

start=time.time()
your_md5_hash='your_md5_hash'
letters='abcdefghijklmnopqrstuvwxyz'
possible_words=[]
for r in range(1,10): #change 10 to the maximum size of your email
    for combo in combinations(list(letters), r=r):
        res=''.join(combo)
        possible_words.append(res)


possible_words=[''.join(x)+'@domain.com' for x in possible_words]
print (len(possible_words))
for x in possible_words:
    res=hashlib.md5(x.encode())
    if res==your_md5_hash:
        print (res)
        print (x)
        print ("RESULT_FOUND")
        exit(0)

print (time.time()-start)

This is brute force approach and if you know the size of your email then this could work. Secondly please note that if you do not know the size then the size of possibilities will increase exponentially.

For instance the length of combinations as of now is 5658536 and it took my basic laptop 6 seconds to process.

Related