Python Forum
Brute Force Pad Lock Guesser
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Brute Force Pad Lock Guesser
#1
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?
Reply
#2
your while loop wont print out After 1080 guesses... with that !=, try other comparison operator instead?
swallow osama bin laden
Reply
#3
(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. ...
Reply
#4
https://docs.python.org/3.4/library/stri...i-language
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need an alternative to brute force optimization loop jmbonni 5 1,178 Dec-07-2023, 12:28 PM
Last Post: RockBlok
  Solving an equation by brute force within a range alexfrol86 3 2,783 Aug-09-2022, 09:44 AM
Last Post: Gribouillis
  force a program to exit ? Armandito 3 2,524 May-12-2022, 04:03 PM
Last Post: Gribouillis
  How to use scipy.optimization.brute for multivariable function Shiladitya 9 6,203 Oct-28-2020, 10:40 PM
Last Post: scidam
  best way to force an exception Skaperen 2 2,064 Oct-21-2020, 05:59 AM
Last Post: Gribouillis
  I need advise with developing a brute forcing script fatjuicypython 11 5,070 Aug-21-2020, 09:20 PM
Last Post: Marbelous
  Cant find root cause of thread.lock error burlyboys 0 1,552 May-18-2020, 12:51 PM
Last Post: burlyboys
  Force calculation result as decimal vercetty92 4 2,866 Mar-20-2019, 02:27 PM
Last Post: vercetty92
  Password Brute Force 2skywalkers 9 5,359 Oct-18-2018, 02:35 PM
Last Post: buran
  Brute Force Password Guesser 2skywalkers 1 3,181 Oct-05-2018, 08:04 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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