Posts: 1
Joined: Fri Feb 19, 2016 6:50 am
Occupation: Student

Stumped by python passwords

Postby awesomesciencegirl » Fri Feb 19, 2016 7:02 am

Hi, I'm working on the password cracking project, ... p046.shtml and our fair is in about 3 weeks. I'm supposed to demonstrait it in class next week though. I ran into a problem with the program and need some help.

I added in some functions that I think will gusss just about anything. I want my program to try ALL of the passwords and not just 1 so I added this code and it doesn't work

Code: Select all

for num in range(0,5):
   # this line adds a number to the end of the word password so it's like password0 or whatever and then gets the value of that password as the password to guess. It will try all 6 of them.
   #guessmypassword is the function I wrote that uses a bunch of ways to guess passwords

What happens is that it runs forever on even simple passwords. I tried just guessing simple numbers like the 314 it came with and that doesn't work either. Did I do something stupid?

Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer

Re: Stumped by python passwords

Postby HowardE » Fri Apr 08, 2016 4:21 pm


I'm sorry that no one answered your question. The experts here generally try to make sure everyone gets an answer. I'm not sure what happened. I hope the fair went well for you and that you figured this out for yourself. Again, I'm sorry we didn't help.

You were on the right track though. The guessing methods generate the guess and pass that along with a number from 0 to 6 to the checking function. All you needed to do is set up your 'guessmypassword()' like you had planned and tell it which of the passwords it's guessing. I took the main() function from the downloaded version, broke it into two and did this which I think is what you were looking for:

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
    # data blocks. Set them up using MD5me like:
    #     'password1=MD5me("ScienceBuddies")'

    for num in range(0,5):
        print("* * * * * * *")

def guessmypassword(n):
    # start searching
    which_password = n
    ## which_password = int(input("Which password (0-6)? "))
    overallstart = time.time()
    foundit = False
    print("Trying to guess password "+str(which_password))
    # 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)")
        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")
        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.")
            print("You can confirm your find at")

The guessing is exactly the same, but instead of asking you which one to guess, it iterates from 0 to 5 as you had planned. I hope seeing the technique is still helpful.


Return to “Grades 6-8: Math and Computer Science”