start_password = "vzbxkghb" # start_password = "abcdefgh" print("Start password:", start_password) def b26_to_int(input_string): result = 0 exp = 1 for char in input_string[::-1]: char_value = ord(char) - 97 # from 0 to 25 result += char_value * exp exp *= 26 return result def int_to_b26(input_number): result = "" while input_number: quot, remainder = divmod(input_number, 26) result += chr(remainder + 97) input_number = quot return result[::-1] def increment_password(password): return int_to_b26(b26_to_int(password) + 1).rjust(8, "a") STRAIGHTS = [chr(x + 97) + chr(x + 98) + chr(x + 99) for x in range(24)] def has_increasing_straight(password): for straight in STRAIGHTS: if straight in password: return True return False def has_forbidden_letter(password): for char in ["i", "o", "l"]: if char in password: return True return False PAIRS = [chr(x + 97) + chr(x + 97) for x in range(26)] def contains_two_pairs(password): count_pairs = 0 for pair in PAIRS: if pair in password: count_pairs += 1 if count_pairs >= 2: return True return False def validate_password(password): return ( has_increasing_straight(password) and not has_forbidden_letter(password) and contains_two_pairs(password) ) # to_int = b26_to_int(start_password) # print(start_password, to_int, int_to_b26(to_int)) # print(start_password, increment_password(start_password)) # for pwd in ["hijklmmn", "abbceffg", "abbcegjk", "abcdffaa", "ghjaabcc"]: # print(pwd) # print(validate_password(pwd)) # print() # print(STRAIGHTS) # print(PAIRS) while not validate_password(start_password): start_password = increment_password(start_password) print(start_password) # false guess: vzcaabcc