简体   繁体   中英

Python and Cryptography: md5

I am very interested in python and cryptography and I would like to know what would be the most simple method in python to crack a hash.

I would like to build a small python script that can crack this hash:21232f297a57a5a743894a0e4a801fc3 which is simply 'admin'.

What process would I need to go through to guess what this hash represents?

I have read up about md5 and at this point in time I have only just started learning the methods behind cryptography, but they also go into deep computer science which is something I don't understand as of yet.

I did some research here: http://nsfsecurity.pr.erau.edu/crypto/md5.html

You can output a hex md5 like so:

>>> from hashlib import md5
>>> md5('admin').hexdigest()
'21232f297a57a5a743894a0e4a801fc3'

If you have a list of words, you could try them one by one and output if their md5 matches your desired one. (This is known as a dictionary attack)

>>> words = 'test', 'alex', 'steve', 'admin'
>>> for word in words:
...     if md5(word).hexdigest() == '21232f297a57a5a743894a0e4a801fc3':
...         print word
...         break
... 
admin

If you were serious about cracking an MD5 you'd have much better results on the GPU - try a tool like OCLHashCat

http://www.google.com/search?q=md5+lookup

>>> import requests
>>> import lxml.html
>>> 
>>> def reverse_md5(digest):
...     r = requests.get('http://www.md5-lookup.com/index.php?q={}'.format(digest))
...     root = lxml.html.fromstring(r.content)
...     for x in root.cssselect('#LSResult table tr')[4:-3]:
...         return x.find('td').text_content() 
...     # fallback to brute force.
...     # ...
... 
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc3')
'admin'
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc4') # lookup fail
>>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM