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 1,750 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 4,774 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 4,534 Jul-14-2022, 12:40 PM
Last Post: Frankduc
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 3,563 Aug-12-2021, 04:25 PM
Last Post: palladium
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 3,393 Nov-23-2020, 05:15 PM
Last Post: cananb
  factorial, repeating Aldiyar 4 3,817 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Python Speech recognition, word by word AceScottie 6 18,219 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  How to generate Lines from wordlist? python7777 1 2,114 Oct-22-2019, 02:00 PM
Last Post: ichabod801
  print a word after specific word search evilcode1 8 6,309 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Repeating equations Tbot100 2 4,066 May-29-2019, 02:38 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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