You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.7.2 32位ZIP密码破解器语法错误求助

Fixing Your Python ZIP Password Cracker

Hey there! Let's start with the immediate syntax error that's throwing you off, then go through a few other adjustments to make your cracker more reliable and efficient.

The Direct Syntax Fix

The error you're seeing (invalid syntax on line 18) is a simple typo: you wrote for j im map(...) instead of for j in map(...). Swap im to in and that syntax error will vanish right away.

Other Critical Tweaks to Avoid Headaches

Beyond that typo, there are a few issues that will either break your script or make it perform poorly:

1. Variable Name Conflict

You're using zipfile as a variable name for your ZIP archive, but that's the same name as the module you imported. This will cause problems if you try to use any other functions from the zipfile module later. Let's rename that variable to something like zip_archive:

zip_archive = zipfile.ZipFile("D:\\-----[WEBSITE]-----\\Source1.zip")

2. Overly Broad Exception Handling

Your except: clause catches all exceptions, including things like KeyboardInterrupt (which would prevent you from stopping the script with Ctrl+C) or actual file errors. Instead, only catch the specific exception thrown for bad passwords:

except RuntimeError:
    pass

This way, genuine errors (like a corrupted ZIP file) will still show up, so you can debug them properly.

3. Thread Explosion

Creating a new thread for every single password guess is a terrible idea—for 3-letter passwords alone, that's 52³ = 140,608 threads. Your system can't handle that many threads at once, and it'll grind to a halt. Instead, use a thread pool to limit the number of concurrent threads (we'll use concurrent.futures.ThreadPoolExecutor for this).

4. Stop All Work Once the Password is Found

Right now, even after finding the password, your script will keep spawning new threads. Let's add a global flag to signal all threads to stop once the password is cracked.

Revised Working Code

Here's the fixed version with all these adjustments:

import zipfile
import itertools
import string
from concurrent.futures import ThreadPoolExecutor
import traceback

# Flag to stop all threads once password is found
password_found = False

def crack(zip_archive, pdw):
    global password_found
    if password_found:
        return
    try:
        zip_archive.extractall(pwd=pdw.encode('utf-8'))
        print(f'Geschafft: Passwort ist {pdw}')
        password_found = True
    except RuntimeError:
        pass

if __name__ == "__main__":
    zip_archive = zipfile.ZipFile("D:\\-----[WEBSITE]-----\\Source1.zip")
    myLetters = string.ascii_letters
    
    # Use a thread pool with 10 concurrent threads (adjust based on your system)
    with ThreadPoolExecutor(max_workers=10) as executor:
        for i in range(3, 10):
            if password_found:
                break
            # Generate all possible combinations for current length
            combinations = itertools.product(myLetters, repeat=i)
            for combo in combinations:
                if password_found:
                    break
                pdw = ''.join(combo)
                executor.submit(crack, zip_archive, pdw)

Quick Notes

  • The max_workers value in ThreadPoolExecutor can be adjusted based on your CPU cores—start with 10-20 and tweak if needed.
  • string.ascii_letters includes both uppercase and lowercase letters; if your password might have numbers or symbols, add string.digits or string.punctuation to myLetters.
  • Brute-forcing passwords longer than 5-6 characters will take a very long time—if you have any idea about possible characters or patterns, narrow down the myLetters set to speed things up.

内容的提问来源于stack exchange,提问作者LeqitShxdow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:15:12