I'm writing an alphabet cipher that ciphers at random. It looks like it should work when I'm debugging it but when I look at the cipher key it comes out with duplicate letters like some of them weren't switched during the for loop. Any help is much appreciated. WasSwapped is used to keep track of whether the letters been used in the cipher already and alphabet is just a list of the alphabet in order. All arrays and lists are size 26.
List<String^>^ encryptAlphabet = gcnew List<String^>();
array<bool>^ wasSwapped = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
Random^ rand = gcnew Random();
int temp;
encryptAlphabet = alphabet;
for(int i =0; i < 26; i++)
{
temp = rand->Next(26);
if(wasSwapped[temp] ==false)
{
encryptAlphabet[i] = alphabet[temp];
wasSwapped[temp] = true;
}
else
{
i -= 1;
}
}