# Science Buddies derived password cracker

I am trying to improve the performance of this password cracking method:

def search_method_2(num_pass_wheels):
global totalguesses
result = False
starttime = time.time()
tests = 0
still_searching = True
print("Using method 2 and searching with "+str(num_pass_wheels)+" password wheels.")
wheel = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
# we only allow up to 8 wheels for each password for now
if (num_pass_wheels > 8):
print("Unable to handle the request. No more than 8 characters for a password")
still_searching = False
# set all of the wheels to the first position
pass_wheel_array=array('i',[1,0,0,0,0,0,0,0,0])

while still_searching:
ourguess_pass = ""
for i in range(0,num_pass_wheels):  # once for each wheel
if pass_wheel_array[i] > 0:
ourguess_pass = wheel[pass_wheel_array[i]] + ourguess_pass
#print ("trying ["+ourguess_pass+"]")
still_searching = False   # we can stop now - we found it!
result = True
#else:
#print ("Darn. " + ourguess + " is NOT the password.")
tests = tests + 1
totalguesses = totalguesses + 1

carry = 1
for i in range(0,num_pass_wheels): # once for each wheel
pass_wheel_array[i] = pass_wheel_array[i] + carry
carry = 0
if pass_wheel_array[i] > 62:
pass_wheel_array[i] = 1
carry = 1
if i == (num_pass_wheels-1):
still_searching = False

seconds = time.time()-starttime
report_search_time(tests, seconds)
return result


This is a modified version of the Science Buddies password cracker (found here: http://www.sciencebuddies.org/science-fair-projects/project_ideas/CompSci_p046.shtml#materials

You can see the full file here if you would like to: https://files.fm/u/bg9ppx77

Basically, I need a way to run this method faster, I can currently do about 200,000 tests (or runs of this method) per second. I would like to double or triple that number so that I can "crack" longer passwords in a reasonable period of time.

If anyone could point me in the right direction that would be great, if anyone has any code ideas that would be amazing.

• you might want to use any profiler to figure out which part/call takes most of the time and focus on it. – Alex Nov 1 '16 at 10:05
• Your indentation was most likely not properly shown due to a copy-paste error. I fixed it for you. Let me know if this isn't exactly as your own code. Indentation is important in Python. – Mast Nov 1 '16 at 10:29
• How is check_userpass implemented? Since it is called every loop iteration, this is quite important for the performance... – Graipher Nov 1 '16 at 16:27
• The more you call functions, the more you spend time. – Laurent LAPORTE Nov 2 '16 at 23:06
• In the future please declare your cross-posts. stackoverflow.com/questions/40352390/… – janos Nov 3 '16 at 21:22