Hashing with certain seeds are not consistent in Javascript and Java
senthil-root opened this issue · comments
Hashing with hashes above ### > 0x7fffffff produces hashes which are different from what is generated using Java.
Example (In JavaScript js-xxhash):
Seed : 0x7FFFFFFF
var seed = 0x7FFFFFFF;
var Hasher = xxhashjs.h64( seed );
var stringToHash = 'ABCD';
var h = Hasher.update( stringToHash ).digest().toString(16)
console.log('getHash("' + stringToHash + '") with seed [0x' + seed.toString(16) + "] = " + h)
output:
getHash("ABCD") with seed [0x7fffffff] = 5479e1557e1d305a
Example (In JavaScript js-xxhash):
Seed : 0x80000000
seed = 0x80000000;
Hasher = xxhashjs.h64( seed );
stringToHash = 'ABCD';
h = Hasher.update( stringToHash ).digest().toString(16)
console.log('getHash("' + stringToHash + '") with seed [0x' + seed.toString(16) + "] = " + h)
output:
getHash("ABCD") with seed [0x80000000] = 846bea22a8abeaf0
Here is the same operation using Java
Example (In Java xxhash):
Seed : 0x7FFFFFFF
long seed = 0x7FFFFFFF;
String stringToHash = "ABCD";
StreamingXXHash64 streamingXXHash64 = XXHashFactory.safeInstance().newStreamingHash64(seed);
streamingXXHash64.update(stringToHash.getBytes(), 0, stringToHash.length());
System.out.println("getHash(\"" + stringToHash + "\") with seed [0x" + Long.toHexString(seed) + "] = " + Long.toHexString(streamingXXHash64.getValue()));
output
getHash("ABCD") with seed [0x7fffffff] = 5479e1557e1d305a
Example (In Java xxhash):
Seed : 0x80000000
long seed = 0x80000000;
String stringToHash = "ABCD";
StreamingXXHash64 streamingXXHash64 = XXHashFactory.safeInstance().newStreamingHash64(seed);
streamingXXHash64.update(stringToHash.getBytes(), 0, stringToHash.length());
System.out.println("getHash(\"" + stringToHash + "\") with seed [0x" + Long.toHexString(seed) + "] = " + Long.toHexString(streamingXXHash64.getValue()));
output
getHash("ABCD") with seed [0x80000000] = 445bfd9f010fc179
While using 0x7FFFFFFF as seed both Java and Javascript implementation creates hash of 5479e1557e1d305a for 'ABCD', using 0x80000000 as seed, JavaScript implementation produces hash of 846bea22a8abeaf0 and Java implementation produces hash of 445bfd9f010fc179