Python Forum
Brute Force Pad Lock Guesser - 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: Brute Force Pad Lock Guesser (/thread-8542.html)



Brute Force Pad Lock Guesser - RedSkeleton007 - Feb-25-2018

I'm trying to learn how to have more control over increments, but I have a delema (see comments in following code):

#!/usr/bin/env python3
#PadLockGuesser.py

lockCombo = 1080

#brute force pad lock guesser with while loop:
guess = 0
while guess != lockCombo:
    #guess += 1#placing the guess incrementor here causes 0 to not be one of the guesses
    if guess == lockCombo:
        print("After " + str(guess) + " guesses, the correct combo is " + str(guess))
        break
    else:
        print(str(guess) + " is not the correct combo. Trying next guess.")
        guess += 1#placing the guess incrementor here causes the program to stop guessing at 1079
        continue

#brute force pad lock guesser with for loop:
guessAgain = 0
for i in range(0000,9999):
    if guessAgain == lockCombo:
        print("After " + str(guessAgain) + " guesses, the correct combo is " + str(guessAgain))
        break
    else:
        print(str(guessAgain) + " is not the correct combo. Trying next guess.")
        guessAgain += 1
The output of the for loop, however, is correct:
Output:
0 is not the correct combo. Trying next guess. 1 is not the correct combo. Trying next guess. 2 is not the correct combo. Trying next guess. 3 is not the correct combo. Trying next guess. ... 1077 is not the correct combo. Trying next guess. 1078 is not the correct combo. Trying next guess. 1079 is not the correct combo. Trying next guess. After 1080 guesses, the correct combo is 1080
How do I get the while loop to produce the same output?


RE: Brute Force Pad Lock Guesser - ka06059 - Feb-26-2018

your while loop wont print out After 1080 guesses... with that !=, try other comparison operator instead?


RE: Brute Force Pad Lock Guesser - RedSkeleton007 - Feb-28-2018

(Feb-26-2018, 06:48 AM)ka06059 Wrote: your while loop wont print out After 1080 guesses... with that !=, try other comparison operator instead?
I forgot that I wasn't comparing strings, which means the <= operator worked!

Does anybody know any formatting techniques that would cause the output to be four digits the whole time?
For instance, how could I turn this output:
Output:
0 is not the correct combo. Trying next guess. 1 is not the correct combo. Trying next guess. 2 is not the correct combo. Trying next guess. 3 is not the correct combo. Trying next guess. ...
Into this output:
Output:
0000 is not the correct combo. Trying next guess. 0001 is not the correct combo. Trying next guess. 0002 is not the correct combo. Trying next guess. 0003 is not the correct combo. Trying next guess. ...



RE: Brute Force Pad Lock Guesser - buran - Feb-28-2018

https://docs.python.org/3.4/library/string.html#format-specification-mini-language


RE: Brute Force Pad Lock Guesser - RedSkeleton007 - Mar-03-2018

zfill is the answer:

#!/usr/bin/env python3
#PadLockGuesser.py

lockCombo = 1080

#brute force pad lock guesser with while loop:
guess = 0
while guess <= lockCombo:
    #guess += 1#placing the guess incrementor here causes 0 to not be one of the guesses
    if guess == lockCombo:
        print("After " + str(guess) + " guesses, the correct combo is " + str(guess))
        break
    else:
        print(str(guess).zfill(4) + " is not the correct combo. Trying next guess.")
        guess += 1#placing the guess incrementor here causes the program to stop guessing at 1079
        continue