キーは大文字で、文字列は小文字です。だから、文
if (key[j] == toEncrypt[i])
と
else if (key[j+1] == toEncrypt[i])
真になることはありません、あなたが機能であなたの鍵を.ToLower()
すべき
編集:あなたは、あなたのエンコードを示さなかった
public static Tuple<string, int[]> Encode(string key, string toEncrypt)
{
key = key.ToLower();
int[] iterations = new int[] { 0, 0, 0, 0, 0, 0 };
if (key.Length % 2 == 0)
{
if (key.Length == key.Distinct().Count())
{
var encodedText = new StringBuilder(toEncrypt);
for (int i = 0; i < toEncrypt.Length ; i++)
{
for (int j = 0; j < key.Length; j += 2)
{
if (key[j] == toEncrypt[i])
{
encodedText[i] = key[j + 1];
iterations[j/2] += 1;
}
else if (key[j+1] == toEncrypt[i])
{
encodedText[i] = key[j];
iterations[j/2] += 1;
}
}
}
return Tuple.Create(encodedText.ToString(), iterations);
}
else throw new ArgumentException("Key cannot contain the same chars");
}
else throw new ArgumentException("You have to put a key which is dividable by 2");
}
機能 –
私はそれが役立つ場合、あまりにも機能を掲載しました。 –
あなたも囲むクラスを投稿することができます、関数はOKと見えます –