0

how I change this code to use a txt file instead of URL

from urllib.request import urlopen, hashlib sha1hash = input("Please input the hash to crack.\n>") LIST_OF_COMMON_PASSWORDS=str(urlopen('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt').read(), 'utf-8') for guess in LIST_OF_COMMON_PASSWORDS.split('\n'): hashedGuess = hashlib.sha1(bytes(guess, 'utf-8')).hexdigest() if hashedGuess == sha1hash: print("The password is ", str(guess)) quit() elif hashedGuess != sha1hash: print("Password guess ",str(guess)," does not match, trying next...") print("Password not in database, we'll get them next time.")

24th Jan 2023, 2:54 PM
NS7
NS7 - avatar
2 Answers
+ 9
NS7 , instead of using the python *path* module, we can use the python module *pathlib*, that offers object-oriented filesystem paths. https://docs.python.org/3/library/pathlib.html#module-pathlib > for reading from a txt file, we also need to use the built-in function *open()* . https://www.sololearn.com/learn/Python/2445/?ref=app https://www.sololearn.com/learn/Python/2447/?ref=app https://www.sololearn.com/learn/Python/2446/?ref=app https://www.sololearn.com/learn/Python/2448/?ref=app
24th Jan 2023, 3:41 PM
Lothar
Lothar - avatar
+ 3
You would need to use a path if the txt file on your machine. Check out the os library for using paths: https://docs.python.org/3/library/os.path.html
24th Jan 2023, 3:15 PM
Justice
Justice - avatar