PJW Hash

PJW is a hash function algorithm.



									Public Shared Function PJWHash(str As String) As UInteger
	Const BitsInUnsignedInt As UInteger = CUInt(4 * 8)
	Const ThreeQuarters As UInteger = CUInt((BitsInUnsignedInt * 3) / 4)
	Const OneEighth As UInteger = CUInt(BitsInUnsignedInt \ 8)
	Const HighBits As UInteger = CUInt(&HFFFFFFFFUI) << CInt(BitsInUnsignedInt - OneEighth)
	Dim hash As UInteger = 0
	Dim test As UInteger = 0
	Dim i As UInteger = 0

	For i = 0 To str.Length - 1
		hash = (hash << CInt(OneEighth)) + CByte(AscW(str(CInt(i))))
		test = hash And HighBits

		If test <> 0 Then
			hash = ((hash Xor (test >> CInt(ThreeQuarters))) And (Not HighBits))
		End If
	Next

	Return hash
End Function
								


Example

									Dim data = "jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^"
Dim value = PJWHash(data)
								


Output

									248446350