亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

???????如何利用python破解zip加密文件

 更新時(shí)間:2022年05月22日 11:13:38   作者:??藍(lán)星部隊(duì)????  
這篇文章主要介紹了???????如何利用python破解zip加密文件,文章基于python的相關(guān)資料展開破解zip加密文件的詳細(xì)內(nèi)容介紹,需要的小伙伴可以參考一下

前言:

日常工作中,會(huì)遇到一些加密的zip文件,但是因?yàn)槟承┰蚧蛘邥r(shí)間過長,密碼不知道了。但是zip文件中文件有很重要很必須。那么,我們試一試萬能的Python,暴力破解密碼。

一、破解zip加密文件的思路

  • 準(zhǔn)備一個(gè)加密的zip文件。
  • zipfile模塊可以解壓zip文件。

解壓時(shí)可以提供密碼zfile.extractall("./", pwd=password.encode("utf8"))

  • itertools.permutations實(shí)現(xiàn)全字符的全排列。

通過函數(shù)itertools.permutations("abc", 3)實(shí)現(xiàn)全字符的全排列:abc/acb/bca/bac/cab/cba

二、實(shí)例代碼演示

0、zip的壓縮方式

本文介紹的zip文件知道密碼一共是4位的,密碼字符的范圍是a-z1-0。并且不存在重復(fù)字符的,不會(huì)有“aabb”的密碼。zip壓縮時(shí)是選擇了zip傳統(tǒng)加密!

1、解壓zip文件

導(dǎo)入zipfile模塊,使用其中的extractall()函數(shù)。

import itertools
filename = "readme.zip"
# 創(chuàng)建一個(gè)解壓的函數(shù),入?yún)槲募兔艽a
# 并使用try-except,避免報(bào)錯(cuò)中斷程序。
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False

2、實(shí)現(xiàn)密碼字符的全排列

import zipfile
import itertools
filename = "readme.zip"
# 創(chuàng)建一個(gè)解壓的函數(shù),入?yún)槲募兔艽a
# 并使用try-except,避免報(bào)錯(cuò)中斷程序。
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False
# chars是密碼可能的字符集
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for c in itertools.permutations(chars, 4):
    password = ''.join(c)
    print(password)
    result = uncompress(filename, password)
    if not result:
        print('解壓失敗。', password)
    else:
        print('解壓成功。', password)
        break

文件壓縮時(shí),一些注意的事項(xiàng): 

三、密碼是幾位未知,也可以破解密碼

查過一些資料,zip壓縮文件密碼最長為12位,在原來的程序上增加上一個(gè)for循環(huán)就可以實(shí)現(xiàn)破解密碼了。

import zipfile
import itertools
filename = "readme.zip"
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for i in range(12):
    for c in itertools.permutations(chars, i):
        password = ''.join(c)
        print(password)
        result = uncompress(filename, password)
        if not result:
            print('解壓失敗。', password)
        else:
            print('解壓成功。', password)
            break

總結(jié)

此方法可以是實(shí)現(xiàn)破解zip文件的密碼,python可以完成一些好玩的事情。

到此這篇關(guān)于如何利用python破解zip加密文件的文章就介紹到這了,更多相關(guān)python破解加密文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論