I have been trying to make a simple zip file password cracker (just for fun, not malicious purposes) however my try and except statement will not work. No matter the input it always leads to the except statement, and the else is never executed (even though the zip file does extract)
import zipfile
k = 0
file = zipfile.ZipFile('john.zip')
def check(i):
p = bytes(i, 'ascii')
try:
file.extractall(pwd=p)
except:
return False
else:
return True
def crack():
x = open('john(1).txt', 'r')
for i in x.readlines():
i.strip('\n')
k = check(i)
if k == True:
print('Password is: ' + k)
break;
x.close()
x.close()`
1) Log the error in the except block. Helps a lot.
2) You are closing the file in the 'for' loop. Bad idea as the loop reads lines from the file.
3) The last line has a reverse quote character at the end (may be a typo in the question): `