Skip to content

Instantly share code, notes, and snippets.

@RCasatta
Created October 27, 2017 09:57
Show Gist options
  • Select an option

  • Save RCasatta/53322f876e4f6c4acec0963e39273d3d to your computer and use it in GitHub Desktop.

Select an option

Save RCasatta/53322f876e4f6c4acec0963e39273d3d to your computer and use it in GitHub Desktop.
Recursive sha256
package com.eternitywall;
import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
public class Main {
public static void main(String[] args) {
try {
byte[] b = new byte[32];
new Random().nextBytes(b);
MessageDigest md = MessageDigest.getInstance("SHA-256");
long start = System.currentTimeMillis();
for(long l=0;l<1000000000;l++) {
if(l%10000000==0) {
String s = DatatypeConverter.printHexBinary(b).toLowerCase();
long elapsedNanos = (System.currentTimeMillis()-start)*1000;
System.out.println(l + " " + s + " " + ((double) l / (double) elapsedNanos) + " Mhash/s");
}
md.update(b);
b = md.digest();
md.reset();
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment