GetHashCode

  • Thread starter Peter Morris [Droopy Eyes Software]
  • Start date
P

Peter Morris [Droopy Eyes Software]

Hi all

I am creating a kind of authorisation process in my CF application and part
of this requires the use of string.GetHashCode.

Unfortunately I have discovered that the result of this method in CF returns
a different value to that of the one from the full framework.

Can anyone suggest a way to get my Desktop app to produce the same value? I
have tried disassembling the CF version using Reflector but I cannot get it
to compile...

public override unsafe int GetHashCode()
{
if (AppDomain.CompatVersion.Major == 1)
{
goto Label_0057;
}
fixed (char* chRef1 = &this.m_firstChar)
{
int num1;
int num4;
char* chPtr1 = chRef1;
int num2 = 0x1505;
int num3 = num2;
while ((num1 = chPtr1[0]) != '\0')
{
num2 = ((num2 << 5) + num2) ^ num1;
num1 = chPtr1[1];
if (num1 == 0)
{
break;
}
num3 = ((num3 << 5) + num3) ^ num1;
chPtr1 += 2;
}
return (num2 + (num3 * 0x5d588b65));
Label_0057:
num4 = 0x1505;
int num5 = this.Length;
fixed (char* chRef2 = &this.m_firstChar)
{
for (int num6 = 0; num6 < num5; num6++)
{
num4 = ((num4 << 5) + num4) ^ chRef2[num6];
}
}
return num4;
}
}




Thanks

Pete
 
P

Peter Morris [Droopy Eyes Software]

public int MyHashCode(string value)

{

int charIndex = 0;

int num1;

int num4;

int num2 = 0x1505;

int num3 = num2;

char currentChar;

while (charIndex < value.Length)

{

currentChar = value[charIndex];

num1 = (int)currentChar;

num2 = ((num2 << 5) + num2) ^ num1;

if (charIndex == value.Length - 1)

break;

num1 = value[charIndex + 1];

if (num1 == 0)

{

break;

}

num3 = ((num3 << 5) + num3) ^ num1;

charIndex += 2;

}

return (num2 + (num3 * 0x5d588b65));

}
 
G

Guest

GetHashCode is not designed for this - in fact it's no guaranteed to be the
same between versions of any framework, so FFX 1.1 and 2.0 could produce
different results on the desktop alone. Use an MD5 hash or something if
reproducibility is needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top