Created
December 16, 2015 10:34
-
-
Save paulhoadley/f4d6fea16f078bd3acd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.logicsquad.advent; | |
import java.io.UnsupportedEncodingException; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import javax.xml.bind.DatatypeConverter; | |
public class Day4 { | |
private static final String KEY = "yzbqklnj"; | |
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException { | |
int counter = 1; | |
while (true) { | |
String candidate = KEY + counter; | |
byte[] bytes = candidate.getBytes("UTF-8"); | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
byte[] digest = md.digest(bytes); | |
String result = DatatypeConverter.printHexBinary(digest); | |
if (result.startsWith("000000")) { | |
break; | |
} | |
counter++; | |
} | |
System.out.println("Day4.main: counter = " + counter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment