summaryrefslogtreecommitdiff
path: root/ws2015/eip/blaetter/10/2/PasswordCrackerThread.java
blob: dcc06562aa632e102c5e1ac60476943d47527f93 (plain)
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
import java.util.Formatter;

public class PasswordCrackerThread implements Runnable {

    public final long rangeStart;
    public final long rangeEnd;

    public final Synchronizer sync;

    public PasswordCrackerThread(Synchronizer s, long start, long end)
    {
	sync       = s;
	rangeStart = start;
	rangeEnd   = end;
    }
    
    public void run() {
	for (long i = rangeStart; i <= rangeEnd; i++) {
	    String guess = new Formatter().format("%8d", i).toString();
	    String digest = SHA.encrypt(guess);
	    if (digest.equals(sync.targetHash)) {
		synchronized (sync) {
		    sync.setSolution(i);
		    break;
		}
	    }
	}
    }
}