Created
October 30, 2019 01:26
-
-
Save Kwansy98/9a462d23c871578df3d8b5423bc5b632 to your computer and use it in GitHub Desktop.
与佛论禅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <component name="ArtifactManager"> | |
| <artifact type="jar" name="与佛论禅:jar"> | |
| <output-path>$PROJECT_DIR$/out/artifacts/_jar</output-path> | |
| <root id="archive" name="与佛论禅.jar"> | |
| <element id="module-output" name="与佛论禅" /> | |
| </root> | |
| </artifact> | |
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ProjectRootManager" version="2" languageLevel="JDK_12" default="true" project-jdk-name="12" project-jdk-type="JavaSDK"> | |
| <output url="file://$PROJECT_DIR$/out" /> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ProjectModuleManager"> | |
| <modules> | |
| <module fileurl="file://$PROJECT_DIR$/与佛论禅.iml" filepath="$PROJECT_DIR$/与佛论禅.iml" /> | |
| </modules> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="Palette2"> | |
| <group name="Swing"> | |
| <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> | |
| </item> | |
| <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> | |
| </item> | |
| <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> | |
| </item> | |
| <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> | |
| <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> | |
| </item> | |
| <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> | |
| <initial-values> | |
| <property name="text" value="Button" /> | |
| </initial-values> | |
| </item> | |
| <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
| <initial-values> | |
| <property name="text" value="RadioButton" /> | |
| </initial-values> | |
| </item> | |
| <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
| <initial-values> | |
| <property name="text" value="CheckBox" /> | |
| </initial-values> | |
| </item> | |
| <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> | |
| <initial-values> | |
| <property name="text" value="Label" /> | |
| </initial-values> | |
| </item> | |
| <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
| <preferred-size width="150" height="-1" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
| <preferred-size width="150" height="-1" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
| <preferred-size width="150" height="-1" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> | |
| </item> | |
| <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
| <preferred-size width="150" height="50" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
| <preferred-size width="200" height="200" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
| <preferred-size width="200" height="200" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
| </item> | |
| <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
| </item> | |
| <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> | |
| </item> | |
| <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> | |
| </item> | |
| <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> | |
| <preferred-size width="-1" height="20" /> | |
| </default-constraints> | |
| </item> | |
| <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
| <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> | |
| </item> | |
| <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
| <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> | |
| </item> | |
| </group> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ArtifactsWorkspaceSettings"> | |
| <artifacts-to-build> | |
| <artifact name="与佛论禅:jar" /> | |
| </artifacts-to-build> | |
| </component> | |
| <component name="ChangeListManager"> | |
| <list default="true" id="96bf4334-b1ab-4ec8-a2fe-cb1749e8e93c" name="Default Changelist" comment="" /> | |
| <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> | |
| <option name="SHOW_DIALOG" value="false" /> | |
| <option name="HIGHLIGHT_CONFLICTS" value="true" /> | |
| <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> | |
| <option name="LAST_RESOLUTION" value="IGNORE" /> | |
| </component> | |
| <component name="FileTemplateManagerImpl"> | |
| <option name="RECENT_TEMPLATES"> | |
| <list> | |
| <option value="Class" /> | |
| </list> | |
| </option> | |
| </component> | |
| <component name="ProjectId" id="1SpPbN7jBjuHcOyLslFOOgWvF4W" /> | |
| <component name="PropertiesComponent"> | |
| <property name="UI_DESIGNER_EDITOR_MODE.PaletteManager.WIDTH" value="257" /> | |
| <property name="project.structure.last.edited" value="SDKs" /> | |
| <property name="project.structure.proportion" value="0.15" /> | |
| <property name="project.structure.side.proportion" value="0.2" /> | |
| <property name="restartRequiresConfirmation" value="false" /> | |
| <property name="settings.editor.selected.configurable" value="vcs.Git" /> | |
| </component> | |
| <component name="RecentsManager"> | |
| <key name="MoveFile.RECENT_KEYS"> | |
| <recent name="C:\Users\ASUS\IdeaProjects\与佛论禅\src" /> | |
| </key> | |
| </component> | |
| <component name="RunDashboard"> | |
| <option name="ruleStates"> | |
| <list> | |
| <RuleState> | |
| <option name="name" value="ConfigurationTypeDashboardGroupingRule" /> | |
| </RuleState> | |
| <RuleState> | |
| <option name="name" value="StatusDashboardGroupingRule" /> | |
| </RuleState> | |
| </list> | |
| </option> | |
| </component> | |
| <component name="RunManager" selected="Application.TestBuddhism"> | |
| <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> | |
| <option name="MAIN_CLASS_NAME" value="Main" /> | |
| <module name="与佛论禅" /> | |
| <method v="2"> | |
| <option name="Make" enabled="true" /> | |
| </method> | |
| </configuration> | |
| <configuration name="TestBuddhism" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> | |
| <option name="MAIN_CLASS_NAME" value="TestBuddhism" /> | |
| <module name="与佛论禅" /> | |
| <extension name="coverage"> | |
| <pattern> | |
| <option name="PATTERN" value=".*" /> | |
| <option name="ENABLED" value="true" /> | |
| </pattern> | |
| </extension> | |
| <method v="2"> | |
| <option name="Make" enabled="true" /> | |
| </method> | |
| </configuration> | |
| <recent_temporary> | |
| <list> | |
| <item itemvalue="Application.TestBuddhism" /> | |
| <item itemvalue="Application.Main" /> | |
| </list> | |
| </recent_temporary> | |
| </component> | |
| <component name="SvnConfiguration"> | |
| <configuration /> | |
| </component> | |
| <component name="TaskManager"> | |
| <task active="true" id="Default" summary="Default task"> | |
| <changelist id="96bf4334-b1ab-4ec8-a2fe-cb1749e8e93c" name="Default Changelist" comment="" /> | |
| <created>1572257634714</created> | |
| <option name="number" value="Default" /> | |
| <option name="presentableId" value="Default" /> | |
| <updated>1572257634714</updated> | |
| </task> | |
| <servers /> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "太深奥了,参悟不出佛经的真意……"; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package buddhism; | |
| import java.util.HashMap; | |
| public class TruthTable { | |
| private static TruthTable instance = null; | |
| private static HashMap<String, String> map = new HashMap<>(); | |
| public static TruthTable getInstance() { | |
| if (instance != null) return instance; | |
| return new TruthTable(); | |
| } | |
| private TruthTable() { | |
| map.put("啰", "e"); | |
| map.put("羯", "E"); | |
| map.put("婆", "t"); | |
| map.put("提", "T"); | |
| map.put("摩", "a"); | |
| map.put("埵", "A"); | |
| map.put("诃", "o"); | |
| map.put("迦", "O"); | |
| map.put("耶", "i"); | |
| map.put("吉", "I"); | |
| map.put("娑", "n"); | |
| map.put("佛", "N"); | |
| map.put("夜", "s"); | |
| map.put("驮", "S"); | |
| map.put("那", "h"); | |
| map.put("谨", "H"); | |
| map.put("悉", "r"); | |
| map.put("墀", "R"); | |
| map.put("阿", "d"); | |
| map.put("呼", "D"); | |
| map.put("萨", "l"); | |
| map.put("尼", "L"); | |
| map.put("陀", "c"); | |
| map.put("唵", "C"); | |
| map.put("唎", "u"); | |
| map.put("伊", "U"); | |
| map.put("卢", "m"); | |
| map.put("喝", "M"); | |
| map.put("帝", "w"); | |
| map.put("烁", "W"); | |
| map.put("醯", "f"); | |
| map.put("蒙", "F"); | |
| map.put("罚", "g"); | |
| map.put("沙", "G"); | |
| map.put("嚧", "y"); | |
| map.put("他", "Y"); | |
| map.put("南", "p"); | |
| map.put("豆", "P"); | |
| map.put("无", "b"); | |
| map.put("孕", "B"); | |
| map.put("菩", "v"); | |
| map.put("伽", "V"); | |
| map.put("怛", "k"); | |
| map.put("俱", "K"); | |
| map.put("哆", "j"); | |
| map.put("度", "J"); | |
| map.put("皤", "x"); | |
| map.put("阇", "X"); | |
| map.put("室", "q"); | |
| map.put("地", "Q"); | |
| map.put("利", "z"); | |
| map.put("遮", "Z"); | |
| map.put("穆", "0"); | |
| map.put("参", "1"); | |
| map.put("舍", "2"); | |
| map.put("苏", "3"); | |
| map.put("钵", "4"); | |
| map.put("曳", "5"); | |
| map.put("数", "6"); | |
| map.put("写", "7"); | |
| map.put("栗", "8"); | |
| map.put("楞", "9"); | |
| map.put("咩", "+"); | |
| map.put("输", "/"); | |
| map.put("漫", "="); | |
| map.put("e", "啰"); | |
| map.put("E", "羯"); | |
| map.put("t", "婆"); | |
| map.put("T", "提"); | |
| map.put("a", "摩"); | |
| map.put("A", "埵"); | |
| map.put("o", "诃"); | |
| map.put("O", "迦"); | |
| map.put("i", "耶"); | |
| map.put("I", "吉"); | |
| map.put("n", "娑"); | |
| map.put("N", "佛"); | |
| map.put("s", "夜"); | |
| map.put("S", "驮"); | |
| map.put("h", "那"); | |
| map.put("H", "谨"); | |
| map.put("r", "悉"); | |
| map.put("R", "墀"); | |
| map.put("d", "阿"); | |
| map.put("D", "呼"); | |
| map.put("l", "萨"); | |
| map.put("L", "尼"); | |
| map.put("c", "陀"); | |
| map.put("C", "唵"); | |
| map.put("u", "唎"); | |
| map.put("U", "伊"); | |
| map.put("m", "卢"); | |
| map.put("M", "喝"); | |
| map.put("w", "帝"); | |
| map.put("W", "烁"); | |
| map.put("f", "醯"); | |
| map.put("F", "蒙"); | |
| map.put("g", "罚"); | |
| map.put("G", "沙"); | |
| map.put("y", "嚧"); | |
| map.put("Y", "他"); | |
| map.put("p", "南"); | |
| map.put("P", "豆"); | |
| map.put("b", "无"); | |
| map.put("B", "孕"); | |
| map.put("v", "菩"); | |
| map.put("V", "伽"); | |
| map.put("k", "怛"); | |
| map.put("K", "俱"); | |
| map.put("j", "哆"); | |
| map.put("J", "度"); | |
| map.put("x", "皤"); | |
| map.put("X", "阇"); | |
| map.put("q", "室"); | |
| map.put("Q", "地"); | |
| map.put("z", "利"); | |
| map.put("Z", "遮"); | |
| map.put("0", "穆"); | |
| map.put("1", "参"); | |
| map.put("2", "舍"); | |
| map.put("3", "苏"); | |
| map.put("4", "钵"); | |
| map.put("5", "曳"); | |
| map.put("6", "数"); | |
| map.put("7", "写"); | |
| map.put("8", "栗"); | |
| map.put("9", "楞"); | |
| map.put("+", "咩"); | |
| map.put("/", "输"); | |
| map.put("=", "漫"); | |
| } | |
| // 如果找不到映射返回 null | |
| public String get(String key) { | |
| return map.get(key); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import buddhism.BuddhismTools; | |
| import java.io.*; | |
| import java.net.InetSocketAddress; | |
| import java.net.Socket; | |
| import java.net.SocketAddress; | |
| import java.util.Scanner; | |
| public class Main { | |
| private static SocketAddress socketAddress = new InetSocketAddress("gg.4fk.me", 6324); | |
| private static Socket socket = new Socket(); | |
| private static BufferedReader in = null; | |
| private static PrintWriter out = null; | |
| public static void main(String[] args) { | |
| try { | |
| socket.connect(socketAddress); | |
| in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); | |
| out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"), true); | |
| System.out.println("连接服务器成功"); | |
| System.out.println("用法:输入人话,打印佛语并广播给其他人;输入佛语,翻译成人话,不广播"); | |
| Scanner sc = new Scanner(System.in); | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| try { | |
| String recv; | |
| while ((recv = in.readLine()) != null) { | |
| System.out.println(recv); | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }).start(); | |
| while (true) { | |
| String input = sc.nextLine(); | |
| if (input.isBlank()) continue; | |
| if (input.startsWith("佛曰:") || input.startsWith("如是我闻:")) { | |
| String encryptedString = BuddhismTools.buddhism2Human(input); | |
| System.out.println(encryptedString); | |
| } else { | |
| String buddhi = BuddhismTools.human2Buddhism(input); | |
| System.out.println(buddhi); | |
| out.println(buddhi); | |
| } | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } finally { | |
| try { | |
| if (in != null) in.close(); | |
| if (out != null) out.close(); | |
| if (socket != null) socket.close(); | |
| } catch (IOException ex) { | |
| ex.printStackTrace(); | |
| } | |
| } | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import buddhism.BuddhismTools; | |
| public class TestBuddhism { | |
| public static void main(String[] args) { | |
| String encryptedString = "佛曰:室参哆室娑伽阇栗啰诃唵嚧输遮摩迦耶伊栗埵遮陀罚栗喝驮哆那吉俱驮伊写穆唎数提豆室埵悉无钵曳室迦伽伽卢帝阇舍度伽陀埵数耶呼无他利烁蒙"; | |
| System.out.println(BuddhismTools.buddhism2Human(encryptedString)); | |
| String content = "清风不识字,何故乱翻书?"; | |
| String customKey = "dontusedefaultkey"; | |
| String encryptedString2 = BuddhismTools.human2Buddhism(content, customKey); | |
| System.out.println(encryptedString2); | |
| System.out.println(BuddhismTools.buddhism2Human(encryptedString2)); // use wrong key | |
| System.out.println(BuddhismTools.buddhism2Human(encryptedString2, customKey)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils; | |
| import javax.crypto.*; | |
| import javax.crypto.spec.SecretKeySpec; | |
| import java.io.UnsupportedEncodingException; | |
| import java.security.InvalidKeyException; | |
| import java.security.NoSuchAlgorithmException; | |
| import java.security.SecureRandom; | |
| import java.util.Base64; | |
| public class AESTools { | |
| private static final Base64.Decoder decoder = Base64.getDecoder(); | |
| private static final Base64.Encoder encoder = Base64.getEncoder(); | |
| public static byte[] AESEncode(String password, byte[] content) { | |
| try { | |
| KeyGenerator keygen = KeyGenerator.getInstance("AES"); | |
| SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); | |
| random.setSeed(password.getBytes()); | |
| keygen.init(128, random); | |
| SecretKey originalKey = keygen.generateKey(); | |
| SecretKey key = new SecretKeySpec(originalKey.getEncoded(), "AES"); | |
| Cipher cipher = Cipher.getInstance("AES"); | |
| cipher.init(Cipher.ENCRYPT_MODE, key); | |
| return Base64Tools.encode(cipher.doFinal(content)); // 加密后用base64编码 | |
| } catch (NoSuchAlgorithmException e) { | |
| // e.printStackTrace(); | |
| } catch (InvalidKeyException e) { | |
| // e.printStackTrace(); | |
| } catch (NoSuchPaddingException e) { | |
| // e.printStackTrace(); | |
| } catch (BadPaddingException e) { | |
| // e.printStackTrace(); | |
| } catch (UnsupportedEncodingException e) { | |
| // e.printStackTrace(); | |
| } catch (IllegalBlockSizeException e) { | |
| // e.printStackTrace(); | |
| } | |
| return null; | |
| } | |
| public static byte[] AESDecode(String password, byte[] content) { | |
| try { | |
| KeyGenerator keygen = KeyGenerator.getInstance("AES"); | |
| SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); | |
| random.setSeed(password.getBytes()); | |
| keygen.init(128, random); | |
| SecretKey originalKey = keygen.generateKey(); | |
| SecretKey key = new SecretKeySpec(originalKey.getEncoded(), "AES"); | |
| Cipher cipher = Cipher.getInstance("AES"); | |
| cipher.init(Cipher.DECRYPT_MODE, key); | |
| return cipher.doFinal(Base64Tools.decode(content)); | |
| } catch (NoSuchAlgorithmException e) { | |
| // e.printStackTrace(); | |
| } catch (InvalidKeyException e) { | |
| // e.printStackTrace(); | |
| } catch (NoSuchPaddingException e) { | |
| // e.printStackTrace(); | |
| } catch (BadPaddingException e) { | |
| // e.printStackTrace(); | |
| } catch (UnsupportedEncodingException e) { | |
| // e.printStackTrace(); | |
| } catch (IllegalBlockSizeException e) { | |
| // e.printStackTrace(); | |
| } | |
| return null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils; | |
| import java.io.UnsupportedEncodingException; | |
| import java.util.Base64; | |
| public class Base64Tools { | |
| private final static Base64.Decoder decoder = Base64.getDecoder(); | |
| private final static Base64.Encoder encoder = Base64.getEncoder(); | |
| public static byte[] encode(byte[] content) throws UnsupportedEncodingException { | |
| return encoder.encode(content); | |
| } | |
| public static byte[] decode(byte[] content) throws UnsupportedEncodingException { | |
| return decoder.decode(content); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <module type="JAVA_MODULE" version="4"> | |
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | |
| <exclude-output /> | |
| <content url="file://$MODULE_DIR$"> | |
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
| </content> | |
| <orderEntry type="inheritedJdk" /> | |
| <orderEntry type="sourceFolder" forTests="false" /> | |
| </component> | |
| </module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment