我正在使用下面的代碼根據特定的表對字符串進行置換。如何在置換後重新排列字符串
public static void main(String[] args) {
int[] IP = { 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 };
String text = "00000001 00100011 01000101 01100111 10001001 10101011 11001101 11101111".replace(" ", "");
text = Permute(text,IP);
System.out.println(text);
}
public static String Permute(String text,int [] table)
{
String keys = "0" + text;
StringBuilder sb = new StringBuilder();
for (int i = 1 ; i <= table.length; i++)
{
sb.append(keys.charAt(table[i-1]));
}
return sb.toString();
}
修訂:任何想法創造另一種方法來獲得原始字符串回來?喜歡的東西:
public static String GetoriginalText(String TextafterPermutation,int [] table)
保存其獨立的變量引用? ;-) – Andremoniy
假設我丟失了原文。如何恢復? – FSm
排列表可以包含兩倍相同的索引嗎? – Sebas