0

I am trying to calculate MD2 hashes using PyCrypto until i find one or more starting with a given string. (Please don't ask why :=)

I am able to find several hashes. If i check the correctness of my hash calculation via online tools, i will not get the same hash.

Code:

import itertools
from Crypto.Hash import MD2

charset = 'abcdefghijklmnopqrstuvwxyz0123456789'
md2hasher = MD2.new()

res = itertools.product(charset, repeat=6)
for i in res: 
    md2hasher.update(bytes(i))
    strMD2 = md2hasher.hexdigest()
    if strMD2.startswith('757c47'):
        print i
        print strMD2

Sample output:

('a', 'e', 's', '1', 'x', 'e')
757c47bf59afdcd8d05bd4c5d571ef5d
('a', 'i', 'p', '3', 'v', '4')
757c4758262eb9a3ce3a021728f0a842
('a', 'j', '3', 'j', 'p', '3')
757c475ffc257d31026674cb6b346094

Online verification:

http://md5hashing.net/hash/md2/d25e0cd52f62792daff6f76c5a640b4c

(d25e0cd52f62792daff6f76c5a640b4c)

What am i doing wrong?

2bNs
  • 3
  • 1
  • This is the reason why: http://hackyeaster.hacking-lab.com/hackyeaster/challenge24.html...It's an ongoing challenge!! – evandrix Apr 09 '15 at 02:19

2 Answers2

1

You are using Python 2 - bytes is synonymous to str. str(i) returns a byte string "('a', 'e', 's', '1', 'x', 'e')" instead of 'aes1xe'; to get the latter, use ''.join(i)

Also you're reusing the hash, which is nono. You must create a new hash object unless you want to concatenate.

Thus we get:

charset = "abcdefghijklmnopqrstuvwxyz0123456789"
for i in itertools.product(charset, repeat=6): 
    strMD2 = MD2.new("".join(i)).hexdigest()
    if strMD2.startswith("757c47"):
        print strMD2
evandrix
  • 6,041
  • 4
  • 27
  • 38
0

I've a similar problem, I've tried to check the same string, my code looks a little bit different:

from Crypto.Hash import MD2
import itertools

letters = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789\"_$&#@"
h = MD2.new()

for guess in itertools.product(letters, repeat=6):
    h.update(''.join(guess).encode())    
    if(h.hexdigest()[0:6:1] == "757c47"):
        print ("String: " + ''.join(guess))
        print (h.hexdigest())

I've tried the solution above, this works fine. But I don't know what's the mistake in my code.

Output:

String: aa8LVM
757c4765c5a45c70128c02766c63255b
String: abto9L
757c47e274e0d7e3a5a0a0574f154c7e
String: abFjlK
....
Pang
  • 9,564
  • 146
  • 81
  • 122
the_new_one
  • 33
  • 1
  • 5