将您的哈希破解方法抽象出来可能是最简单的:
Function hashType(ByVal filename As String) As Boolean
If algo.Text = "MD5" Then
Dim firstWord = (From word In IO.File.ReadLines(filename)
Where String.Equals(MD5(word), hash.Text)).FirstOrDefault()
If firstWord IsNot Nothing Then
Label2.Text = firstWord
Return True
Else
Label2.Text = "Hash Could Not Be Cracked"
End If
ElseIf algo.Text = "SHA1" Then
Dim firstWord = (From word In IO.File.ReadLines(filename)
Where String.Equals(SHA1(word), hash.Text)).FirstOrDefault()
If firstWord IsNot Nothing Then
Label2.Text = firstWord
Return True
Else
Label2.Text = "Hash Could Not Be Cracked"
End If
End If
Return False
End Function
Private Sub Thief3Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Thief3Button1.Click
OpenFileDialog1.Filter = "Dictionaries (*.dic)|*.dic"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.RestoreDirectory = True
OpenFileDialog1.Multiselect = True
OpenFileDialog1.ShowDialog()
End Sub
Private Sub Thief3TopButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Thief3TopButton1.Click
Me.Close()
End Sub
Private Sub Thief3Button3_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Thief3Button2.Click
hashType(OpenFileDialog1.FileName)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each wl As String In File.ReadLines("settings.txt")
If hashType(wl) Then Exit For
Next
End Sub
瞧。不过,我认为您可能希望在活动之外的其他地方执行此操作-首次创建表单时Load
不会有任何内容。hash.Text