Hash Codes: Can C# and J#/J++ values be reconciled?

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

Hello,

C# and J#/J++ return very different HashCodes for the same string. Is there
a reliable and generic way to reconcile these values? For example:

[C#]
string foo = "BOB";
int cFooHash = foo.HashCode;

[J#/J++]
String foo = "BOB;
int jFooHash = foo.getHashCode();

Is there a way to make cFooHash == jFooHash for any value of foo?

I have hashed stuff stored externally from a J++ app. I could use J# to
process them, but I'd rather not add a dependency to the J# runtime.

Thanks!

Keith
 
Hi,
The internal algorithms will differ from language to language. usually
these hash codes are not meant to be portable.
If you want to generate truly portable hash codes you should try MD5 or
SHA hashes. These hashes are generated using standard algorithms and will
be the same regardless of the language generated.
In .Net the System.Cryptography namespace has classes to help with this.
C# and J# use the are .Net languages so a string in C# and J# could
contain the same hash codes not too sure about this, maybe the exact
implementations of the string object differ). J++ uses the Java runtime so
the hash code would be different.
anyway if you really want to reliable hashcodes use MD5 or SHA. You could
crate a new string class derived from string and override the HashCode
method.

Hope this helps...


Hello,

C# and J#/J++ return very different HashCodes for the same string. Is
there
a reliable and generic way to reconcile these values? For example:

[C#]
string foo = "BOB";
int cFooHash = foo.HashCode;

[J#/J++]
String foo = "BOB;
int jFooHash = foo.getHashCode();

Is there a way to make cFooHash == jFooHash for any value of foo?

I have hashed stuff stored externally from a J++ app. I could use J# to
process them, but I'd rather not add a dependency to the J# runtime.

Thanks!

Keith
 
Back
Top