-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashCracker.java
More file actions
25 lines (22 loc) · 826 Bytes
/
HashCracker.java
File metadata and controls
25 lines (22 loc) · 826 Bytes
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
import java.security.*;
public class HashCracker {
public static void main(String[] args) throws Exception {
String target = md5("abc");
for (char a='a'; a<='z'; a++)
for (char b='a'; b<='z'; b++)
for (char c='a'; c<='z'; c++) {
String test = "" + a + b + c;
if (md5(test).equals(target)) {
System.out.println("Cracked: " + test);
return;
}
}
}
static String md5(String s) throws Exception {
MessageDigest m = MessageDigest.getInstance("MD5");
byte[] b = m.digest(s.getBytes());
StringBuilder sb = new StringBuilder();
for (byte x : b) sb.append(String.format("%02x", x));
return sb.toString();
}
}