压缩包密码破解示例分享(类似典破解)

yipeiwu_com5年前Python基础

昨天翻硬盘,找到一个好东西,可惜自己加了密码自己不记得了。试了几个常用的没试出来,于是写了这么个小脚本来替我尝试。。呵呵,还真给解出来了。
python脚本内容如下,跑跑自己加密的压缩包还不错

复制代码 代码如下:

# -*- coding: utf-8 -*-

import sys,os

def IsElementUniq(list):
    """
          判断list中的元素是否为唯一的
    """
    for word in list:
        if list.count(word)>1:
            return False

    return True

def GenPswList():
    """
          要求用户输入词,并根据单词组合密码,只尝试四个单词来组合,并限制密码长度为20。写的比较挫
    """
    psw=raw_input('input a word>')
    wordlist = []
    while psw:
        wordlist.append(psw)
        psw=raw_input('input a word>')
    print wordlist

    global g_pswlist
    g_pswlist = []
    for word in wordlist:
        g_pswlist.append(word)

    for word1 in wordlist:
        for word2 in wordlist:
            locallist = [word1, word2]
            if IsElementUniq(locallist):
                tmp = word1 + word2
                if len(tmp) < 20:
                    g_pswlist.append(tmp)

    for word1 in wordlist:
        for word2 in wordlist:
            for word3 in wordlist:
                locallist = [word1, word2, word3]
                if IsElementUniq(locallist):
                    tmp = word1 + word2 + word3
                    if len(tmp) < 20:
                        g_pswlist.append(tmp)

    for word1 in wordlist:
        for word2 in wordlist:
            for word3 in wordlist:
                for word4 in wordlist:
                    locallist = [word1, word2, word3, word4]
                    if IsElementUniq(locallist):
                        tmp = word1 + word2 + word3 + word4
                        if len(tmp) < 20:
                            g_pswlist.append(tmp)

    print 'gen psw is:', g_pswlist

def TestUnZipPack(filename):
    """
          尝试用密码来解压压缩包
    """

    command = ""
    for psw in g_pswlist:
        command = "7z e -p%s -y %s" %(psw,filename)
        print command
        ret = os.system(command)
        if ret == 0:
            print 'right psw is ', psw
            break

def main(filename):
    GenPswList()
    TestUnZipPack(filename)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'argv error'
        print 'example:test_7z_psw.py 1.7z'
        sys.exit(1)

    main(sys.argv[1])

相关文章

Python嵌套函数,作用域与偏函数用法实例分析

本文实例讲述了Python嵌套函数,作用域与偏函数用法。分享给大家供大家参考,具体如下: 内嵌函数(嵌套函数): 意思:在函数里面再定义一个新的函数 如果在函数体内不调用内嵌的...

python函数装饰器之带参数的函数和带参数的装饰器用法示例

本文实例讲述了python函数装饰器之带参数的函数和带参数的装饰器用法。分享给大家供大家参考,具体如下: 1. 函数带多个参数 # 普通的装饰器, 打印函数的运行时间 def dec...

Python实现的质因式分解算法示例

本文实例讲述了Python实现的质因式分解算法。分享给大家供大家参考,具体如下: 本来想实现一个其它的基本数学算法问题,但是发现在实现之前必须得先完成分解质因式的算法。 没有去网上寻找什...

使用Python进行目录的对比方法

如果进行单个文件的比较,可以使用difflib模块。虽然filecmp模块也能够进行单个文件的对比,但是前者能够提供观感更好的报告。如果我们只是想看一下两个目录中的某个文件是否一致而不关...

numpy的文件存储.npy .npz 文件详解

Numpy能够读写磁盘上的文本数据或二进制数据。 将数组以二进制格式保存到磁盘 np.load和np.save是读写磁盘数组数据的两个主要函数,默认情况下,数组是以未压缩的原始二进制格式...