-1

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()`
msw
  • 42,753
  • 9
  • 87
  • 112
Ellis
  • 105
  • 2
  • 10

2 Answers2

1

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): `

ChrisC73
  • 1,833
  • 14
  • 14
0

I got it working with a couple of changes in crack() as shown in comments below. Here is what worked for me:

…
def crack():
    x = open('john(1).txt', 'r')
    for i in x.readlines():
        i = i.strip() # not just the statement i.strip('\n')
        k = check(i)
        if k == True:
            print('Password is: ' + i) # not print('Password is: ' + k)
…
msw
  • 42,753
  • 9
  • 87
  • 112