my example in the previous post was for wavic.
Here is one for you, where the passwords.txt file is read line by line and once a match is found it returns the number (of attempts)
assumes python3
Here is one for you, where the passwords.txt file is read line by line and once a match is found it returns the number (of attempts)
assumes python3
def guess_password(real): WORDLIST = "passwords.txt" with open(WORDLIST, 'r') as in_file: # open the file for read for attempt, line in enumerate(in_file, start=1): # read file line by line if line.strip() == real: # compare line, stripped of the cartridge return, with real return attempt # if match is found - return the number of attempts return None # no match after the file is exhausted - return None. You can skip this line, but for clarity let explicitly return None. if __name__ == '__main__': my_guess = input("Enter password to crack: ") # take user input is_found = guess_password(my_guess) # call the function and get the result if is_found: # if function returned number, i.e. there is match and that evaluates to True print('password is {}. found in {} guesses.'.format(my_guess, is_found)) else: # function return None (that evaluates to False) print('passowrd {} not found in the file.'.format(my_guess))