Guest User

Untitled

a guest
Dec 3rd, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.security.MessageDigest;
  2.  
  3. public class Advent4 {
  4.  
  5.     public static String byteToHex(byte b) {
  6.         int i = (int) b & 0xff;
  7.         return String.format("%02x", i);
  8.     }
  9.  
  10.     public static int countZeroes(String s) {
  11.         int count = 0;
  12.         for (char each : s.toCharArray()) {
  13.             if (each == '0') {
  14.                 count++;
  15.             } else break;
  16.         }
  17.         return count;
  18.     }
  19.  
  20.     public static String byteArrayToHex(byte[] b) {
  21.         String retval = "";
  22.         for (byte each : b) {
  23.             retval+= byteToHex(each);
  24.         }
  25.         return retval;
  26.     }
  27.  
  28.     public static void main(String[] args) throws Exception {
  29.  
  30.         MessageDigest md = MessageDigest.getInstance("MD5");
  31.         String test = "ckczppom";
  32.         String temp = "";
  33.         int count = 0;
  34.         int pad = 1;
  35.         while (count < 6) {
  36.             temp = test + pad++;
  37.             md.update(temp.getBytes());
  38.             count = countZeroes(byteArrayToHex(md.digest()));
  39.             md.reset();
  40.         }
  41.         System.out.println(temp);
Advertisement
Add Comment
Please, Sign In to add comment