Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

MD5 Hash Cracker

I'm just getting back into learning python. I wrote a bruteforce hash crack script, it is probably very unoptimized and would like critique/tips on what I could do better. Thanks!

PHP Code

<?php 
import hashlib
, string, time

def words
(chars=string.ascii_letters + string.digits):
    yield from 
chars
    
for word in words(chars):
        for 
char in chars:
            yield 
word + char
            
def hashcrack
(h):
    if 
len(h) == 32:
        
startTime = time.clock()
        print(
"Working...")
        for 
word in words('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-=_+[]\{}|;:\'",./<>?'):
            
hash = hashlib.md5(word.encode('utf-8')).hexdigest()
            if 
hash == h:
                print(
"Success! The string was {}".format(word))
                print(
"Time taken: {}".format(time.clock()-startTime))
                
input()
    else:
        
hash = input("Try again, what is the hash?\n")
        
hashcrack(hash)
    
hash = input("What is the hash?\n")
hashcrack(hash) 
use itertools, it's going to make your code a lot more easier
You have no idea how slow this is just fyi...
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Nov 2, 2016 02:28 PM)Goodies Wrote:  You have no idea how slow this is just fyi...

Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.
(Nov 2, 2016 03:25 PM)bhop_alex Wrote:  Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.

To be honest, there really isn't a faster way to do this using python. You'd have to re-write your code in a native language as the python interpreter is rather slow.
I guess it depends on what you want to achieve. Do you want to find fastest way to brute-force an md5 hash with python, just for fun and learning purposes, or do you want to actually crack an md5 hash. Because in that case you're probably better off not brute-forcing it and using another programming language.
(Nov 2, 2016 03:25 PM)bhop_alex Wrote:  Any tips on improving speed? I do understand it is probably one of the the worst ways I could go about this, because I am pretty new to it.

Yeah. Use another langusge. If you're dead set in Python (I have no idea why you would be, but alright)

1) multiprocessing NOT MULTITHREADING
2) use native standard libraries like itertools
3) some GPU APIs have Python implementations. Maybe check those out.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
Thanks for the help, everyone!
(Nov 2, 2016 05:34 PM)M5DD Wrote:  To be honest, there really isn't a faster way to do this using python. You'd have to re-write your code in a native language as the python interpreter is rather slow.

Or just use a different interpreter.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by SIM-587985Sep 23, 2022 08:23 AM 3 286 Sep 23, 2022 08:23 AM
Last Post: MavenGradle
[Python] by HammyleinMar 30, 2022 12:37 PM 4 256 Mar 30, 2022 12:37 PM
Last Post: foxegado
[C] by Ex NihiloMay 18, 2019 01:34 PM 6 305 May 18, 2019 01:34 PM
Last Post: pelayo