1

I'm attempting to write a "cash box" style password breaker that spins dials, each dial has every character on it, until the answer is found. I'm quite new to Python (And coding in general), but with a lot of help I was able to do it with numbers and letter (capitalized and decapitalized)

Now I'm trying to build it so it only checks for numbers and decapitalized letters, not capital letters. Here is what I got:

def method_2(num_pass_wheels):
    result = False
    still_searching = True
    print()
    print("Using method 2 and searching with " + str(num_pass_wheels) + " characters.")
    wheel = " abcdefghijklmnopqrstuvwxyz0123456789"
# 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_pass(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

 # 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

    return result

The error message points to:

line 341, in <module>
    foundit = method_2(8)

line 188, in method_2
    ourguess_pass = wheel[pass_wheel_array[i]] + ourguess_pass

And throws the error:

IndexError: string index out of range

I know it has something to do with me removing the capital letters from "wheel" but I don't know how to go about fixing it. Any help?

1
  • 2
    Is len(num_pass_wheels) the same as len(pass_wheel_array)? Print both of those lengths and i and I guess len(wheel) and pass_wheel_array[i], just before the offending statement - that should help you figure it out. Commented Jan 8, 2018 at 2:52

1 Answer 1

2

You hard coded a length check limit here:

        if pass_wheel_array[i] > 62: <-----
            pass_wheel_array[i] = 1
            carry = 1

wheel only has only has 36 items in the version you posted. Instead of using 62 use len(wheel).

But since array indices are zero based, you might want to change it to

if pass_wheel_array[i] > len(wheel) - 1:
#or
if pass_wheel_array[i] == len(wheel):
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, that fixed it. Really dumb mistake there, completely forgot about coding that in. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.