Skip to content

Instantly share code, notes, and snippets.

@Serphentas
Created August 27, 2016 08:22
Show Gist options
  • Save Serphentas/d619a0b253c7c6bcc9c184737c23dd23 to your computer and use it in GitHub Desktop.
Save Serphentas/d619a0b253c7c6bcc9c184737c23dd23 to your computer and use it in GitHub Desktop.
[Java] Salt collision finder
int maxSalts = 1234567,
saltBytes = 4;
long cnt1 = 0L,
step0 = 1000000L,
step1 = 1000000L;
System.out.println("Assigning array");
long time = System.nanoTime();
byte[][] test = new byte[maxSalts][saltBytes];
System.out.println("Done in " + (System.nanoTime() - time) / 1e9);
System.out.println("Generating salts");
time = System.nanoTime();
for (int i = 0; i < maxSalts; i++) {
if (i != 0 && i % step0 == 0) {
System.out.println(i / step0 + "/" + maxSalts / step0);
}
test[i] = GPCrypto.randomGen(saltBytes);
}
System.out.println("Done in " + (System.nanoTime() - time) / 1e9);
System.out.println("Searching duplicates");
time = System.nanoTime();
for (int i = 0; i < maxSalts; i++) {
for (int j = i + 1; j < maxSalts; j++) {
cnt1++;
if (cnt1 % step1 == 0) {
System.out.println(cnt1 / step1 + "/" + "6.21590E6984214");
}
if (test[i] == test[j] && i != j) {
System.out.println("Found match at indexes " + i + " and " + j);
System.out.println("Salt is " + Hex.toHexString(test[j]));
}
}
}
System.out.println("Done in " + (System.nanoTime() - time) / 1e9);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment