|
@@ -9,6 +9,10 @@ import java.util.List;
|
|
*/
|
|
*/
|
|
public class CryptUtil {
|
|
public class CryptUtil {
|
|
|
|
|
|
|
|
+ private final static char EN_MAX = '\u0080';//128
|
|
|
|
+ private final static int MOVE_NUM = 2;
|
|
|
|
+ private final static char DE_MAX = EN_MAX + MOVE_NUM;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 加密,把一个字符串在原有的基础上+2
|
|
* 加密,把一个字符串在原有的基础上+2
|
|
*
|
|
*
|
|
@@ -18,7 +22,9 @@ public class CryptUtil {
|
|
public static String encrypt_char(String data) {
|
|
public static String encrypt_char(String data) {
|
|
char[] chars = data.toCharArray();
|
|
char[] chars = data.toCharArray();
|
|
for (int i = 0; i < chars.length; i++) {
|
|
for (int i = 0; i < chars.length; i++) {
|
|
- chars[i] += 2;
|
|
|
|
|
|
+ if (EN_MAX < chars[i]) {
|
|
|
|
+ chars[i] += MOVE_NUM;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return new String(chars);
|
|
return new String(chars);
|
|
}
|
|
}
|
|
@@ -32,7 +38,9 @@ public class CryptUtil {
|
|
public static String decrypt_char(String data) {
|
|
public static String decrypt_char(String data) {
|
|
char[] chars = data.toCharArray();
|
|
char[] chars = data.toCharArray();
|
|
for (int i = 0; i < chars.length; i++) {
|
|
for (int i = 0; i < chars.length; i++) {
|
|
- chars[i] -= 2;
|
|
|
|
|
|
+ if (DE_MAX < chars[i]) {
|
|
|
|
+ chars[i] -= MOVE_NUM;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return new String(chars);
|
|
return new String(chars);
|
|
}
|
|
}
|
|
@@ -64,10 +72,16 @@ public class CryptUtil {
|
|
|
|
|
|
|
|
|
|
//加密中文
|
|
//加密中文
|
|
- data = "跳梁小豆tlxd666,";
|
|
|
|
|
|
+ data = "跳梁小豆tlxd666,z";
|
|
String result = encrypt_char(data);
|
|
String result = encrypt_char(data);
|
|
System.out.println("加密后:" + result);
|
|
System.out.println("加密后:" + result);
|
|
String str1 = decrypt_char(result);
|
|
String str1 = decrypt_char(result);
|
|
System.out.println("解密后:" + str1);
|
|
System.out.println("解密后:" + str1);
|
|
|
|
+
|
|
|
|
+// int num = 32;
|
|
|
|
+// while (num <= 128) {
|
|
|
|
+// System.out.println((char) num + " (Unicode编码对应的数字为:) " + num);
|
|
|
|
+// num++;
|
|
|
|
+// }
|
|
}
|
|
}
|
|
}
|
|
}
|