File size: 674 Bytes
ef4248d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

import itertools
import string

def brute_force_password(target_hash, hash_function, max_length=6):
    charset = string.ascii_letters + string.digits
    for length in range(1, max_length + 1):
        for attempt in itertools.product(charset, repeat=length):
            password = ''.join(attempt)
            if hash_function(password) == target_hash:
                print(f"Password found: {password}")
                return password
    print("Password not found.")
    return None

if __name__ == "__main__":
    import hashlib
    target = hashlib.md5("secret".encode()).hexdigest()
    brute_force_password(target, lambda p: hashlib.md5(p.encode()).hexdigest())