I'm trying to make a password cracker in Python as practice, and I've noticed that it takes on average 586,634 iterations to crack the password "hey". I'm thinking it's so high because it can freely generate a random string that may have already been checked. For example, it could generate the following and use extra time doing so, when it's already found that it doesn't work.
a!?
, h[j
, jpc
, o$w
, 01g
, a5b
, a!?
, 01g
So how do I stop Python from generating the same string over and over?
Here's my code (the length that it generates is determined by the input's length):
while crack!=password:
i+=1
crack=''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(length))