Witam,
mam kod funkcji deszyfrującej szyfr płotkowy napisany w C#. Potrzebuję go w programie z javy, niestety podczas przepisania tego kodu na jave występuje problem z listami gdyż nie mogę stworzyć listy w taki sam sposób jak tutaj, gdyż muszę wybierać pomiędzy ArrayList a LinkedList, a każde z tych rozwiązań stwarza problem podczas railFence[number].Add(i);
public static string Decrypt(int rail, string cipherText)
{
int cipherLength = cipherText.Length;
List<List<int>> railFence = new List<List<int>>();
for (int i = 0; i < rail; i++)
{
railFence.Add(new List<int>());
}
int number = 0;
int increment = 1;
for (int i = 0; i < cipherLength; i++)
{
if (number + increment == rail)
{
increment = -1;
}
else if (number + increment == -1)
{
increment = 1;
}
railFence[number].Add(i);
number += increment;
}
int counter = 0;
char[] buffer = new char[cipherLength];
for (int i = 0; i < rail; i++)
{
for (int j = 0; j < railFence[i].Count; j++)
{
buffer[railFence[i][j]] = cipherText[counter];
counter++;
}
}
return new string(buffer);
}
Będę wdzięczny za każdą podpowiedź.
Pozdrawiam