import itertools, time import string def guess_password(password,chars): found = False start = time.time() attempts = 0 for password_length in range(1, 9): for guess in itertools.product(chars, repeat=password_length): attempts += 1 guess = ''.join(guess) #print(guess) if guess == password: found = True end = time.time() duration = end - start return "password is " + guess + " found in " + str(attempts) + " attempts in " + str(duration) + " seconds" if not(found): return "Password not found" #ascii letters and digitals alpha = chars = string.ascii_letters + string.digits #ascii letters, digits, special characters and whitespace extended = string.ascii_letters + string.digits + string.punctuation + string.whitespace #password to check password = "password" #call function and print return value print(guess_password(password,alpha))