Ejemplo n.º 1
0
        static private string processString2(string w, string p)
        {
            //Input to uppercase
            string word   = w.ToUpper();
            string phrase = p.ToUpper();

            //Input to array
            char[] wordArray   = word.ToCharArray();
            char[] phraseArray = phrase.ToCharArray();

            //Defines array length
            int wordInt   = wordArray.Length;
            int phraseInt = phraseArray.Length;

            //Initializes variables
            int    x             = 0;
            int    y             = 0;
            string encodedPhrase = ("");

            //Initializes reverse code grid
            char[][] Grid = CipherGrid.Initialize2();

            //2nd encryption starts
            for (int i = 0; i < phraseInt; i++)
            {
                //Picks out character
                char wordChar   = wordArray[x];
                char phraseChar = phraseArray[y];

                //Sets character to numerical value (0-25)
                int wordCharInt   = wordChar - 65;
                int phraseCharInt = phraseChar - 65;

                //Finds character's ecrypted equivalent
                char encode = Grid[wordCharInt][phraseCharInt];

                //Adds encrypted character to output string
                encodedPhrase += ($"{encode}");

                //Repeats code word through phrase to encrypt
                x++;
                y++;
                if (x == wordInt)
                {
                    x = 0;
                }
            }

            //Returns final phrase to 1st method
            return(encodedPhrase);
        }
Ejemplo n.º 2
0
        //2nd level decryption method (goes first)
        static private string processString2(string w, string p)
        {
            //Initial converstions
            string word   = w.ToUpper();
            string phrase = p.ToUpper();

            char[] wordArray   = word.ToCharArray();
            char[] phraseArray = phrase.ToCharArray();
            int    wordInt     = wordArray.Length;
            int    phraseInt   = phraseArray.Length;

            //Set needed variables
            int    x             = 0;
            int    y             = 0;
            string decodedPhrase = ("");

            //Initialize reverse code grid
            char[][] Grid = CipherGrid.Initialize2();

            //Finds encrypted character address
            for (int i = 0; i < phraseInt; i++)
            {
                char wordChar   = wordArray[x];
                char phraseChar = phraseArray[y];

                int wordCharInt   = wordChar - 65;
                int phraseCharInt = phraseChar - 65;

                char decode = Grid[wordCharInt][phraseCharInt];

                //Adds character to phrase
                decodedPhrase += ($"{decode}");


                //Repeats code word through encrypted phrase
                x++;
                y++;
                if (x == wordInt)
                {
                    x = 0;
                }
            }

            //Returns encrypted phrase with program code word decrypted
            return(decodedPhrase);
        }