Untitled

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

attempts = 0
pass_to_guess_len = 0


def find_pass_match(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

    for char_to_try in available_chars:
        attempts += 1
        pass_to_try = current_pass + char_to_try

        if pass_to_try == pass_to_guess:
            return True
        else:
            pass_to_try_matches = find_pass_match(pass_to_guess, pass_to_try, available_chars)
            if pass_to_try_matches:
                return True

    return False


password = "vladi"
pass_to_guess_len = len(password)
pass_characters = list(string.ascii_lowercase)
#random.shuffle(pass_characters)

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

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