Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.security.MessageDigest;
- public class Advent4 {
- public static String byteToHex(byte b) {
- int i = (int) b & 0xff;
- return String.format("%02x", i);
- }
- public static int countZeroes(String s) {
- int count = 0;
- for (char each : s.toCharArray()) {
- if (each == '0') {
- count++;
- } else break;
- }
- return count;
- }
- public static String byteArrayToHex(byte[] b) {
- String retval = "";
- for (byte each : b) {
- retval+= byteToHex(each);
- }
- return retval;
- }
- public static void main(String[] args) throws Exception {
- MessageDigest md = MessageDigest.getInstance("MD5");
- String test = "ckczppom";
- String temp = "";
- int count = 0;
- int pad = 1;
- while (count < 6) {
- temp = test + pad++;
- md.update(temp.getBytes());
- count = countZeroes(byteArrayToHex(md.digest()));
- md.reset();
- }
- System.out.println(temp);
Advertisement
Add Comment
Please, Sign In to add comment