Skip to content

Instantly share code, notes, and snippets.

@Serphentas
Created August 30, 2016 07:36
Show Gist options
  • Save Serphentas/dabb03dcdfc48d6827c9a9078e8e8c36 to your computer and use it in GitHub Desktop.
Save Serphentas/dabb03dcdfc48d6827c9a9078e8e8c36 to your computer and use it in GitHub Desktop.
[Java] scrypt collision test
int period = (int) 1e4, size = (int) 1e5, period2int = (int) 1e7;
String[] arr = new String[size];
long tmp = System.nanoTime(), start = System.nanoTime(), gen
= System.nanoTime();
for (int i = 0; i < arr.length; i++) {
arr[i]
= Hex.toHexString(SCrypt.generate("asd".getBytes("UTF-8"),
GPCrypto.randomGen(256), (int) Math.pow(2, 1), 1, 1, 32));
if (i
% period == 0) {
System.out.println((i / period) + "/" + size / period
+ " in " + ((System.nanoTime() - tmp) / 1e9) + " s");
tmp
= System.nanoTime();
}
}
System.out.println(size / period + "/" + size / period + " in "
+ ((System.nanoTime() - tmp) / 1e9) + " s");
System.out.println("done generating " + arr.length + " keys in " + (System.nanoTime() - gen)
/ 1e9 + " s");
tmp = System.nanoTime();
long search = System.nanoTime();
BigInteger cnt = new BigInteger("0"), one = new BigInteger("1"), period2 = new BigInteger(Integer.toString(period2int)), zero = new BigInteger("0");
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j
< arr.length; j++) {
cnt = cnt.add(one);
if (cnt.mod(period2).equals(zero)) {
System.out.println(cnt.divide(period2) + "/" + Math.pow(size, 2)
/ period2.intValue() / 2 + " in " + ((System.nanoTime() - tmp) / 1e9)
+ " s");
tmp = System.nanoTime();
}
if (arr[i].equals(arr[j])) {
System.out.println("found match between " + i + " and " + j);
}
}
}
System.out.println(Math.pow(size, 2) / period2.intValue() / 2 + "/"
+ Math.pow(size, 2) / period2.intValue() / 2 + " in "
+ ((System.nanoTime() - tmp) / 1e9) + " s");
System.out.println("done searching through " + cnt + " keys in "
+ (System.nanoTime() - search) / 1e9 + " s");
System.out.println(
"done scrubing in " + (System.nanoTime() - start) / 1e9 + " s");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment