Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package advent.of.code;
- import java.math.BigInteger;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- public class Day4 {
- public static String getMD5(String input) {
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] messageDigest = md.digest(input.getBytes());
- BigInteger number = new BigInteger(1, messageDigest);
- String hashtext = number.toString(16);
- while (hashtext.length() < 32) {
- hashtext = "0" + hashtext;
- }
- return hashtext;
- }
- catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
- }
- public static void main(String[] args) throws NoSuchAlgorithmException {
- String text = "yzbqklnj";
- boolean found = false;
- int counter = 1;
- while(found != true) {
- String input = text + String.valueOf(counter);
- String md5 = getMD5(input);
- if(md5.substring(0, 5).equals("00000")) { // part1
- //if(md5.substring(0, 6).equals("000000")) { // part2
- found = true;
- System.out.println(input);
- System.out.println(md5);
- }
- counter++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement