Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Guesser Project
#17
Okay, first of all, what is wrong with line 86? Am I not allowed to call the main function where ever I want?

Second, initializing i and n to 0 on lines 9 and 10 doesn't make them global constants, does it?

Finally, the third error says that I'm referencing a local variable before assignment, and yet I've initialized the guess string to "" on line 7 before converting it to guessList.

#!/usr/bin/env python3
#SamsPasswordGuesser.py
import sys

AlphaNum = "abc"#temporary AlphaNum. Will add more characters after program works.
password = "cab"
guess = ""#default length is 0
AN_size = AlphaNum[len(AlphaNum)-1]
i = 0
n = 0
def passwordGuesser(n,i):#guessList[n], AlphaNum[i]
    guessList = list(guess)
    if len(guessList) < 1:
        guessList.append(AlphaNum[0])

    print(guess)#output current guess

    guess = ''.join(guessList)
    if guess == password:
        print("The password is: " + guess)
        sys.exit

    else:
        guessList = list(guess)
        guessList[n] = AlphaNum[i]#point current guessList char to the char in AlphaNum

        if guessList[n] < AlphaNum[-1]:
            i += 1
            guessList[n] = AlphaNum[i]

        elif i == (len(AlphaNum)-1):#if we are pointing to the last char in the AlphaNum string,
            guessList[n] = AlphaNum[i]#then apply it to the current guessList char.

        else:#if we have exhausted all possible chars in AlphaNum to be pointed to for the current guessList char,
            for n in range(0, guessList[n]):#then reset all characters (guessList elements) on the left to AlphaNum[0].
                guessList[n] = AlphaNum[0]

            #However, before we reset the current guessList char to AlphaNum[0], we need to check if we are already at
            #the end of guessList. If we are not, then the current guessList char also needs to be reset to AlphaNum[0],
            #and the next guessList index value to the right needs to point to the next char in AlphaNum. If we ARE already
            #at the end of guessList, then we need to make sure that we reset all chars in guessList to AlphaNum[0], and
            #increase the length of guessList by one for a new password guess length. This needs to be done with the following:

            if guessList[n] == guessList[-1] and guessList[n] == AlphaNum[-1]:#if we are at the last index of guessList,
                #and it is pointing to the last char in AlphaNum,
                guessList[n] = AlphaNum[i]#then apply it to the current guessList char. For example, a guess string of "ccc"
                #must be tested against the password before we test "aaaa" against the password.

            elif guessList[n] == guessList[-1] and guessList[n] < AlphaNum[-1]:#if we are at the last index of guessList,
                #but it has not yet pointed to the last char in AlphaNum,
                i += 1#then point to the next char in AlphaNum,
                guessList[n] = AlphaNum[i]#apply it to the current guessList index,
                guessList[n] = guessList[0]#and move back to the first index of guessList (without overwritting the current
                #guessList char we just got done making point to the char in AlphaNum with what's currently at guessList[0])

            elif guessList[n] < guessList[-1] and guessList[n] < AlphaNum[-1]:#if we are NOT at the last index of guessList,
                #and it has not yet pointed to the last char in AlphaNum,
                i += 1#then point to the next char in AlphaNum,
                guessList[n] = AlphaNum[i]#apply it to the current guessList index,
                guessList[n] = guessList[0]#and move back to the first index of guessList (without overwritting the current
                #guessList char we just got done making point to the char in AlphaNum with what's currently at guessList[0])

            elif guessList[n] < guessList[-1] and guessList[n] == AlphaNum[-1]:#if we are NOT at the last index of guessList,
                #but it IS pointing to the last char in AlphaNum,
                guessList[n] = AlphaNum[i]#then apply it to the current guessList char. For example, a guess string of "bcc"
                #must be tested against the password before we test "ccc" against the password.
                guessList[n] = guessList[0]#and move back to the first index of guessList (without overwritting the current
                #guessList char we just got done making point to the char in AlphaNum with what's currently at guessList[0])

            else:#if we are NOT at the last index of guessList, but we have exhausted all possible chars in AlphaNum to be pointed
                #to for the current guessList char,
                i += 1#then make a pointer to the next char in AlphaNum,
                n += 1#move to the next guessList char,
                guessList[n] = AlphaNum[i]#apply it to the current guessList char,
                for n in range(0, guessList[n]):#reset all characters (guessList elements) on the left to AlphaNum[0]
                    #(for example, "ccca" would become "aaab"),
                    guessList[n] = AlphaNum[0]
                guessList[n] = guessList[0]#and move back to the first index of guessList (without overwritting the current
                #guessList char we just got done making point to the char in AlphaNum with what's currently at guessList[0])

            passwordGuesser(n,i)#and the function begins again until the password is guessed!

def main():
    passwordGuesser(n,i)

main()
Error:
Traceback (most recent call last): File "I:\Python\Python36-32\SamsPrograms\SamsPasswordGuesser.py", line 86, in <module> main() File "I:\Python\Python36-32\SamsPrograms\SamsPasswordGuesser.py", line 84, in main passwordGuesser(n,i) File "I:\Python\Python36-32\SamsPrograms\SamsPasswordGuesser.py", line 12, in passwordGuesser guessList = list(guess) UnboundLocalError: local variable 'guess' referenced before assignment
Reply


Messages In This Thread
Password Guesser Project - by RedSkeleton007 - Oct-22-2017, 05:46 AM
RE: Password Guesser Project - by Lux - Oct-22-2017, 02:55 PM
RE: Password Guesser Project - by RedSkeleton007 - Oct-22-2017, 08:05 PM
RE: Password Guesser Project - by Lux - Oct-22-2017, 09:21 PM
RE: Password Guesser Project - by RedSkeleton007 - Oct-23-2017, 02:10 AM
RE: Password Guesser Project - by Lux - Oct-29-2017, 01:54 AM
RE: Password Guesser Project - by RedSkeleton007 - Nov-01-2017, 05:44 PM
RE: Password Guesser Project - by nilamo - Nov-01-2017, 06:41 PM
RE: Password Guesser Project - by RedSkeleton007 - Nov-13-2017, 03:53 AM
RE: Password Guesser Project - by metulburr - Nov-13-2017, 04:01 AM
RE: Password Guesser Project - by RedSkeleton007 - Nov-13-2017, 05:10 AM
RE: Password Guesser Project - by nilamo - Nov-19-2017, 04:43 PM
RE: Password Guesser Project - by RedSkeleton007 - Nov-20-2017, 07:03 AM
RE: Password Guesser Project - by RedSkeleton007 - Nov-27-2017, 05:33 AM
RE: Password Guesser Project - by nilamo - Nov-27-2017, 06:42 PM
RE: Password Guesser Project - by RedSkeleton007 - Nov-28-2017, 08:58 PM
RE: Password Guesser Project - by nilamo - Nov-29-2017, 07:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Brute Force Password Guesser 2skywalkers 1 3,223 Oct-05-2018, 08:04 PM
Last Post: ichabod801
  Brute Force Pad Lock Guesser RedSkeleton007 4 4,010 Mar-03-2018, 07:42 AM
Last Post: RedSkeleton007
  Speeding up Brute force password guesser Gamervote 5 6,922 Jul-20-2017, 02:52 PM
Last Post: nilamo
  Password Hacker Science Project BenjC 2 4,979 Apr-17-2017, 07:36 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020