Stumped by python passwords

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: AmyCowen, kgudger, bfinio, MadelineB, Moderators

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

Stumped by python passwords

Post by awesomesciencegirl »

Hi, I'm working on the password cracking project, https://www.sciencebuddies.org/science- ... 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.
	password=eval("password"+str(num))
	#guessmypassword is the function I wrote that uses a bunch of ways to guess passwords
	guessmypassword(password)
	
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?
HowardE
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: Stumped by python passwords

Post by HowardE »

awesomesciencegirl-

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")'
    #
    password1="202cb962ac59075b964b07152d234b70"
    password2="570a90bfbf8c7eab5dc5d4e26832d5b1"
    password3="f78f2477e949bee2d12a2c540fb6084f"
    password4="09408af74a7178e95b8ddd4e92ea4b0e"
    password5="2034f6e32958647fdff75d265b455ebf"
    password6="9b3af42d61cde121f40b96097fb77d3e"

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


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)")
    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")
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.

Howard
Locked

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