Encrypt and Decrypt text using alphabet shifting method


Decrypt
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            char[] cypertext = (txtCyperText.Text.ToUpper()).ToCharArray();

            string decryptText = "";
            foreach (char item in cypertext)
            {
                for (int i = 0; i < alpha.Length; i++)
                {
                    if (item == 'A')
                    {
                        decryptText = decryptText + "X";
                        break;
                    }
                    else if (item == 'B')
                    {
                        decryptText = decryptText + "Y";
                        break;
                    }
                    else if (item == 'C')
                    {
                        decryptText = decryptText + "Z";
                        break;
                    }
                    else if (item == alpha[i])
                    {
                        decryptText = decryptText + alpha[i - 3];
                        break;
                    }
                }
            }


            txtDecryptText.Text = decryptText;




Encrypt
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            char[] decriptText = (txtDecryptText.Text.ToUpper()).ToCharArray();

            string encryptText = "";
            foreach (char item in decriptText)
            {
                for (int i = 0; i < alpha.Length; i++)
                {
                    if (item == 'X')
                    {
                        encryptText = encryptText + "A";
                        break;
                    }
                    else if (item == 'Y')
                    {
                        encryptText = encryptText + "B";
                        break;
                    }
                    else if (item == 'Z')
                    {
                        encryptText = encryptText + "C";
                        break;
                    }
                    else if (item == alpha[i])
                    {
                        encryptText = encryptText + alpha[i + 3];
                        break;
                    }
                }               
            }
            txtEncryptText.Text = encryptText;

Comments

Popular posts from this blog

Gridview to Datatable and Viewstate

You think Creating Circuler Graph is a difficult task ...........!!!