Example #1
0
        public static string DecryptVi(string ciphertext, string key)
        {
            char   letter;
            string plaintext = "";
            int    j         = 0;

            key    = key.ToLower();
            letter = ' ';
            for (int i = 0; i < ciphertext.Length; i++, j++)//i for the ciphertext and j for the key
            {
                if (j == key.Length)
                {
                    j = 0;
                }//check the key back to the start if needed

                char character = ciphertext[i];
                char keyLetter = key[j];
                int  shift     = Convert.ToInt32(keyLetter) - 97;
                letter = Convert.ToChar(CeaserCipher.DecryptCC(character.ToString(), shift));//ceaser shift the characters back

                plaintext += letter;
            }
            return(plaintext);
        }
Example #2
0
        public static string EncryptVi(string plaintext, string key)
        {
            char   letter;//declare and intitialise variables
            string ciphertext = "";
            int    j          = 0;

            key    = key.ToLower();
            letter = ' ';
            for (int i = 0; i < plaintext.Length; i++, j++)//j is for the key, i is for the plaintext
            {
                if (j == key.Length)
                {
                    j = 0;
                }//loop for checking if the key needs resetting

                char character = plaintext[i];
                char keyLetter = key[j];
                int  shift     = Convert.ToInt32(keyLetter) - 97;
                letter = Convert.ToChar(CeaserCipher.EncryptCC(character.ToString(), shift)); //ceaser cipher the induvidual characters by the shift of one of the key characters

                ciphertext += letter;                                                         //add to the ciphertext
            }
            return(ciphertext);
        }