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;
    }
}

Hey guys. I'm back. It ended up being a problem with the lists. It works fine when I change them to arrays which is acceptable in this situation. Thanks everyone who took a look.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.