I made a brute force password cracker for one of my classes, but couldn't figure out why it wasn't wasn't fully checking every combination. If I use simple passwords with just numbers or lowercase it usually works, but complex combinations of characters do not necessarily yield an answer at all.
Here is the code I submitted for my assignment:
from datetime import datetime
from itertools import combinations_with_replacement, permutations
#############################
# Password Cracking Program #
#############################
possibleChars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")"]
# Get the current time after program runs, subtracts it from the initial time
now = datetime.now()
password = input("Enter a 4 character password:\n")
combinations = list(combinations_with_replacement(possibleChars, 4)) + list()
totalTries = 0
for combo in combinations:
totalTries += 1
print(join(combo))
if password == "".join(combo):
print("Your password is: " + password)
print(totalTries)
# Output the difference in seconds
later = datetime.now()
diff = (later - now).total_seconds()
print(diff)
break
Any help is appreciated!