In the past I’ve had to recover passwords from certain applications that customers don’t have or have simply forgotten.
Here is a simple class I’ve written to generate key combinations used in brute force password cracking.
Public Class cComboGenerator Dim Positions() As Byte Dim MaxLength As Integer = 10 Dim bCharSet() As Byte Dim bCombo() As Byte Public Sub New() Dim CharSet As String = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" bCharSet = System.Text.Encoding.Default.GetBytes(CharSet) ReDim Positions(MaxLength) ReDim bCombo(MaxLength) End Sub Function NextCombo(Optional Offset As Integer = 1) As String If (Positions(MaxLength) + Offset) > bCharSet.Length - 1 Then Positions(MaxLength) = (Positions(MaxLength) + Offset) Mod bCharSet.Length For x = (MaxLength - 1) To 0 Step -1 If Positions(x) >= bCharSet.Length - 1 Then Positions(x) = 1 Else Positions(x) = Positions(x) + 1 Exit For End If Next Else Positions(MaxLength) = Positions(MaxLength) + Offset End If For x = 0 To MaxLength bCombo(x) = bCharSet(Positions(x)) Next Return System.Text.Encoding.Default.GetString(bCombo).Replace(vbNullChar, String.Empty).Trim 'Dirty Hack End Function End Class
There are some optimisations that can be made, but chances are the bottleneck will be the encryption routine or waiting for a response and not the combination generation itself.