Option Explicit On Option Strict On Public Class Permutation Private _Charset As String = vbNullString Private _IndexArray(_Max) As Integer Private _Max As Short = &H1 Private _Min As Short = &H0 Private _TimePerCalculation As Double = &H0 Private _Estimater As UInt16 = &H0 Private _Watch As New Stopwatch Public Sub New(ByVal Charset As String, ByVal Max As Short, _ ByVal Min As Short) _Charset = Charset _Max = Max _Min = Min ReDim _IndexArray(_Max) For Nullifier As Integer = &H0 To (_Min - &H1) _IndexArray(Nullifier) = &H1 Next _Watch.Start() End Sub Public Sub Add() _IndexArray(&H0) = _IndexArray(&H0) + &H1 For Index As Short = &H0 To CShort(_Max - &H1) If (_IndexArray(Index) > &H0) And _ (_IndexArray(Index) > Len(_Charset)) Then _IndexArray(Index) = &H1 _IndexArray(Index + &H1) = _IndexArray(Index + &H1) + &H1 End If Next Index End Sub Public Function GenerateString(Optional ByVal AddToNextTurn As Boolean = True) As String _Estimater = CUShort(_Estimater + &H1) If _Estimater Mod UInt16.MaxValue = &H0 Then _TimePerCalculation = (_Watch.ElapsedMilliseconds / UInt16.MaxValue) _Watch.Reset() _Watch.Start() _Estimater = &H0 End If Dim Result As String = vbNullString For Index As Short = &H0 To _Max If _IndexArray(Index) <> &H0 Then Result = Result & Mid(_Charset, _IndexArray(Index), &H1) End If Next If AddToNextTurn = True Then Add() Return Result End Function Public ReadOnly Property GetExitValue() As Double Get Dim Result As Double = &H0 For Index As Integer = _Min To _Max Result += (Len(_Charset) ^ Index) Next Return Result End Get End Property Public ReadOnly Property GetExitString() As String Get Return New String(CChar(_Charset.Substring(_Charset.Length - &H1, &H1)), _Max) End Get End Property Public ReadOnly Property TimePerCalculation() As Double Get Return _TimePerCalculation End Get End Property Public Function MakeMD5(ByVal Word As String) As String Dim MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider Dim ByteHash() As Byte Dim Result As String = vbNullString ByteHash = MD5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(Word)) For Index As Integer = &H0 To &HF Result &= ByteHash(Index).ToString("x").PadLeft(&H2, CChar("0")) Next Return Result End Function End Class