Modify the script below to read a recovered hashed password, see if that hashed password exists in the rainbow table, then find the corresponding plaintext password; output the matches if they are found and record how long it takes to search for each password. Your main task here is to put the timing commands in the correct places (startTime = timer() , endTime = timer() ).
------.py
from timeit import default_timer as timer
file1 = open("RECOVERED_PASSWORD_HASHES.txt")
recovered_hashes = file1.readlines()
file1.close()
file2 = open("RAINBOW_TABLE.txt")
indexed_hashes = list(enumerate(file2))
file2.close()
file3 = open("10K_PLAINTEXT_PASSWORDS.txt")
plaintext_passwords = file3.readlines()
file3.close()
# for each candidate hash in recovered_hashes
# you'll need some way to stop the inner for loop search
# maybe use a flag variable (True/False)
for i, hash in indexed_hashes:
if candidate.rstrip() == hash.rstrip():
print("MATCH: hash # " + hash + " = " + plaintext_passwords[i])
print("The search took x microseconds")
# this part of the code is to be executed if there is no match after a search through
# the entire list of indexed_hashes. maybe condition on your flag variable
print("NO MATCH FOUND FOR ", candidate.rstrip())
print("The search took x microseconds")