I'm trying to create a little project (I'm new to C#) where someone can input a key and a string to encrypt. However I have a logic error and it does not display. I have tried my best to explain each line best I could.
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); // so i dont have to make each thig in the array
Console.WriteLine("KeY: "); // ask for key
string key1 = Console.ReadLine(); // store it in a variabe
int key = Convert.ToInt32(key1); // make it a number
Console.WriteLine("Code to encrypt: ");
string code = Console.ReadLine(); // strig that need to be encryot
string EncryptedString = ""; // blank string to insert encrypted letter into
int leng = code.Length;
int i = 0;
while (i > leng)
{
char x = code[i]; // x is after every loop the consequetive letter in the string that needs encrypting
int y = Array.IndexOf(alphabet, x); // finds the index position that "x" is in the alphabet, e.g (a = 0, b = 1)
int z = alphabet[y + key]; // z is the letter index of the letter in alphabet but with the key amount over , imagine the key was 2, e.g (a = c)
string w = Convert.ToString(z); // w is z converted to a string
EncryptedString.Insert(i - 1, w); // is the the position you want to insert the letter, w is the letter you want inserting
i++;
}
Console.WriteLine(EncryptedString);
a logic error somewhere and the encrypted string just won't display