📄 维吉尼亚.txt
字号:
public static BigDecimal vigenere(BigDecimal bd, String key, int mode) {
if (bd == null || key == null)
return null;
if (mode == MyTools.ENCRYPT_MODE) // 加密
{
String str = bd.toPlainString();
byte[] strBytes = str.getBytes();
byte[] keyBytes = key.getBytes();
int keyLength = keyBytes.length;
byte[] result = new byte[strBytes.length];
for (int i = 0; i < strBytes.length; i++) {
if (strBytes[i] == 43 || strBytes[i] == 45 || strBytes[i] == 46)// 正负号和小数点不处理
{
result[i] = strBytes[i];
continue;
}
result[i] = (byte) ((strBytes[i] - 48 + keyBytes[i % keyLength] - 48) % 10 + 48);
}
String inDateBase = new String(result);
if (!str.substring(0, 1).equals("-") && !str.substring(0, 1).equals("+"))
inDateBase = "1" + inDateBase;
else if (str.substring(0, 1).equals("-") || str.substring(0, 1).equals("+"))
inDateBase = inDateBase.substring(0, 1) + "1" + inDateBase.substring(1);
return new BigDecimal(inDateBase);
} else if (mode == MyTools.DECRYPT_MODE) { // 解密
String str = bd.toPlainString();
if (!str.substring(0, 1).equals("-") && !str.substring(0, 1).equals("+"))
str = str.substring(1);
else if (str.substring(0, 1).equals("-") || str.substring(0, 1).equals("+"))
str = str.substring(0, 1) + str.substring(2);
byte[] strBytes = str.getBytes();
byte[] keyBytes = key.getBytes();
int keyLength = keyBytes.length;
byte[] result = new byte[strBytes.length];
for (int i = 0; i < strBytes.length; i++) {
if (strBytes[i] == 43 || strBytes[i] == 45 || strBytes[i] == 46)// 正负号和小数点不处理
{
result[i] = strBytes[i];
continue;
}
int temp = strBytes[i] - keyBytes[i % keyLength];
if (temp < 0)
temp += 10;
result[i] = (byte) (temp % 10 + 48);
}
return new BigDecimal(new String(result));
}
return null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -