Password Guesser Project - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Password Guesser Project (/thread-5787.html) Pages:
1
2
|
Password Guesser Project - RedSkeleton007 - Oct-22-2017 For now, I need an iterator that points to the chars in my AlphaNum string properly. We will start out with a password of just one char in length. Observe the code below: #!/usr/bin/env python3 #PasswordGuesser.py AlphaNum = "abc" guess = "" #bool guessMatches = false password = "b" guessLength = len(guess) guessLength = 1 #start with a guess length of just one char def iterateAlphaNum(): i = 0 while i < len(AlphaNum): guess[0] == AlphaNum[i] i += 1 #Master While Loop: while the last char of the guess string has not yet passed #the last char in AlphaNum while guess[len(guess)-1] !> AlphaNum[len(AlphaNum)-1]: guess[0] = iterateAlphaNum() if guess == password: guessMatches = trueOf course, I don't want the while loop to stop BEFORE it tries the last char (c from AlphaNum). That's why I've tried in vein use the invalid syntax of !> (not greater than, therefore hasn't already stopped after reaching the last char in AlphaNum). Any suggestions? RE: Password Guesser Project - Lux - Oct-22-2017 I think you could do less than or equal to <= or just i < (len(AlphaNum) + 1)
RE: Password Guesser Project - RedSkeleton007 - Oct-22-2017 Next little problem. It says my syntax for guessMatches is invalid. How do I correctly declare a boolean variable? #!/usr/bin/env python3 #PasswordGuesser.py AlphaNum = "abc" guess = "" bool guessMatches = false password = "b" guessLength = len(guess) guessLength = 1 #start with a guess length of just one char def iterateAlphaNum(): i = 0 while i < len(AlphaNum): guess[0] == AlphaNum[i] i += 1 #Master While Loop: while the last char of the guess string has not yet passed #the last char in AlphaNum while guess[len(guess)-1] <= AlphaNum[len(AlphaNum)-1]: guess[0] = iterateAlphaNum() print(guess) if guess == password: guessMatches = true print() print("Found the password! It's " + str(guess)) break RE: Password Guesser Project - Lux - Oct-22-2017 I think you need to write True - it has to be capital
RE: Password Guesser Project - RedSkeleton007 - Oct-23-2017 I now get the error: #while guess[len(guess)-1] <= AlphaNum[len(AlphaNum)-1]: #IndexError: string index out of rangeIf I'm not mistaking, I looks like my program is trying to compare a one-char length guess string with a three-char length AlphaNum (such as 'a' with 'abc'). But that's not what what I'm trying to do. Currently, my guess string is only one char as I have declared it on line 9 of the code below, so guess[len(guess)-1] should just equal guess[0], and AlphaNum[len(AlphaNum)-1] should simply be referring to the last char in AlphaNum: #!/usr/bin/env python3 #PasswordGuesser.py AlphaNum = "abc" guess = "" guessMatches = False password = "b" guessLength = len(guess) guessLength = 1 #start with a guess length of just one char def iterateAlphaNum(): i = 0 while i < len(AlphaNum): guess[0] == AlphaNum[i] i += 1 #Master While Loop: while the last char of the guess string has not yet passed #the last char in AlphaNum while guess[len(guess)-1] <= AlphaNum[len(AlphaNum)-1]: guess[0] = iterateAlphaNum() print(guess) if guess == password: guessMatches = True print() print("Found the password! It's " + str(guess)) breakAny ideas? RE: Password Guesser Project - Lux - Oct-29-2017 I tried running the code. I'm not sure why, but your 'guess' string seems to have a length of 0 at that point. Sidenote- why are you using guess[0] ? guess is a string, you could just set its value...
RE: Password Guesser Project - RedSkeleton007 - Nov-01-2017 I'm having trouble getting the guess string indexes to point to the indexes of AlphaNum. #!/usr/bin/env python3 #PasswordGuesser.py AlphaNum = "abc" passwordThatNeedsToBeGuessed = "cab" guessMatches = False guess = "" guessLength = len(guess) guessLength = 1 #start with a guess length of just one char for char in AlphaNum: guess[0] = char print(guess) guessLength = 2 for char in AlphaNum: guess[0] = char for char in AlphaNum: guess[1] = char guess = guess[1] + guess[0] print(guess) guessLength = 3 for char in AlphaNum: guess[0] = char print(guess) for char in AlphaNum: guess[1] = char guess = guess[1] + guess[0] print(guess) for char in AlphaNum: guess[2] = char guess = guess[2] + guess[1] + guess[0] print(guess) The error in the IDLE shell is: Traceback (most recent call last): File "E:\Python\Python36-32\SamsPrograms\PasswordGuesser.py", line 12, in <module> guess[0] = char TypeError: 'str' object does not support item assignmentOnce these for loops are functioning properly, the output of this program should be exactly: a b c aa ba ca ab bb cb ac bc cc aaa baa caa aba bba cba aca bca cca aab bab cab abb bbb cbb acb bcb ccb aac bac cac abc bbc cbc acc bcc ccc RE: Password Guesser Project - nilamo - Nov-01-2017 (Nov-01-2017, 05:44 PM)RedSkeleton007 Wrote: Strings are immutable. Which means you can't modify them. If you want to change the first character of a string to something else, you need to create a new string instead (or use something else that is mutable, like a list). >>> chars = "spam" >>> chars[0] 's' >>> chars[0] = "e" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment >>> chars = "e" + chars[1:] >>> chars 'epam' RE: Password Guesser Project - RedSkeleton007 - Nov-13-2017 (Nov-01-2017, 06:41 PM)nilamo Wrote: Strings are immutable. Which means you can't modify them. If you want to change the first character of a string to something else, you need to create a new string instead (or use something else that is mutable, like a list). Is that so? Well, I did some tweaking, but I have some traceback errors. I know the syntax for converting a list to string and converting a string to a list is correct, because I tested it in another simpler program, so I suspect variable scope might be the problem. In any case, here's my code: #!/usr/bin/env python3 #PasswordGuesser.py AlphaNum = "abc" passwordThatNeedsToBeGuessed = "cab" guessMatches = False guess = "" guessList = list(guess)#make a list version of guess, so we can change the chars guess = ''.join(guestList)#convert to a string, so we can print guess as a string guessLength = len(guess) ##def iterateAlphaNum(): ## i = 0 ## while i < len(AlphaNum): ## guess[0] == AlphaNum[i] ## i += 1 guessLength = 1 #start with a guess length of just one char char1 = 0 for char1 in AlphaNum: guessList[0] = AlphaNum[char1] char1 += 1 print(guess) guessLength = 2 char1 = 0 char2 = 0 guessList = list(guess) for char1 in AlphaNum: guessList[0] = AlphaNum[char1] char1 += 1 for char2 in AlphaNum: guessList[1] = AlphaNum[char2] guess = guessList[1] + guessList[0] char2 += 1 print(guess)And the traceback:
RE: Password Guesser Project - metulburr - Nov-13-2017 one is guest and the other is guess |