Skip to content

Instantly share code, notes, and snippets.

@nahi
Created July 31, 2012 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahi/3212226 to your computer and use it in GitHub Desktop.
Save nahi/3212226 to your computer and use it in GitHub Desktop.
public class JPACollision {
public static void main(String[] args) {
byte[] bytes1 = new byte[] {
0x58, (byte) 0xa1, (byte) 0x82, 0x6c, 0x00, 0x00, (byte) 0xb1, 0x3b
};
byte[] bytes2 = new byte[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
byte[] bytes12 = concat(bytes1, bytes2);
byte[] bytes21 = concat(bytes2, bytes1);
byte[] bytes11 = concat(bytes1, bytes1);
byte[] bytes22 = concat(bytes2, bytes2);
System.out.println(sun.misc.Hashing.murmur3_32(bytes12));
System.out.println(sun.misc.Hashing.murmur3_32(bytes21));
System.out.println(sun.misc.Hashing.murmur3_32(bytes11));
System.out.println(sun.misc.Hashing.murmur3_32(bytes22));
}
private static byte[] concat(byte[] bytes1, byte[] bytes2) {
byte[] result = new byte[bytes1.length + bytes2.length];
System.arraycopy(bytes1, 0, result, 0, bytes1.length);
System.arraycopy(bytes2, 0, result, bytes1.length, bytes2.length);
return result;
}
}
@nahi
Copy link
Author

nahi commented Jul 31, 2012

You need to obtain OpenJDK 7u6 pre release build. The sun.misc.Hashing.murmur3_32 is used via sun.misc.Hashing.stringHash32, that is the hash32(String) in standard Java Hash collections from Java 7u6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment