Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.1 kB
3
Indexable
import string
import time
import random

attempts = 0
pass_to_guess_len = 0


def analyze(pass_to_guess, current_pass, available_chars):
    global attempts
    global pass_to_guess_len

    current_pass_len = len(current_pass)
    if current_pass_len > pass_to_guess_len:
        return False
    elif current_pass_len == pass_to_guess_len:
        return current_pass == pass_to_guess

    left_chars = available_chars.copy()

    while len(left_chars) > 0:
        attempts += 1
        char_to_try = left_chars.pop()
        pass_to_try = current_pass + char_to_try

        if pass_to_try == pass_to_guess:
            return True
        else:
            result = analyze(pass_to_guess, pass_to_try, available_chars)
            if result is True:
                return True

    return False


password = "aladz"
pass_to_guess_len = len(password)

pass_characters = list(string.ascii_lowercase)

start_time = time.time()
match_found = analyze(password, "", pass_characters)
end_time = time.time()

if match_found:
    print("Found match in {} attempts, took {:.2f} seconds".format(attempts, end_time - start_time))