Brute force password cracker code
import itertools
import string
def brute_force_crack(target_password, max_length=4):
characters = string.ascii_lowercase # a-z
print(f"Starting brute force attack to crack: '{target_password}'")
for length in range(1, max_length + 1):
for guess_tuple in itertools.product(characters, repeat=length):
guess = ''.join(guess_tuple)
print(f"Trying password: {guess}")
if guess == target_password:
print(f"Password cracked! The password is: {guess}")
return guess
print("Password not found within given max length.")
return None
# Example usage:
target = "cat"
cracked_password = brute_force_crack(target, max_length=3)
Code output
Starting brute force attack to crack: 'cat'
Trying password: a
Trying password: b
Trying password: c
Password cracked! The password is: cat