Here's the code for Search Method 3 that I put in the compiler. The exact everything.
Code: Select all
# search method 3 uses a list of dictionary words. In this case, we have a list
# of the 500 most commonly used passwords in 2005 as collected by Mark Burnett
# for his book "Perfect Passwords" (ISBN 978-1597490412). Because the list comes
# from so many people around the world, we had to remove some of the passwords.
# People like to use passwords that they think will shock other people, so
# sometimes they're not fit for polite company.
def search_method_3(file_name):
global totalguesses
result = False
# Start by reading the list of words into a Python list
f = open(file_name)
words = f.readlines()
f.close
# We need to know how many there are
number_of_words = len(words)
print("Using method 3 with "+str(number_of_words)+" in the list")
## Depending on the file system, there may be extra characters before
## or after the words.
for i in range(0, number_of_words):
words[i] = cleanup(words[i])
# Let's try each one as the password and see what happens
starttime = time.time()
tests = 0
still_searching = True
word1count = 0 # Which word we'll try next
while still_searching:
ourguess_pass = words[word1count]
print("Guessing: "+ourguess_pass)
# Try it the way it is in the word list
if (check_userpass(which_password, ourguess_pass)):
print ("Success! Password "+str(which_password)+" is " + ourguess_pass)
still_searching = False # we can stop now - we found it!
result = True
else:
print ("Darn. " + ourguess_pass + " is NOT the password.")
tests = tests + 1
totalguesses = totalguesses + 1
# Now let's try it with the first letter capitalized
if still_searching:
ourguess_pass = Cap(ourguess_pass)
print("Guessing: "+ourguess_pass)
if (check_userpass(which_password, ourguess_pass)):
print ("Success! Password "+str(which_password)+" is " + ourguess_pass)
still_searching = False # we can stop now - we found it!
result = True
else:
print ("Darn. " + ourguess_pass + " is NOT the password.")
tests = tests + 1
totalguesses = totalguesses + 1
word1count = word1count + 1
if (word1count >= number_of_words):
still_searching = False
seconds = time.time()-starttime
report_search_time(tests, seconds)
return result