0

I'm quite new to coding and trying to crack a password with the help of a .txt file. This is my code so far:

import pyautogui
import random

dictionary = ()

real_pwd = pyautogui.password('Enter password: ')




# posibilities = len(chars) ** len(real_pwd)
# guess_pwd = ""
password = ""

with open("TinyButMighty.txt", "r") as wordlist:
    for line in wordlist:
        password = line.strip()
        print("denied:", str(password))
        if password == real_pwd:
            print("\nAccess Granted: ~ ", "".join(password))
            break

However when i run it with the TinyButMighty.txt i get:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 125: invalid start byte

If i make a short list of words myself it doesn't run into any trouble.

Does anyone have an idea on how to surpass this problem?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Dirk Span
  • 1
  • 1
  • It seems like your file can't be decoded in `utf-8`. Did you write the file yourself? – Roy Cohen Dec 17 '20 at 12:07
  • 1
    Your input seems to be in an other encoding as UTF-8, which is the default on Python 3. You can give the `encoding` argument to the `open()` call to adjust it to the right encoding. In most iso-8859 encodings `0xb2` is a `²`. – Klaus D. Dec 17 '20 at 12:09
  • Try ```open("TinyButMighty.txt", "r", encoding='latin-1')```. – Henry Tjhia Dec 17 '20 at 12:15
  • Note that if the file's *actual* encoding isn't really Latin-1, this will simply hide the error and allow - nay, force - the program to produce garbage. – tripleee Dec 18 '20 at 17:26

0 Answers0