Imports System.IO
Imports Ionic.Zip
Imports System.Threading
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim zipFilePath As String = "C:\Users\Administrator\Desktop\2\1.zip" ' 压缩包文件路径
Dim passwordDictPath As String = "C:\Users\Administrator\Desktop\2\mm.txt" ' 密码字典文件路径
Dim passwords As List(Of String) = ReadPasswordsFromFile(passwordDictPath)
Dim correctPassword As String = TryUnlockWithPasswords(zipFilePath, passwords)
If correctPassword <> "" Then
MessageBox.Show("密码匹配成功,正确密码是:" & correctPassword)
Else
MessageBox.Show("所有密码尝试均失败,未找到正确密码。")
End If
End Sub
Function ReadPasswordsFromFile(ByVal filePath As String) As List(Of String)
Dim passwords As New List(Of String)
Try
Using reader As New StreamReader(filePath)
Dim line As String
While Not reader.EndOfStream
line = reader.ReadLine()
passwords.Add(line)
End While
End Using
Catch ex As Exception
MessageBox.Show("读取密码文件时发生错误: " & ex.Message)
End Try
Return passwords
End Function
Function TryUnlockWithPasswords(ByVal zipPath As String, ByVal passwords As List(Of String)) As String
Try
Using zip As ZipFile = ZipFile.Read(zipPath)
For Each password As String In passwords
zip.Password = password
TextBox1.Text &= "正在尝试密码:" & password & vbNewLine ' 将正在尝试的密码显示在文本框中
TextBox1.Refresh() ' 刷新文本框以立即显示新添加的内容
Thread.Sleep(10) ' 延时 0.01 秒,可根据需要调整时长
If ZipFile.CheckZipPassword(zipPath, password) Then
Return password
End If
Next
End Using
Catch ex As Exception
MessageBox.Show("尝试解锁时发生错误: " & ex.Message)
End Try
Return ""
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, j As Integer
Dim a() As String = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
For i = 0 To 9
For j = 0 To 9
TextBox1.Text = TextBox1.Text & a(i) & a(j) & vbCrLf
Next
Next
End Sub
End Class