-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cracker.java
executable file
·62 lines (53 loc) · 1.53 KB
/
Cracker.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
// Cracker.java
/*
Generates SHA hashes of short strings in parallel.
*/
import java.security.*;
public class Cracker {
// Array of chars used to produce strings
public static final char[] CHARS = "abcdefghijklmnopqrstuvwxyz0123456789.,-!".toCharArray();
/*
Given a byte[] array, produces a hex String,
such as "234a6f". with 2 chars for each byte in the array.
(provided code)
*/
public static String hexToString(byte[] bytes) {
StringBuffer buff = new StringBuffer();
for (int i=0; i<bytes.length; i++) {
int val = bytes[i];
val = val & 0xff; // remove higher bits, sign
if (val<16) buff.append('0'); // leading 0
buff.append(Integer.toString(val, 16));
}
return buff.toString();
}
/*
Given a string of hex byte values such as "24a26f", creates
a byte[] array of those values, one byte value -128..127
for each 2 chars.
(provided code)
*/
public static byte[] hexToArray(String hex) {
byte[] result = new byte[hex.length()/2];
for (int i=0; i<hex.length(); i+=2) {
result[i/2] = (byte) Integer.parseInt(hex.substring(i, i+2), 16);
}
return result;
}
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Args: target length [workers]");
System.exit(1);
}
// args: targ len [num]
String targ = args[0];
int len = Integer.parseInt(args[1]);
int num = 1;
if (args.length>2) {
num = Integer.parseInt(args[2]);
}
// a! 34800e15707fae815d7c90d49de44aca97e2d759
// xyz 66b27417d37e024c46526c2f6d358a754fc552f3
// YOUR CODE HERE
}
}