Python Forum
looping wordlist keeps repeating when word not found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looping wordlist keeps repeating when word not found
#1
Hi,

I have a excel password recovery tool that I have built and it keeps looping through the same wordlist even though it has not been found, what am I missing?

    for x in range(1, len(a)):
        if flag == 1:
            for y in tqdm(permutations(a, x),total=n_words, unit=" words"):
                mypass = ''.join(y)
                passwords_tried = passwords_tried + 1
                try:
                        wb = myfile.Workbooks.Open(xlfile, False, True, None, mypass)
                        # Method: Workbooks.Open(Filename, UpdateLine, ReadOnly, Format, password)
                        wb.Close()
                        flag = flag + 1
                        break

                except:
                        pass
                        print("Incorrect password")
                    
    print("[+] Password Found in "+ str(passwords_tried) + " attempts, Password is " + str(mypass))

if __name__ == '__main__':
        try:
            xlkraken()
        except FileNotFoundError:
            print(Fore.RED,'\n[*] xlkraken interrupted: File path not entered or does not exist!!!')
        except KeyboardInterrupt:
            print(Fore.RED,'\n[*] xlkraken interrupted by user!!!')
        pass
            
print(Fore.BLUE)        
input('Press Enter to Exit')
Reply
#2
You have two for loops, but only break out of one of them. If the intention is to break out of more than one, then either multiple breaks are needed, or just put it in a function and use return instead.

def find_password(myfile, xlfile, a, n_words):
    passwords_tried = 0
    for x in range(1, len(a)):
        for y in tqdm(permutations(a, x),total=n_words, unit=" words"):
            mypass = ''.join(y)
            passwords_tried = passwords_tried + 1
            try:
                wb = myfile.Workbooks.Open(xlfile, False, True, None, mypass)
                # Method: Workbooks.Open(Filename, UpdateLine, ReadOnly, Format, password)
                wb.Close()
                return mypass
             except:
                print("Incorrect password")
    return None # or "" if you prefer
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 704 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 2,291 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 2,509 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  matching a repeating string Skaperen 2 1,256 Jun-23-2022, 10:34 PM
Last Post: Skaperen
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,508 Aug-12-2021, 04:25 PM
Last Post: palladium
  Random Number Repeating Tzenesh 5 4,044 Jan-13-2021, 10:00 PM
Last Post: deanhystad
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,552 Nov-23-2020, 05:15 PM
Last Post: cananb
  factorial, repeating Aldiyar 4 2,811 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Python Speech recognition, word by word AceScottie 6 16,011 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  number repeating twice in loop JonnyEnglish 3 3,317 Nov-24-2019, 09:23 AM
Last Post: ThomasL

Forum Jump:

User Panel Messages

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