This post was imported from an old blog archive, and predates the creation of AdamCaudill.com.
This is a very basic form of hashing algorithm, mainly created to use as an example, and it shouldn’t be considered secure, while it should be virtually impossible to reverse, if you are looking for a truly secure hashing algorithm for production use, look at using a SHA family hash, as they have been exhaustively tested and proven to work.
Public Function HashString(strData As String) As String
Dim bytChar() As Byte
Dim strOutTemp As String
Dim strOut As String
Dim i As Long
bytChar() = StrConv(strData, vbFromUnicode)
For i = 0 To UBound(bytChar)
If i < UBound(bytChar) Then
If bytChar(i) > 128 Then
strOutTemp = strOutTemp & Val(bytChar(i) * 3) + Val(bytChar(i + 1) Mod 7)
Else
strOutTemp = strOutTemp & Val(bytChar(i) * 2) + Val(bytChar(i + 1) Mod 13)
End If
Else
strOutTemp = strOutTemp & Val(bytChar(i) * 2) Mod 9
End If
strOut = strOut & Hex(Val(strOutTemp))
strOutTemp = ""
Next
HashString = Replace(strOut, "0", "")
End Function