-
Notifications
You must be signed in to change notification settings - Fork 29
/
SimpleStringObfuscator.java
40 lines (34 loc) · 1.14 KB
/
SimpleStringObfuscator.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
import java.io.PrintStream;
import java.util.Random;
public class SimpleStringObfuscator {
public static void main(String[] args) {
if (args != null && args.length > 0) {
Random r = new Random(System.currentTimeMillis());
byte[] b = args[0].getBytes();
int c = b.length;
PrintStream o = System.out;
o.print("(new Object() {");
o.print("int t;");
o.print("public String toString() {");
o.print("byte[] buf = new byte[");
o.print(c);
o.print("];");
for (int i = 0; i < c; ++i) {
int t = r.nextInt();
int f = r.nextInt(24) + 1;
t = (t & ~(0xff << f)) | (b[i] << f);
o.print("t = ");
o.print(t);
o.print(";");
o.print("buf[");
o.print(i);
o.print("] = (byte) (t >>> ");
o.print(f);
o.print(");");
}
o.print("return new String(buf);");
o.print("}}.toString())");
o.println();
}
}
}