-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
38 lines (29 loc) · 1.08 KB
/
Copy pathPart1.java
File metadata and controls
38 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package y2016.d05;
import org.apache.commons.codec.binary.Hex;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Part1 {
private static String input = "ffykfhsq";
private static int zerolength = 5;
private static MessageDigest md5;
public static void main(String[] args) throws NoSuchAlgorithmException {
md5 = MessageDigest.getInstance("MD5");
String hash = "1234567980";
int count = 0;
StringBuilder password = new StringBuilder();
while (password.length() < 8) {
while (!"00000".equals(hash.substring(0, zerolength))) {
++count;
hash = getMd5Hex(input + count);
}
password.append(hash.substring(zerolength, zerolength+1));
System.out.println(password);
hash = "3472628347623847624";
}
System.out.println(password);
}
private static String getMd5Hex(String input) {
byte[] hashInBytes = md5.digest(input.getBytes());
return Hex.encodeHexString(hashInBytes);
}
}