Python Password Brute Force Guesser
Sun Feb 12 2023 16:02:54 GMT+0000 (Coordinated Universal Time)
# For forcefully stopping the program when done. import sys # For memory optimization purposes. import os # List of all possible characters to search through. characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "~", "_", "+", "{", "}", "|", ":", '"', "<", ">", "?"] # Ask for the actual password that is trying to be found. password = input("Enter the password trying to be brute forced: ") # What method user wants to go through. process = input("\nWould you like to display the process?\n\nNote: agreeing to display the process means the program will take a much longer time to run.\n\nSo, yes or no? ") # Check if the process input is "no". if process.lower() == "no": # Create an empty list to store the indexes of the characters in the password. indexes = [] # loop through each character in the password. for character in password: # Set the index to 1. index = 1 # Loop through each value in the characters list. for value in characters: # If the character is found in the characters list, append the index to the indexes list. if character == value: indexes.append(index) # Increment the index if the character is not found. else: index += 1 # Set the first index value to 1. index = 1 # Set the second index value to 0. index2 = 0 # Set the number of tries to 0. tries = 0 # Loop through the length of the indexes list minus one. for i in range(len(indexes)-1): # Calculate the temporary value. temp = (94 ** index) * indexes[index2] # Add the temporary value to the number of tries. tries += temp # Increment the second index value and the first index value. index2 += 1 index += 1 # Add the last element of the indexes list to the number of tries. tries += indexes[-1] # Print the final result of the number of tries taken. print("\nThe password was guessed in", tries, "tries.") # Check if the process input is "yes". elif process.lower() == "yes": # Set the guessed password equal to the characters list. guessed = characters # Set the number of tries to 0 and the guess value to 0. tries = 0 guess = 0 # Create an empty list for the estimates. estimates = [] # Loop through each character in the characters list. for character in characters: # Increment the number of tries each iteration. tries += 1 # Check if the current character is equal to the password. if character == password: # Print the result and exit the program if the password is guessed. print("Password guessed in", tries, "tries.") sys.exit() # Create an empty list for temporary values. temp = [] # Set the number of loops to 0. loops = 0 # Continue looping until the correct password is guessed. while guess != password: # Loop through each value in the guessed list. for value in guessed: # Loop through each character in the characters list. for character in characters: # Combine the current value and character to form a possibility. possibility = value + character # Increment the number of tries. tries += 1 # Clear the terminal screen. os.system('clear') # Display the password, current guess, and number of tries. print("Password:", password) print("Current Guess:", possibility, "\nTry Number", tries) # Check if the possibility is equal to the password. if possibility == password: # Print the result and exit the program if the password is guessed. print("\nPassword guessed in", tries, "tries.") sys.exit() else: # Add the possibility to the temp list if it's not equal to the password. temp.append(possibility) # Set the guessed list to an empty list. guessed = [] # Set the guessed list to the temp list. guessed = temp # Set the temp list to an empty list. temp = [] ### RANDOM PASSWORD GENERATOR FOR TESTING ### import random desired_length = int(input()) random_output = [] characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "~", "_", "+", "{", "}", "|", ":", '"', "<", ">", "?"] for iteration in range(desired_length): random_output.append(random.choice(characters)) print(*random_output, sep="")
Comments