diff options
Diffstat (limited to 'ws2015/eip/blaetter/10/2/PasswordCracker.java')
-rw-r--r-- | ws2015/eip/blaetter/10/2/PasswordCracker.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ws2015/eip/blaetter/10/2/PasswordCracker.java b/ws2015/eip/blaetter/10/2/PasswordCracker.java new file mode 100644 index 0000000..0c7c094 --- /dev/null +++ b/ws2015/eip/blaetter/10/2/PasswordCracker.java | |||
@@ -0,0 +1,36 @@ | |||
1 | public class PasswordCracker { | ||
2 | |||
3 | // dies ist der laut Angabe bekannte Hashwert des Passworts | ||
4 | public static final String HASH = "ef937752f7348a964445f60857009f881983a6af"; | ||
5 | |||
6 | public static void main(String[] args) { | ||
7 | int numProcs = Runtime.getRuntime().availableProcessors(); | ||
8 | Thread[] workers = new Thread[numProcs]; | ||
9 | |||
10 | Synchronizer sync = new Synchronizer(HASH); | ||
11 | |||
12 | for (int i = 0; i < numProcs; i++) { | ||
13 | workers[i] = new Thread(new PasswordCrackerThread(sync, rangeBound(numProcs, i), rangeBound(numProcs, i + 1) - 1)); | ||
14 | workers[i].start(); | ||
15 | } | ||
16 | |||
17 | synchronized (sync) { | ||
18 | while (! sync.hasSolution()) { | ||
19 | try { | ||
20 | sync.wait(); | ||
21 | } catch (InterruptedException e) {} | ||
22 | } | ||
23 | } | ||
24 | |||
25 | for (Thread w : workers) | ||
26 | w.interrupt(); | ||
27 | |||
28 | System.out.println("Guessed this password: " + sync.getSolution()); | ||
29 | System.exit(0); | ||
30 | } | ||
31 | |||
32 | public static long rangeBound(int n, int i) { | ||
33 | long upperBound = (long) 1e8; | ||
34 | return n == i ? upperBound + 1 : (upperBound / n) * i; | ||
35 | } | ||
36 | } | ||