import string import itertools from Crypto.Cipher import ARC4 import rarfile import concurrent.futures def gen_password(passwd): key = passwd.encode() cipher = ARC4.new(key) return cipher rar_path = "E:/Edge浏览器下载/30.rar" rar = rarfile.RarFile(rar_path) def try_passwords(rar_path, dictionary, max_workers=4): rar = rarfile.RarFile(rar_path) tested = set() with concurrent.futures.ProcessPoolExecutor(max_workers) as executor: fs = [] for password in dictionary: password_str = ''.join(password) if password_str in tested: continue tested.add(password_str) decrypt_pwd = gen_password(password_str) fs.append(executor.submit(rar.extractall, pwd=decrypt_pwd)) for index, future in enumerate(concurrent.futures.as_completed(fs)): try: future.result() print(f'成功!密码是: {dictionary[index]}') return dictionary[index] except (rarfile.BadRarFile, rarfile.RarWrongPassword): pass characters = string.ascii_letters + string.digits + string.punctuation dictionary = itertools.product(characters, repeat=1) result = try_passwords(rar_path, dictionary) print(result) 更改该代码的错误
时间: 2024-01-15 19:03:34 浏览: 89
这段代码缺少一些必要的库和变量定义,我假设你想使用一个密码字典文件来进行暴力破解。以下是更改后的代码:
```
import string
import itertools
import rarfile
import concurrent.futures
from Crypto.Cipher import ARC4
def gen_password(passwd):
key = passwd.encode()
cipher = ARC4.new(key)
return cipher
rar_path = "E:/Edge浏览器下载/30.rar"
def try_passwords(rar_path, dictionary_file, max_workers=4):
rar = rarfile.RarFile(rar_path)
tested = set()
with open(dictionary_file, 'r') as f:
dictionary = f.read().splitlines()
with concurrent.futures.ProcessPoolExecutor(max_workers) as executor:
fs = []
for password in dictionary:
password_str = password.strip()
if password_str in tested:
continue
tested.add(password_str)
decrypt_pwd = gen_password(password_str)
fs.append(executor.submit(rar.extractall, pwd=decrypt_pwd))
for index, future in enumerate(concurrent.futures.as_completed(fs)):
try:
future.result()
print(f'成功!密码是: {dictionary[index]}')
return dictionary[index]
except (rarfile.BadRarFile, rarfile.RarWrongPassword):
pass
result = try_passwords(rar_path, 'passwords.txt')
print(result)
```
你需要将 `passwords.txt` 替换为你自己的密码字典文件路径。
阅读全文