Attribute VB_Name = "mHasher" Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Módulo suporte para cálculo hash ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Guarda o nome do módulo Private Const ST_MY_NAME As String = "mHasher" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Função que retorna um código hash byte-vt dado uma string ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function GetHash(stInput As String) As Byte() On Error GoTo ErrTreat: Dim lnI As Long, lnJ As Long Dim Hash() As Byte, HashAux() As Integer ' Redimenciona os vetores ReDim HashAux(3) ReDim Hash(3) ' Varre o vetor de bytes For lnJ = 0 To 3 ' Varre a string For lnI = (1 + lnJ) To Len(stInput) Step 4 ' Incrementa o hash itJ HashAux(lnJ) = HashAux(lnJ) + AscW(Mid(stInput, lnI, 1)) ' Converte para byte HashAux(lnJ) = HashAux(lnJ) Mod 256 Next lnI ' Guarda o valor no vetor de byte Hash(lnJ) = CByte(Abs(HashAux(lnJ))) Next lnJ ' Retorna vetor GetHash = Hash ' Libera vetores Erase Hash() Erase HashAux() Exit Function ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".GetHash" End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Função que retorna um código hash longo dado uma string ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function GetLngHash(stInput As String) As Long On Error GoTo ErrTreat: Dim Hash() As Byte ' Retorna o hash Hash = GetHash(stInput) ' Copia o valor para o long CopyMemory GetLngHash, Hash(0), 4 ' Libera o hash Erase Hash() Exit Function ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".GetLngHash" End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Função que retorna um código hash em string dado uma string ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function GetStrHash(stInput As String, lnSize As Long) As String On Error GoTo ErrTreat: Dim lnI As Long, lnJ As Long Dim HashAux() As Integer Dim stAux As String ' Redimenciona os vetores de acordo com o tamanho ReDim HashAux(lnSize - 1) As Integer stAux = String(lnSize, 0) ' Varre o vetor de bytes For lnJ = 0 To (lnSize - 1) ' Varre a string For lnI = (1 + lnJ) To Len(stInput) Step lnSize ' Incrementa o hash itJ HashAux(lnJ) = HashAux(lnJ) + AscW(Mid(stInput, lnI, 1)) ' Converte para byte HashAux(lnJ) = HashAux(lnJ) Mod 256 Next lnI ' Guarda o valor na string Mid$(stAux, lnJ + 1) = Chr(Abs(HashAux(lnJ))) Next lnJ ' Libera vetor auxiliar Erase HashAux() ' Retorna GetStrHash = stAux Exit Function ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".GetStrHash", stInput End Function