-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch_Thread.java
84 lines (76 loc) · 2.27 KB
/
Search_Thread.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package MD5_BruteForce;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Search_Thread extends Thread{
String interval;
static int cmp = 0;
int id = 0;
boolean stop = false;
String hashcode;
int server;
public Search_Thread(String i,String hash,int s) {
interval = i;
id = cmp;
hashcode = hash;
server = s;
cmp++;
}
public void setStop(boolean b) {
stop = b;
System.out.println("Thread "+id+" stopped");
}
public static String getMd5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
// this is the thread for starting search
public void run() {
// this method takes an interval and start brute force search on it
String[] A = interval.split("-");
int a = Integer.parseInt(A[0]);
int b = Integer.parseInt(A[1]);
// making search on the first character from a to b
long startTime = System.nanoTime();
for(int i=a;i<b;i++) {
char c = (char) i;
for(int j=33;j<127;j++) {
char d = (char) j;
for(int k=33;k<127;k++) {
char e = (char) k;
for(int l=33;l<127;l++) {
char r = (char) l;
for(int m=33;m<127;m++) {
char x = (char) m;
for(int n=33;n<127;n++) {
char v = (char) n;
String word = c+""+d+""+e+""+r+x+""+v;
//System.out.println(server+":"+id+" : "+word);
// if we find it the stop flag is true
if (hashcode.equals(getMd5(word))) {
System.out.println("Password found : "+word+" by Thread "+id+" on Server "+server);
double endTime = System.nanoTime();
double totalTime = endTime - startTime;
System.out.println("Time : "+(totalTime/1000000000)/60+" minutes");
// and also sending it to other threads
Server1.stop_threads();
}
}
}
}
}
}
}
}
}