├── out
├── production
│ └── yufolunchan
│ │ ├── META-INF
│ │ └── yufolunchan.kotlin_module
│ │ ├── TestBuddhism.class
│ │ ├── utils
│ │ ├── AESTools.class
│ │ └── Base64Tools.class
│ │ └── buddhism
│ │ ├── TruthTable.class
│ │ └── BuddhismTools.class
└── artifacts
│ └── _jar
│ └── 与佛论禅.jar
├── .idea
├── vcs.xml
├── misc.xml
├── modules.xml
├── artifacts
│ └── _jar.xml
├── workspace.xml
└── uiDesigner.xml
├── yufolunchan.iml
├── src
├── TestBuddhism.java
├── utils
│ ├── Base64Tools.java
│ └── AESTools.java
└── buddhism
│ ├── BuddhismTools.java
│ └── TruthTable.java
└── README.md
/out/production/yufolunchan/META-INF/yufolunchan.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/out/artifacts/_jar/与佛论禅.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/artifacts/_jar/与佛论禅.jar
--------------------------------------------------------------------------------
/out/production/yufolunchan/TestBuddhism.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/production/yufolunchan/TestBuddhism.class
--------------------------------------------------------------------------------
/out/production/yufolunchan/utils/AESTools.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/production/yufolunchan/utils/AESTools.class
--------------------------------------------------------------------------------
/out/production/yufolunchan/utils/Base64Tools.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/production/yufolunchan/utils/Base64Tools.class
--------------------------------------------------------------------------------
/out/production/yufolunchan/buddhism/TruthTable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/production/yufolunchan/buddhism/TruthTable.class
--------------------------------------------------------------------------------
/out/production/yufolunchan/buddhism/BuddhismTools.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kwansy98/yufolunchan/HEAD/out/production/yufolunchan/buddhism/BuddhismTools.class
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/artifacts/_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/_jar
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/yufolunchan.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/TestBuddhism.java:
--------------------------------------------------------------------------------
1 | import buddhism.BuddhismTools;
2 |
3 | public class TestBuddhism {
4 | public static void main(String[] args) {
5 | String content = "Hello world!";
6 | String encryptedContent = BuddhismTools.human2Buddhism(content, "MYCUSTOMKEY");
7 | System.out.println(encryptedContent);
8 |
9 | String decryptedContent = BuddhismTools.buddhism2Human(encryptedContent, "MYCUSTOMKEY");
10 | System.out.println(decryptedContent);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/utils/Base64Tools.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.util.Base64;
5 | public class Base64Tools {
6 | private final static Base64.Decoder decoder = Base64.getDecoder();
7 | private final static Base64.Encoder encoder = Base64.getEncoder();
8 |
9 | public static byte[] encode(byte[] content) throws UnsupportedEncodingException {
10 | return encoder.encode(content);
11 | }
12 |
13 | public static byte[] decode(byte[] content) throws UnsupportedEncodingException {
14 | return decoder.decode(content);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 与佛论禅加密API
2 |
3 | 与佛论禅加密基于AES加密算法,可实现文本和咒语的互相转换。
4 |
5 | ---
6 |
7 | * **编译运行**
8 |
9 | 使用JDK8或更高版本的编译器
10 |
11 | ---
12 |
13 |
14 | * **使用方法**
15 |
16 |
17 | 使用默认密钥加密
18 |
19 | ```
20 | String content = "Hello world!";
21 | String encryptedContent = BuddhismTools.human2Buddhism(content);
22 | System.out.println(encryptedContent);
23 | ```
24 |
25 | 使用默认密钥解密
26 |
27 | ```
28 | String decryptedContent = BuddhismTools.buddhism2Human(encryptedContent);
29 | System.out.println(decryptedContent);
30 | ```
31 |
32 | 使用自定义密钥
33 |
34 | ```
35 | String content = "Hello world!";
36 | String encryptedContent = BuddhismTools.human2Buddhism(content, "MYCUSTOMKEY");
37 | System.out.println(encryptedContent);
38 | String decryptedContent = BuddhismTools.buddhism2Human(encryptedContent, "MYCUSTOMKEY");
39 | System.out.println(decryptedContent);
40 | ```
41 |
42 |
43 | ---
44 |
45 |
46 | 目前是对base64的65个字符进行映射,也可以找256个佛经里面的字对字节进行映射,那样咒语就会更加丰富。
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/utils/AESTools.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import javax.crypto.*;
4 | import javax.crypto.spec.SecretKeySpec;
5 | import java.io.UnsupportedEncodingException;
6 | import java.security.InvalidKeyException;
7 | import java.security.NoSuchAlgorithmException;
8 | import java.security.SecureRandom;
9 | import java.util.Base64;
10 |
11 | public class AESTools {
12 | private static final Base64.Decoder decoder = Base64.getDecoder();
13 | private static final Base64.Encoder encoder = Base64.getEncoder();
14 | public static byte[] AESEncode(String password, byte[] content) {
15 | try {
16 | KeyGenerator keygen = KeyGenerator.getInstance("AES");
17 | SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
18 | random.setSeed(password.getBytes());
19 | keygen.init(128, random);
20 | SecretKey originalKey = keygen.generateKey();
21 | SecretKey key = new SecretKeySpec(originalKey.getEncoded(), "AES");
22 | Cipher cipher = Cipher.getInstance("AES");
23 | cipher.init(Cipher.ENCRYPT_MODE, key);
24 | return Base64Tools.encode(cipher.doFinal(content)); // 加密后用base64编码
25 | } catch (NoSuchAlgorithmException e) {
26 | // e.printStackTrace();
27 | } catch (InvalidKeyException e) {
28 | // e.printStackTrace();
29 | } catch (NoSuchPaddingException e) {
30 | // e.printStackTrace();
31 | } catch (BadPaddingException e) {
32 | // e.printStackTrace();
33 | } catch (UnsupportedEncodingException e) {
34 | // e.printStackTrace();
35 | } catch (IllegalBlockSizeException e) {
36 | // e.printStackTrace();
37 | }
38 | return null;
39 | }
40 |
41 | public static byte[] AESDecode(String password, byte[] content) {
42 | try {
43 | KeyGenerator keygen = KeyGenerator.getInstance("AES");
44 | SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
45 | random.setSeed(password.getBytes());
46 | keygen.init(128, random);
47 | SecretKey originalKey = keygen.generateKey();
48 | SecretKey key = new SecretKeySpec(originalKey.getEncoded(), "AES");
49 | Cipher cipher = Cipher.getInstance("AES");
50 | cipher.init(Cipher.DECRYPT_MODE, key);
51 | return cipher.doFinal(Base64Tools.decode(content));
52 | } catch (NoSuchAlgorithmException e) {
53 | // e.printStackTrace();
54 | } catch (InvalidKeyException e) {
55 | // e.printStackTrace();
56 | } catch (NoSuchPaddingException e) {
57 | // e.printStackTrace();
58 | } catch (BadPaddingException e) {
59 | // e.printStackTrace();
60 | } catch (UnsupportedEncodingException e) {
61 | // e.printStackTrace();
62 | } catch (IllegalBlockSizeException e) {
63 | // e.printStackTrace();
64 | }
65 | return null;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/buddhism/BuddhismTools.java:
--------------------------------------------------------------------------------
1 | package buddhism;
2 |
3 | import utils.AESTools;
4 |
5 | public class BuddhismTools {
6 | private static final String password = "U2FsdGVkX1+9azMGhHoOZ59u"; // 默认密钥
7 | private static final TruthTable truthTable = TruthTable.getInstance();
8 |
9 | // base64密文 <-- 字符映射 --> 佛语
10 | private static String encode(String content) throws Exception {
11 | char[] arr = content.toCharArray();
12 | StringBuilder res = new StringBuilder();
13 | for (char c : arr) {
14 | String rp = truthTable.get(String.valueOf(c));
15 | if (rp == null) throw new Exception(""); // 不在真值表内的字符无法处理
16 | res.append(rp);
17 | }
18 | return res.toString();
19 | }
20 |
21 | public static String human2Buddhism(String human) {
22 | String base64EncryptedString = new String(AESTools.AESEncode(password, human.getBytes()));
23 | String buddhiString = "";
24 | try {
25 | buddhiString = encode(base64EncryptedString);
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | return human.length() % 2 == 0 ? "如是我闻:" + buddhiString : "佛曰:" + buddhiString;
30 | }
31 |
32 | public static String human2Buddhism(String human, String password) {
33 | String base64EncryptedString = new String(AESTools.AESEncode(password, human.getBytes()));
34 | String buddhiString = "";
35 | try {
36 | buddhiString = encode(base64EncryptedString);
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | return human.length() % 2 == 0 ? "如是我闻:" + buddhiString : "佛曰:" + buddhiString;
41 | }
42 |
43 | public static String buddhism2Human(String buddhi) {
44 | try {
45 | if (buddhi.startsWith("佛曰:")) {
46 | buddhi = buddhi.split("佛曰:")[1];
47 | String base64Encrypted = encode(buddhi);
48 | return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
49 | } else if (buddhi.startsWith("如是我闻:")) {
50 | buddhi = buddhi.split("如是我闻:")[1];
51 | String base64Encrypted = encode(buddhi);
52 | return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
53 | } else {
54 | return "太深奥了,参悟不出佛经的真意……";
55 | }
56 | } catch (Exception ex) {
57 | return "太深奥了,参悟不出佛经的真意……";
58 | }
59 | }
60 |
61 | public static String buddhism2Human(String buddhi, String password) {
62 | try {
63 | if (buddhi.startsWith("佛曰:")) {
64 | buddhi = buddhi.split("佛曰:")[1];
65 | String base64Encrypted = encode(buddhi);
66 | return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
67 | } else if (buddhi.startsWith("如是我闻:")) {
68 | buddhi = buddhi.split("如是我闻:")[1];
69 | String base64Encrypted = encode(buddhi);
70 | return new String(AESTools.AESDecode(password, base64Encrypted.getBytes()));
71 | } else {
72 | return "太深奥了,参悟不出佛经的真意……";
73 | }
74 | } catch (Exception ex) {
75 | return "太深奥了,参悟不出佛经的真意……";
76 | }
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
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 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | 1572257634714
90 |
91 |
92 | 1572257634714
93 |
94 |
95 |
96 |
97 |
98 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/src/buddhism/TruthTable.java:
--------------------------------------------------------------------------------
1 | package buddhism;
2 |
3 | import java.util.HashMap;
4 |
5 | public class TruthTable {
6 | private static TruthTable instance = null;
7 | private static HashMap map = new HashMap<>();
8 |
9 | public static TruthTable getInstance() {
10 | if (instance != null) return instance;
11 | return new TruthTable();
12 | }
13 |
14 | private TruthTable() {
15 | map.put("啰", "e");
16 | map.put("羯", "E");
17 | map.put("婆", "t");
18 | map.put("提", "T");
19 | map.put("摩", "a");
20 | map.put("埵", "A");
21 | map.put("诃", "o");
22 | map.put("迦", "O");
23 | map.put("耶", "i");
24 | map.put("吉", "I");
25 | map.put("娑", "n");
26 | map.put("佛", "N");
27 | map.put("夜", "s");
28 | map.put("驮", "S");
29 | map.put("那", "h");
30 | map.put("谨", "H");
31 | map.put("悉", "r");
32 | map.put("墀", "R");
33 | map.put("阿", "d");
34 | map.put("呼", "D");
35 | map.put("萨", "l");
36 | map.put("尼", "L");
37 | map.put("陀", "c");
38 | map.put("唵", "C");
39 | map.put("唎", "u");
40 | map.put("伊", "U");
41 | map.put("卢", "m");
42 | map.put("喝", "M");
43 | map.put("帝", "w");
44 | map.put("烁", "W");
45 | map.put("醯", "f");
46 | map.put("蒙", "F");
47 | map.put("罚", "g");
48 | map.put("沙", "G");
49 | map.put("嚧", "y");
50 | map.put("他", "Y");
51 | map.put("南", "p");
52 | map.put("豆", "P");
53 | map.put("无", "b");
54 | map.put("孕", "B");
55 | map.put("菩", "v");
56 | map.put("伽", "V");
57 | map.put("怛", "k");
58 | map.put("俱", "K");
59 | map.put("哆", "j");
60 | map.put("度", "J");
61 | map.put("皤", "x");
62 | map.put("阇", "X");
63 | map.put("室", "q");
64 | map.put("地", "Q");
65 | map.put("利", "z");
66 | map.put("遮", "Z");
67 | map.put("穆", "0");
68 | map.put("参", "1");
69 | map.put("舍", "2");
70 | map.put("苏", "3");
71 | map.put("钵", "4");
72 | map.put("曳", "5");
73 | map.put("数", "6");
74 | map.put("写", "7");
75 | map.put("栗", "8");
76 | map.put("楞", "9");
77 | map.put("咩", "+");
78 | map.put("输", "/");
79 | map.put("漫", "=");
80 |
81 | map.put("e", "啰");
82 | map.put("E", "羯");
83 | map.put("t", "婆");
84 | map.put("T", "提");
85 | map.put("a", "摩");
86 | map.put("A", "埵");
87 | map.put("o", "诃");
88 | map.put("O", "迦");
89 | map.put("i", "耶");
90 | map.put("I", "吉");
91 | map.put("n", "娑");
92 | map.put("N", "佛");
93 | map.put("s", "夜");
94 | map.put("S", "驮");
95 | map.put("h", "那");
96 | map.put("H", "谨");
97 | map.put("r", "悉");
98 | map.put("R", "墀");
99 | map.put("d", "阿");
100 | map.put("D", "呼");
101 | map.put("l", "萨");
102 | map.put("L", "尼");
103 | map.put("c", "陀");
104 | map.put("C", "唵");
105 | map.put("u", "唎");
106 | map.put("U", "伊");
107 | map.put("m", "卢");
108 | map.put("M", "喝");
109 | map.put("w", "帝");
110 | map.put("W", "烁");
111 | map.put("f", "醯");
112 | map.put("F", "蒙");
113 | map.put("g", "罚");
114 | map.put("G", "沙");
115 | map.put("y", "嚧");
116 | map.put("Y", "他");
117 | map.put("p", "南");
118 | map.put("P", "豆");
119 | map.put("b", "无");
120 | map.put("B", "孕");
121 | map.put("v", "菩");
122 | map.put("V", "伽");
123 | map.put("k", "怛");
124 | map.put("K", "俱");
125 | map.put("j", "哆");
126 | map.put("J", "度");
127 | map.put("x", "皤");
128 | map.put("X", "阇");
129 | map.put("q", "室");
130 | map.put("Q", "地");
131 | map.put("z", "利");
132 | map.put("Z", "遮");
133 | map.put("0", "穆");
134 | map.put("1", "参");
135 | map.put("2", "舍");
136 | map.put("3", "苏");
137 | map.put("4", "钵");
138 | map.put("5", "曳");
139 | map.put("6", "数");
140 | map.put("7", "写");
141 | map.put("8", "栗");
142 | map.put("9", "楞");
143 | map.put("+", "咩");
144 | map.put("/", "输");
145 | map.put("=", "漫");
146 | }
147 |
148 | // 如果找不到映射返回 null
149 | public String get(String key) {
150 | return map.get(key);
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------