?? 維吉尼亞.txt
字號(hào):
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)// 正負(fù)號(hào)和小數(shù)點(diǎn)不處理
{
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)// 正負(fù)號(hào)和小數(shù)點(diǎn)不處理
{
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;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -