Created
July 31, 2012 00:12
-
-
Save nahi/3212226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.