|
-
Mar 30th, 2012, 10:14 AM
#1
Thread Starter
Frenzied Member
GetHashCode 64 vs 32
Hello
I have a very old app that uses a little function that calculates a value and after that i get the hash code of that value, that it's used as a password to unlock some functionalities to the user. Now the manager has a 64 bits computer and the function returns a different value.
What i need it's how to convert this function from C# to Vb, i know that I can use the converts, but they don't work, pointers...
c# Code:
public static unsafe int GetHashCode32(string s)
{
fixed (char* str = s.ToCharArray())
{
char* chPtr = str;
int num = 0x15051505;
int num2 = num;
int* numPtr = (int*)chPtr;
for (int i = s.Length; i > 0; i -= 4)
{
num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0];
if (i <= 2)
{
break;
}
num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ numPtr[1];
numPtr += 2;
}
return (num + (num2 * 0x5d588b65));
}
}
Can I convert this function?
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Mar 30th, 2012, 12:55 PM
#2
Re: GetHashCode 64 vs 32
Try this (not 100% sure it will work, you might need to use the Marshal object).
Code:
Public Shared Function GetHashCode32(s As String) As Integer
Dim chPtr As Pointer(Of Char) = str
Dim num As Integer = &H15051505
Dim num2 As Integer = num
Dim numPtr As Pointer(Of Integer) = CType(chPtr, Pointer(Of Integer))
For i As Integer = s.Length To 1 Step -4
num = (((num << 5) + num) + (num >> &H1b)) Xor numPtr(0)
If i <= 2 Then
Exit For
End If
num2 = (((num2 << 5) + num2) + (num2 >> &H1b)) Xor numPtr(1)
numPtr += 2
Next
Return (num + (num2 * &H5d588b65))
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|