crack2.py Not working
Moderators: kgudger, bfinio, Moderators
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
crack2.py Not working
So I was attempting to do the project on hacking passwords, http://bit.ly/1dInMbA , and I could not get the code to work. Every time when I open crack2.py with python and put in the number of which password, it shows the first 4 lines of code it is supposed to, then after about a minute, it shows the next lines of code it is supposed to along with the final line with the answer, but it instantly closes before I can even read the code. I also cannot figure out how to import the passwords from passwords.txt.
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
The code runs much better if you run it from Python's IDE, or development environment, IDLE. Depending on how you installed Python, it might be called IDLE or it might be called IDLE3 (most likely). Put the crack2.py and passwords.txt into the same directory, start up IDLE or IDLE3 and load crack2.py into the editor. Run it from IDLE and the program will find the passwords file by itself. The two MUST be in the same directory otherwise it will get an error.
If you don't have, or don't want to use IDLE, I suppose you could also put another INPUT statement into the code just before the program terminates. At least that way you'd get to read the text before the screen cleared. I'd still suggest using IDLE if you can.
Howard
If you don't have, or don't want to use IDLE, I suppose you could also put another INPUT statement into the code just before the program terminates. At least that way you'd get to read the text before the screen cleared. I'd still suggest using IDLE if you can.
Howard
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
So how can I open the IDE? And just in case it affects anything, i'm on a Windows 8 Computer.
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
Hit the Windows key to get up the Windows START tiles. Click on the magnifying glass to search, and search for IDLE. If you installed the standard Python 3.3 or 3.4, it will offer you the IDLE gui. Click on that to launch it. Once it starts, use File->Open to head to the directory where you put the two files and select 'crack2.py'.
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
Ok so when I run it, and I chose a number, then it will just choose a random password from the list?
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
Not exactly. There are 6 encoded passwords that it can "guess", plus you can enter one of your own. The number you're entering is which one of the passwords (7 in total) that it will try to guess. It uses a number of algorithms to try and guess them, including trying each of the passwords in that list in various ways. It's not uncommon for the program to try a million attempts to guess one of the passwords.
So let's say you want to see how long it takes to guess your password "secret". Find the section of the code that includes Change the "314" to "secret" and then run the program, entering '0' to select password 0. The program will eventually get to the part where it tries the words in the word list and it will successfully guess 'secret' because it's in the list. The encoded passwords 1 through 6 are there for you to try different methods of your own. The program will find 1 through 5 just as provided - can you make it find them faster? 6 will require you to write some new code.
So let's say you want to see how long it takes to guess your password "secret". Find the section of the code that includes
Code: Select all
# This is a place for you to set a password of your own
password0 = "314"
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
So, if i'm getting this correct, the only way to test the passwords is changing password 0?
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
You can make the project into anything you like of course, but the suggested idea was to write a program that guesses passwords. Since in the real world you don't know the passwords in advance, passwords 1 through 6 give you some to test your program out against. While you're testing though, you'll want to test against something that you DO know, since that's the best way to make sure your code works as designed. Then once you're sure it works, you can have teachers, parents, siblings or friends enter a password you don't know as password 0, OR you can try the ones we provided.
The program as provided only tries to guess one password. You pick which one of the 7 that is. If you don't want to use any of the encoded ones we provide, just plug yours into password 0, or change the code to allow plain text for passwords 1 through 6. It's your project and you're encouraged to take the code and use it as you please.
The program as provided only tries to guess one password. You pick which one of the 7 that is. If you don't want to use any of the encoded ones we provide, just plug yours into password 0, or change the code to allow plain text for passwords 1 through 6. It's your project and you're encouraged to take the code and use it as you please.
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
I forgot to add that another student modified the program so that instead of asking for a password number from 0 through 6, it asks for a password you want it to guess. It stores that as password0, sets the selection number to 0 and then runs. That would work really well, except it might look odd if on screen, it asks "What password should guess?", you type in "secret" and it says "I guessed it!". The code to do all that was pretty simple though.
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
Are all of the passwords supposed to be hacked in 0.02 seconds or less, because that doesn't seem right to me.
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
20 milliseconds is pretty fast for all of them, and it seems highly unlikely that they'd all be found in the same amount of time. Do the reported times make sense or is it possible that the program simply misreported the time? Perhaps the Python time functions aren't working on your machine.
I did the project on a Macbook, but I now have a shiny new Dell Win 8 machine so I just ran passwords 1 through 5 to see how long it took. Password 1 was located in 85 seconds, passwords 2 and 3 took 10 milliseconds each (faster than you said). Password 4 took 3 seconds and password 5 was faster again, at 39 milliseconds. If you look at the code and what the passwords are, does that make sense to you? Can you see why passwords that include standard dictionary words might be less secure and easier to crack than ones that contain gibberish?
I didn't include any long gibberish strings in the encoded set because the samples are only for practice and i didn't want them to take hours. See how long it takes for your computer to get this one: set one of the encoded passwords to "82858639ec0abf0e73c436d24ad6c7dc" and try it. My machine got it in 37 seconds and needed 27 million trials. It's not a 3 or 4 digit number and it's not a dictionary word.
How about "1271ed5ef305aadabc605b1609e24c52"? Can you get it faster than this machine did (1.5 hours) the nearly 771 million trials?
On the examples included in the code:
Password 1 was found in 85 seconds.
Password 2 was found in 10 milliseconds.
Password 3 was found in 10 milliseconds.
Password 4 was found in 3 seconds.
Password 5 was found in 39 milliseconds.
I didn't realize the Macbook was so much slower than this new Windows laptop - but even so, if the program is reporting the same 20 milliseconds for all 5 of the supplied passwords, you may need another way of timing or perhaps try a different computer - or simply use the number of trials as your data.
I did the project on a Macbook, but I now have a shiny new Dell Win 8 machine so I just ran passwords 1 through 5 to see how long it took. Password 1 was located in 85 seconds, passwords 2 and 3 took 10 milliseconds each (faster than you said). Password 4 took 3 seconds and password 5 was faster again, at 39 milliseconds. If you look at the code and what the passwords are, does that make sense to you? Can you see why passwords that include standard dictionary words might be less secure and easier to crack than ones that contain gibberish?
I didn't include any long gibberish strings in the encoded set because the samples are only for practice and i didn't want them to take hours. See how long it takes for your computer to get this one: set one of the encoded passwords to "82858639ec0abf0e73c436d24ad6c7dc" and try it. My machine got it in 37 seconds and needed 27 million trials. It's not a 3 or 4 digit number and it's not a dictionary word.
How about "1271ed5ef305aadabc605b1609e24c52"? Can you get it faster than this machine did (1.5 hours) the nearly 771 million trials?
On the examples included in the code:
Password 1 was found in 85 seconds.
Password 2 was found in 10 milliseconds.
Password 3 was found in 10 milliseconds.
Password 4 was found in 3 seconds.
Password 5 was found in 39 milliseconds.
I didn't realize the Macbook was so much slower than this new Windows laptop - but even so, if the program is reporting the same 20 milliseconds for all 5 of the supplied passwords, you may need another way of timing or perhaps try a different computer - or simply use the number of trials as your data.
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
Am i supposed to have all of the passwords i test in the password0= field?
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
The code as provided only tests one password per run. So yes, if you want to try the code against a lot of passwords, you have to modify password0 for each one and then run it.
What you may want to do instead is enclose the whole program in a loop and store a bunch of passwords in an array.
Or something like that. That may help if a lot of your tests will take hours and you want to queue them up to run overnight.
What you may want to do instead is enclose the whole program in a loop and store a bunch of passwords in an array.
Code: Select all
manypasswords = ["secret", "password", "letmein", "opensesame"]
print ("We have "+str(len(manypasswords))+" passwords to try")
for which in range (0, len(manypasswords)):
password0 = manypasswords[which]
print ("Guessing "+ password0)
# The rest of the program goes here-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
So, where would you put the the many passwords part? And how would you put the program in a loop?
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
The general idea is that in the provided program, it starts by setting password 0 to something (1 through 6 also), and then asking you which one of the 7 you want to test. Like this:
When you test for password 0 this way, the variable 'password0' contains the test password and the variable 'which_password' contains the number 0. So let's change the function 'main()' to have a new name and have it take as an argument the password we want to try:
Okay so far? Now we'll write a new main() that simply calls our function testOnePassword():
When the program is run, it starts by calling main() which then calls the test function with a password. You can put a bunch of them in like this:
Or if you want get fancy:
I'll leave the details of implementing it to you. If you haven't worked in Python before, you may find it handy to look at an online tutorial or see if one of your teachers at school can help you. I can't really post a fully functional program here beyond what's in the original project idea - that will take away the fun of your making the changes yourself.
Howard
Code: Select all
def main(argv=None):
global password0, password1, password2, password3
global password4, password5, password6, totalguesses
global which_password
# This is a place for you to set a password of your own
password0 = "314"
# Set up the passwords we want to crack. These must be MD5 hash
...
which_password = int(input("Which password (0-6)? "))
Code: Select all
def testOnePassword(testMe):
global password0, password1, password2, password3
global password4, password5, password6, totalguesses
global which_password
# This is a place for you to set a password of your own
password0 = testMe
# It doesn't matter what we set for passwords 1 through 6 since we don't use them
# start searching
which_password = 0
Code: Select all
def main(argv=None):
testOnePassword("ScienceBuddies")
Code: Select all
def main(argv=None):
testOnePassword("ScienceBuddies")
testOnePassword("secret")
testOnePassword("Harry+Ginny")
Code: Select all
def main(argv=None):
manyPasswords = ["ScienceBuddies","secret","Harry+Ginny"]
for which in range(0, len(manyPasswords)):
testOnePassword(manyPasswords[which])
Howard
-
deleted-265782
- Posts: 8
- Joined: Sat Jan 24, 2015 2:37 pm
- Occupation: Student
- Project Question: How Easily Can Your Password Be Hacked?
- Project Due Date: 2/4/15
- Project Status: I am conducting my experiment
Re: crack2.py Not working
I'm sorry if I sound rude, but I do not really have the time to be browsing around guides trying to find one thing, and I need to have this done as soon as possible. All of your help has been very appreciated, but I really need to know how I can make this work.
-
deleted-249560
- Posts: 496
- Joined: Thu Nov 20, 2014 1:35 pm
- Occupation: Science Buddies content developer
- Project Question: N/A
- Project Due Date: N/A
- Project Status: Not applicable
Re: crack2.py Not working
I understand time crunches. I've also already given you the solution to the automation problem if you simply cut and paste the pieces I gave you into the original code. It ends up looking like this:
More importantly, the point of the project was to think about password security and while coming up with new ways of guessing passwords, realizing what you could to to make your own passwords more secure. The code attached is no different than the original - it only has 435 words and can't do much of a dictionary attack without your help. The parts of the code that pretend to be a 62-position suitcase lock will choke if asked to handle more than 4 or 5 characters. It would take years to guess a 10 or 12 character password that way. That code can be easily rewritten to go a lot faster. Others have managed to get it guessing in 60 or 70% of the original time. I'm sorry that you don't have the time to dig into this, but it's really a fun topic if you do.
Frankly, I don't think providing an automated list of passwords by itself is all that useful. For the ones it can guess, it typically manages to do those in well under an hour - sometimes in under a second. For a longer gibberish password that can be anything, it will take even the fastest computers running code not written in Python MANY years to complete. I finally decided I'd make those little code changes for you since it really is only adding 10 or so lines of code to the original. You really ought to at least try rearranging the order of the tests based on the kinds of passwords people pick to see if you can speed things up.
Code: Select all
#!/usr/bin/python
# This program is offered for use with the Science Buddies project idea
# "How Easily Can Your Password Be Hacked?" which lets you explore the
# makeup of a good password. This program will help you understand some
# methods that people use to guess other people's passwords.
#
# the program begins execution at 'main' after the helper programs and functions
# are defined. You'll also notice that several functions have places where
# print() functions have been turned into comments. When debugging a program, it's
# helpful to add in more descriptive screen output than you might want later on.
# Once the program is working, you can remove the extra output or, as we've done here,
# 'comment it out' so that someone else can use it again later on if they decide to
# modify your program.
#Tell Python we want to use some functions it doesn't always use
import sys, time, hashlib
from array import *
#--------------- global variables we expect will be used by any function -----------
#
# a number from 1 to 6 selects which password we'll be trying to guess from
# a selection below.
which_password = 0
# the user names and password we're trying to 'crack'. These will get written
password0 = ""
password1 = ""
password2 = ""
password3 = ""
password4 = ""
password5 = ""
password6 = ""
# total number of guesses we had to make to find it
totalguesses = 0
#--------------- extra helper functions -------------------
# These will be used by our search routines later on. We'll get these defined and out
# of the way. The actual search program is called "main" and will be the last one
# defined. Once it's defined, the last statement in the file runs it.
#
#
## Convert a string into MD5 hash
def MD5me(s):
result = s.encode("utf-8")
result = hashlib.md5(result).hexdigest()
return result
# Takes a number from 0 on up and the number of digits we want it to have. It uses that
# number of digits to make a string like "0000" if we wanted 4 or "00000" if we wanted
# 5, converts our input number to a character string, sticks them together and then returns
# the number we started with, with extra zeroes stuck on the beginning.
def leading_zeroes(n, zeroes):
t=("0"*zeroes)+str(n)
t=t[-zeroes:]
return t
# check_userpass
def check_userpass(which_password, password):
global password0, password1, password2, password3
global password4, password5, password6
result = False
if (0 == which_password):
if password == password0:
result = True
if (1 == which_password):
if MD5me(password) == password1:
result = True
if (2 == which_password):
if (MD5me(password) == password2):
result = True
if (3 == which_password):
if (MD5me(password) == password3):
result = True
if (4 == which_password):
if (MD5me(password) == password4):
result = True
if (5 == which_password):
if (MD5me(password) == password5):
result = True
if (6 == which_password):
if (MD5me(password) == password6):
result = True
return result
# This displays the results of a search including tests per second when possible
def report_search_time(tests, seconds):
if (seconds > 0.000001):
print ("The search took "+make_human_readable(seconds)+" seconds for "+make_human_readable(tests)+" tests or "+make_human_readable(tests/seconds)+" tests per second.")
else:
print ("The search took "+make_human_readable(seconds)+" seconds for "+make_human_readable(tests)+" tests.")
return
# search method 1 will try using digits as the password.
def search_method_1(num_digits):
global totalguesses
result = False
a=0
#num_digits = 3 # How many digits to try. 1 = 0 to 9, 2 = 00 to 99, etc.
starttime = time.time()
tests = 0
still_searching = True
print("Using method 1 and searching for "+str(num_digits)+" digit numbers.")
while still_searching and a<(10**num_digits):
ourguess = leading_zeroes(a,num_digits)
tests = tests + 1
totalguesses = totalguesses + 1
if (check_userpass(which_password, ourguess)):
print ("Success! Password "+str(which_password)+" is " + ourguess)
still_searching = False # we can stop now - we found it!
result = True
#else:
#print ("Darn. " + ourguess + " is NOT the password.")
a=a+1
seconds = time.time()-starttime
report_search_time(tests, seconds)
return result
# search method 2 is a simulation of a letter-style combination lock. Each'wheel' has the
# letters A-Z, a-z and 0-9 on it as well as a blank. The idea is that we have a number of
# wheels for a user name and password and we try each possible combination.
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+"]")
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 + " is NOT the password.")
tests = tests + 1
totalguesses = totalguesses + 1
# spin the rightmost wheel and if it changes, spin the next one over and so on
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 function takes in numbers, rounds them to the nearest integer and puts
# commas in to make it more easily read by humans
def make_human_readable(n):
if n>=1:
result = ""
temp=str(int(n+0.5))
while temp != "":
result = temp[-3:] + result
temp = temp[:-3]
if temp != "":
result = "," + result
else:
temp = int(n*100)
temp = temp /100
result = str(temp)
return result
## A little helper program to remove any weird formatting in the file
def cleanup (s):
s = s.strip()
return s
## A little helper program that capitalizes the first letter of a word
def Cap (s):
s = s.upper()[0]+s[1:]
return s
# 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
## Search method 4 is similar to 3 in that it uses the dictionary, but it tries two
## two words separated by a punctuation character
def search_method_4(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)
## 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
punc_count = 0
word2count = 0
punctuation="~!@#$%^&*()_-+={}[]:<>,./X" # X is a special case where we omit
# the punctuation to run the words together
number_of_puncs = len(punctuation)
print("Using method 4 with "+str(number_of_puncs)+" punc chars and "+str(number_of_words)+" in the list")
while still_searching:
if ("X" == punctuation[punc_count]):
# If we're at the end of the string and found the 'X', leave it out
ourguess_pass = words[word1count] + words[word2count]
else:
ourguess_pass = words[word1count] + punctuation[punc_count] + words[word2count]
#print("Guessing: "+ourguess_pass)
# Try it the way they are 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 of the first word capitalized
if still_searching:
ourguess_pass = Cap(words[word1count]) + punctuation[punc_count] + words[word2count]
#print("Guessing: "+ourguess_pass)
if (check_userpass(which_password, ourguess_pass)):
print ("Success! Passwword "+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 of the second word capitalized
if still_searching:
ourguess_pass = words[word1count] + punctuation[punc_count] + Cap(words[word2count])
#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
# Now let's try it with the both words capitalized
if still_searching:
ourguess_pass = Cap(words[word1count]) + punctuation[punc_count] + Cap(words[word2count])
#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):
word1count = 0
punc_count = punc_count + 1
if (punc_count >= number_of_puncs):
punc_count = 0
word2count = word2count + 1
if (word2count >= number_of_words):
still_searching = False
seconds = time.time()-starttime
report_search_time(tests, seconds)
return result
def main(argv=None):
# A list of passwords to try
manyPasswords = ["314","secret+password","Football!master","5768","qwerty","qwerty1"]
for which in range(0, len(manyPasswords)):
testOnePassword(manyPasswords[which])
def testOnePassword(testMe):
global password0, password1, password2, password3
global password4, password5, password6, totalguesses
global which_password
# This is a place for you to set a password of your own
password0 = testMe
# Set up the passwords we want to crack. These must be MD5 hash
# data blocks. Set them up using MD5me like:
# 'password1=MD5me("ScienceBuddies")'
#
# We don't really have to bother with this any more since we never test
# these passwords. But it doesn't hurt to leave them here just the same.
password1="202cb962ac59075b964b07152d234b70"
password2="570a90bfbf8c7eab5dc5d4e26832d5b1"
password3="f78f2477e949bee2d12a2c540fb6084f"
password4="09408af74a7178e95b8ddd4e92ea4b0e"
password5="2034f6e32958647fdff75d265b455ebf"
password6="9b3af42d61cde121f40b96097fb77d3e"
# start searching
# Don't ask which one - just assume password 0 which is the unencoded one
which_password = 0
# which_password = int(input("Which password (0-6)? "))
overallstart = time.time()
foundit = False
print("Trying to guess password "+str(which_password)+"["+password0+"]")
# Look through our list of common passwords first
if not foundit:
foundit = search_method_3("passwords.txt")
# Still looking? Let's combine the common passwords 2 at a time
if not foundit:
foundit = search_method_4("passwords.txt")
# Still looking? See if it's a single digit
if not foundit:
foundit = search_method_1(1)
# Still looking? See if it's a 2 digit number
if not foundit:
foundit = search_method_1(2)
# Still looking? See if it's a 3 digit number
if not foundit:
foundit = search_method_1(3)
# Still looking? See if it's a 4 digit number
if not foundit:
foundit = search_method_1(4)
# Still looking? Use our rotary wheel simulation up to 6 wheels.
# This should take care of any 5 digit number as well as letter
# combinations up to 6 characters
if not foundit:
foundit = search_method_2(6)
# Still looking? Try 7 digit numbers
if not foundit:
foundit = search_method_1(7)
# Still looking? Try 8 digit numbers
if not foundit:
foundit = search_method_1(8)
seconds = time.time()-overallstart
# When testing this project, some users reported that the next lines of code reported
# an error when Python tried to divide by zero. On those machines, the clock seems
# to think that the seconds calculation just above gave us "zero" seconds which doesn't
# make any sense. To avoid the crash though, we'll test for that case and avoid the
# problem.
if (seconds < 0.00001):
print ("The total search for all methods took "+make_human_readable(seconds)+" seconds and "+make_human_readable(totalguesses)+" guesses.")
print ("(on some machines, Python doesn't know how long things actually took)")
else:
print ("The total search for all methods took "+make_human_readable(seconds)+" seconds and "+make_human_readable(totalguesses)+" guesses.("+make_human_readable(totalguesses/seconds)+" guesses per second)")
if foundit:
if (6 == which_password):
print("Wow! Be sure to confirm your find at https://www.sciencebuddies.org/science-fair-projects/project_ideas/CompSci_p046/PasswordCrack.shtml")
elif (0 == which_password): # The Science Buddies website can't confirm passwords you added yourself
print ("Your algorithm correctly guessed the password you entered. Try some others or see if you can make it guess faster.")
else:
print("You can confirm your find at https://www.sciencebuddies.org/science-fair-projects/project_ideas/CompSci_p046/PasswordCrack.shtml")
print ("Science Buddies: How Easily Can Your password Be Hacked?")
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
Frankly, I don't think providing an automated list of passwords by itself is all that useful. For the ones it can guess, it typically manages to do those in well under an hour - sometimes in under a second. For a longer gibberish password that can be anything, it will take even the fastest computers running code not written in Python MANY years to complete. I finally decided I'd make those little code changes for you since it really is only adding 10 or so lines of code to the original. You really ought to at least try rearranging the order of the tests based on the kinds of passwords people pick to see if you can speed things up.

