-
Notifications
You must be signed in to change notification settings - Fork 7
/
BuddhismTools.java
80 lines (71 loc) · 3.22 KB
/
BuddhismTools.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
package buddhism;
import utils.AESTools;
public class BuddhismTools {
private static final String password = "U2FsdGVkX1+9azMGhHoOZ59u"; // 默认密钥
private static final TruthTable truthTable = TruthTable.getInstance();
// base64密文 <-- 字符映射 --> 佛语
private static String encode(String content) throws Exception {
char[] arr = content.toCharArray();
StringBuilder res = new StringBuilder();
for (char c : arr) {
String rp = truthTable.get(String.valueOf(c));
if (rp == null) throw new Exception(""); // 不在真值表内的字符无法处理
res.append(rp);
}
return res.toString();
}
public static String human2Buddhism(String human) {
String base64EncryptedString = new String(AESTools.AESEncode(password, human.getBytes()));
String buddhiString = "";
try {
buddhiString = encode(base64EncryptedString);
} catch (Exception e) {
e.printStackTrace();
}
return human.length() % 2 == 0 ? "如是我闻:" + buddhiString : "佛曰:" + buddhiString;
}
public static String human2Buddhism(String human, String password) {
String base64EncryptedString = new String(AESTools.AESEncode(password, human.getBytes()));
String buddhiString = "";
try {
buddhiString = encode(base64EncryptedString);
} catch (Exception e) {
e.printStackTrace();
}
return human.length() % 2 == 0 ? "如是我闻:" + buddhiString : "佛曰:" + buddhiString;
}
public static String buddhism2Human(String buddhi) {
try {
if (buddhi.startsWith("佛曰:")) {
buddhi = buddhi.split("佛曰:")[1];
String base64Encrypted = encode(buddhi);
return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
} else if (buddhi.startsWith("如是我闻:")) {
buddhi = buddhi.split("如是我闻:")[1];
String base64Encrypted = encode(buddhi);
return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
} else {
return "太深奥了,参悟不出佛经的真意……";
}
} catch (Exception ex) {
return "太深奥了,参悟不出佛经的真意……";
}
}
public static String buddhism2Human(String buddhi, String password) {
try {
if (buddhi.startsWith("佛曰:")) {
buddhi = buddhi.split("佛曰:")[1];
String base64Encrypted = encode(buddhi);
return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
} else if (buddhi.startsWith("如是我闻:")) {
buddhi = buddhi.split("如是我闻:")[1];
String base64Encrypted = encode(buddhi);
return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
} else {
return "太深奥了,参悟不出佛经的真意……";
}
} catch (Exception ex) {
return "太深奥了,参悟不出佛经的真意……";
}
}
}