Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Guesser Project
#1
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 = true
Of 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?
Reply
#2
I think you could do less than or equal to <= or just i < (len(AlphaNum) + 1)
Reply
#3
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
Reply
#4
I think you need to write True- it has to be capital
Reply
#5
I now get the error:
#while guess[len(guess)-1] <= AlphaNum[len(AlphaNum)-1]:
#IndexError: string index out of range
If 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))
        break
Any ideas?
Reply
#6
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...
Reply
#7
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 assignment
Once 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
Reply
#8
(Nov-01-2017, 05:44 PM)RedSkeleton007 Wrote:
Error:
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 assignment

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'
Reply
#9
(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:
Error:
Traceback (most recent call last): File "I:\Python\Python36-32\SamsPrograms\PasswordGuesser.py", line 9, in <module> guess = ''.join(guestList)#convert to a string, so we can print guess as a string NameError: name 'guestList' is not defined
Reply
#10
one is guest and the other is guess
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Brute Force Password Guesser 2skywalkers 1 3,140 Oct-05-2018, 08:04 PM
Last Post: ichabod801
  Brute Force Pad Lock Guesser RedSkeleton007 4 3,882 Mar-03-2018, 07:42 AM
Last Post: RedSkeleton007
  Speeding up Brute force password guesser Gamervote 5 6,745 Jul-20-2017, 02:52 PM
Last Post: nilamo
  Password Hacker Science Project BenjC 2 4,864 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