我想编写一个简单的加密算法,使用随机移位模式加密。我已经编写了一个基于所有字符数组的算法,然后使用Collections.shuffle进行混淆,并将其与之匹配。然而,该数组似乎没有被混淆,因为输出文本与输入相同。
这是我的方法:
这是我的方法:
static void encrypt(String s)
{
//Define variable for indexOf output
int n;
//Encrypted output
String output = "";
//Shuffle array to create random replacements
Collections.shuffle(Arrays.asList(alphashuff));
//Create new string
String alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int index = 0; index < s.length();index++)
{
char aChar = s.charAt(index);
n = alpha.indexOf(aChar, 0);
if(n == -1)
{
output = output + aChar;
}
else
{
output = output + alphashuff[n];
}
}
//Print encrypted string to console
System.out.println("Encrypted Text: " + output);
}
Arrays.asList
函数来创建列表。 - Subhrajyoti MajumderList<Object>
。 - Luiggi MendozaArrayUtils
是 Java 的原生类吗?我认为它是来自于 Apache Commons Lang。 - Luiggi Mendoza