-1

I'm not good at programming. Actually, I already understand the algorithm but it doesn't work in implementing it to coding. So I explain here.

I have a word = "lionfire" and md5 hash = "55dbbb5fa990642a061cdfcf73b5027b"

if i just know the md5 hash and "li?nf?re" word, how i can guess the real word? this is my last try with python

import hashlib
import sys
import string

characters = string.printable

for x, y  in characters:
    content= 'li'+ x + 'nf' + y + 're'
    if hashlib.md5(content).hexdigest() == "55dbbb5fa990642a061cdfcf73b5027b":
        print content
        sys.exit(0)
straycat
  • 1
  • 3
  • x is the same in your example for both characters... bruteforcing (the only way) would require a combination of 2 characters (or a double loop) – Jean-François Fabre Nov 23 '20 at 05:32
  • Does this answer your question? [is a there md5 decrypt function in python?](https://stackoverflow.com/questions/2760911/is-a-there-md5-decrypt-function-in-python) – Melvin Abraham Nov 23 '20 at 05:32
  • @MelvinAbraham thanks for the suggestion, but i don't think that was same – straycat Nov 23 '20 at 05:39

1 Answers1

0

The search pattern has to allow for 2 possible letters 'o' and 'i'... so you need to account for a pair of letters (python calls these tuples).

Used pattern 2 letter pattern: 'li%snf%sre'. The %s substitutes the first (f) and second (s) cases.

import hashlib
import sys
import string


def findWord(md5Key, pattern):
    charList = [(f,s) for f in string.printable for s in string.printable]

    for f,s  in charList:
        content= pattern % (f,s)
        if hashlib.md5(content.encode()).hexdigest() == md5Key:
            print('found',content)
            return content
    return None

findWord("55dbbb5fa990642a061cdfcf73b5027b", 'li%snf%sre')
frankr6591
  • 1,211
  • 1
  • 8
  • 14