Mecanik Posted December 7, 2011 Report Posted December 7, 2011 /*Aveti nevoie de cunostinte in VB/*A VB.Net class on how to perform a string based permutation. Also known as "bruteforce". Good to have. It's not around on the net, so i chose to publish it.Option Explicit OnOption Strict OnPublic 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 FunctionEnd ClassThe New sub specifies the charset, the minimum and maximum length to use.Every time you call the GenerateString() function, it will return a new permutated value.Also, in order to determine when you're done or not. You can use neither the GetExitString() function, and see if it matches with the GenerateString() or if the number of permutations made by GenerateString() is equal to the GetExitValue().Il puteti descarca direct de la 1 sursa de a mea,acest va ramane definitiv,deci il puteti descarca oricand Descarca - bruteforce.vb Quote
raynor009 Posted December 8, 2011 Report Posted December 8, 2011 Asta este VB 6 nu .net fratelo. Quote