Python 官方文档:入门教程 => 点击学习
目录简介:1.步骤1.环境2.判断文件格式3.判断是否有密码4.密码字典 自己写或者下载相应的软件生成。5.解压文件2.代码1.在线调试2.脚本运行简介: 破解rar和zip压缩包。
破解rar和zip压缩包。windows下使用PyCharm软件。
type = os.path.splitext(path)[-1][1:]
if type == "zip":
elif type == "rar":
type = os.path.splitext(path)[-1][1:]
if type == "zip":
fileGet = zipfile.ZipFile(path)
with fileGet as z:
for l in z.infolist():
is_encrypted = l.flag_bits & 0x1
if is_encrypted:
print("have passWord ")
break
else:
pass
elif type == "rar":
fileGet = rarfile.RarFile(path)
with fileGet as z:
if z.needs_password():
print("have password ")
else:
print("no password")
return
1.zip和rar
fileGet = zipfile.ZipFile(path)
fileGet = rarfile.RarFile(path)
2.解压
fileExtr.extractall(pwd=password)
import sys
import zipfile
import rarfile
import threading
import datetime
import os
import subprocess
import getopt
i = 0
fileGet = ""
class MyThread(threading.Thread):
def __init__(self, func, args, name=''):
threading.Thread.__init__(self)
self.name = name
self.func = func
self.args = args
self.result = self.func(*self.args)
def get_result(self):
try:
return self.result
except Exception:
return None
def extractFile(fileExtr, password, fileType):
try:
encodestr = str.encode(password)
if (fileType == "zip"):
fileExtr.extractall(pwd=str.encode(password))
else:
fileExtr.extractall(pwd=password)
global i
i = i + 1
print("search count : %d,real password is : %s" % (i, password))
return password
except:
i = i + 1
print("search count : %d,test password : %s, err:%s" % (i, password, sys.exc_info()[0]))
pass
def mainStep():
path = input("please input path:")
try:
if os.path.exists(path) == False:
print("%s : path error!"%(path))
return
type = os.path.splitext(path)[-1][1:]
if type == "zip":
fileGet = zipfile.ZipFile(path)
with fileGet as z:
for l in z.infolist():
is_encrypted = l.flag_bits & 0x1
if is_encrypted:
print("have password ")
break
else:
pass
fileGet = zipfile.ZipFile(path)
elif type == "rar":
fileGet = rarfile.RarFile(path)
with fileGet as z:
if z.needs_password():
print("have password ")
else:
print("no password")
return
else:
print("file not right")
return
pwdLists = open("D:\python工程\mutou.txt")
startTime = datetime.datetime.now()
for line in pwdLists.readlines():
Pwd = line.strip('\n')
t = MyThread(extractFile, (fileGet, Pwd, type))
t.start()
if (t.get_result() is Pwd):
break
endTime = datetime.datetime.now()
timeSpan = endTime - startTime
print("search time:%ss" % (timeSpan.total_seconds()))
except:
print("err:%s" % sys.exc_info()[0])
if __name__ == '__main__':
mainStep()
到此这篇关于Python如何破解压缩包密码的文章就介绍到这了,更多相关Python破解压缩包密码内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Python如何破解压缩包密码
本文链接: https://lsjlt.com/news/118232.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0