穷举破解EXCEL、WORD文档密码(2)
作者:佚名; 更新时间:2014-12-05
ayLen) = Chr(124)
        all_char(ArrayLen+1) = Chr(126)
        ArrayLen = ArrayLen + 2
    End If
    If ArrayLen = 0 Then
        MsgBox "错误:没有选择'密码使用的字符'", , "请选择密码使用的字符范围..."
        Exit Sub
    End If
    If blnProcessing Then
        If MsgBox("真的要中断解密过程吗?", vbYesNo, "用户中断任务") = vbYes Then blnProcessing = False
    Else
        CmdStartCrack.Caption = "中断破解"
        blnProcessing = True
        strpath = Combo1.Text
        If strpath = "" Then
            MsgBox "错误:没有选择'需要解密的文件'", , "请选择需要解密的文件..."
            Exit Sub
        End If
        strpath = Trim(strpath)
        Password_Start_Long = Val(txtPasswordStartLong.Text)
        Password_End_Long = Val(txtPasswordEndLong.Text)
        If Password_Start_Long > Password_End_Long Then
            Password_Start_Long = Val(txtPasswordEndLong.Text)
            Password_End_Long = Val(txtPasswordStartLong.Text)
        End If
        Label1.Caption = "破解进度:"
        Label1.Refresh
        On Error Resume Next
        If UCase(Right(strpath, 3)) = "XLS" Then
            For K = Password_Start_Long To Password_End_Long    '破解excel开始
                For I = 0 To ArrayLen ^ K - 1
                    pass = ""
                    Temp = I
                    For J = 1 To K - 1
                        Temp = Temp \ ArrayLe
                        pass = all_char(Temp Mod ArrayLen) + pass
                    Next J
                    pass = pass + all_char(I Mod ArrayLen)
                    Set OpenReturn = xls.Workbooks.Open(FileName:=strpath, Password:=pass)
                    Text1.Text = pass    '显示破解进度
                    Text1.Refresh
                    If Err.Number <> 0 Then  '如果解密成功,打开文档,显示密码,退出过程
                        Err.Clear
                    Else
                        Label1.Caption = "文档密码:"
                        Text1.Text = pass
                        Me.Refresh
                        xls.Visible = True
                        CmdStartCrack.MousePointer = 0
                        CmdStartCrack.Caption = "开始破解"
                        blnProcessing = False
                        Set xls = Nothing
                        Exit Sub
                    End If
                    DoEvents
                    If Not blnProcessing Then Exit For
                Next I
                If Not blnProcessing Then Exit For
            Next K
            xls.Quit
            Set xls = Nothing
        Else
            For K = Password_Start_Long To Password_End_Long  '破解word开始
                For I = 0 To ArrayLen ^ K - 1
                    pass = ""
                    Temp = I
                    For J = 1 To K -
                      Temp = Temp \ ArrayLen
                        pass = all_char(Temp Mod ArrayLen) + pass
                    Next J
                    pass = pass + all_char(I Mod ArrayLen)
                    OpenReturn = wd.Documents.Open(FileName:=strpath, passworddocument:=pass)
                    Text1.Text = pass  '显示破解进度
                    Text1.Refresh
                    If Err.Number <> 0 Then    '如果解密成功,打开文档,显示密码,退出过程
                        Err.Clear
                    Else
                        'MsgBox "word password"
                        Label1.Caption = "文档密码:"
                        Text1.Text = pass
                        Me.Refresh
                        wd.Visible = True
                        CmdStartCrack.MousePointer = 0
                        CmdStartCrack.Caption = "开始破解"
                        blnProcessing = False
                        Set wd = Nothing
                        Exit Sub
                    End If
                    DoEvents
                    If Not blnProcessing Then Exit For
                Next I
                If Not blnProcessing Then Exit For
            Next K
            wd.Quit
            Set wd = Nothing
        End If
        CmdStartCrack.Caption = "开始破解"
        If blnProcessing Then MsgBox "没有找到密码,可能是密码位数不对!", , "提示信息..."
        blnProcessing = False
End Sub
3. 时间复杂度分析
一个算法的时间复杂度,是指该算法的时间耗费,是该算法所求解问题规模n的函数。根据前面讲的实现原理,我们知道,破解算法的时间耗费主要集中在尝试打开OFFICE文档上,因此,当我们假设破解一个N位字符串密码,且选定密码字符范围的总字符数为ArrayLen时,该算法的时间复杂度是O(ArrayLen^N)。即,当N确定后,该算法的时间复杂度是N次方阶;当ArrayLen确定后,该算法的时间复杂度是指数阶。都是高数量级的时间复杂度。
4. 说明
穷举法解密对系统资源的占用是十分惊人的,在解密的过程中最好不要运行其他应用程序。如果安装有瑞星等杀毒软件,应将杀毒软件的“office安全助手”去掉,以便加快程序的运行速度。
该程序在WinXP+OfficeXP+VB6.0环境下测试通过,笔者随便测试了一个5位数字密码,在P4机器上,8分钟左右即可解开口令。



 

 

参考文献
[1] 王建华 译. Visual Basic 6 开发人员指南.  北京:机械工业出版社,1999

核心期刊快速发表
Copyright@2000-2030 论文期刊网 Corporation All Rights Reserved.
《中华人民共和国信息产业部》备案号:ICP备07016076号;《公安部》备案号:33010402003207
本网站专业、正规提供职称论文发表和写作指导服务,并收录了海量免费论文和数百个经国家新闻出版总署审批过的具有国内统一CN刊号与国际标准ISSN刊号的合作期刊,供诸位正确选择和阅读参考,免费论文版权归原作者所有,谨防侵权。联系邮箱:256081@163.com