Exemplo n.º 1
0
        public string Encode(string text)
        {
            string encryptedText = "";
            string upperText     = text.ToUpper();
            int    code;

            for (int i = 0; i < text.Length; i++)
            {
                switch (TextCheck.WhatLanguage(text[i]))
                {
                case (int)Languages.Russian:
                    code           = GetRightCodeToEncrypt(upperText[i], 'А', 'Я');
                    encryptedText += TextCheck.ProperCaseChar(text, i, code);
                    break;

                case (int)Languages.English:
                    code           = GetRightCodeToEncrypt(upperText[i], 'A', 'Z');
                    encryptedText += TextCheck.ProperCaseChar(text, i, code);
                    break;

                case (int)Languages.Unknown:
                    encryptedText += text[i];
                    break;

                default:
                    break;
                }
            }

            Console.WriteLine(Menu.NL + " Your text:" + Menu.NL + text);
            Console.WriteLine(Menu.NL + " Encrypted text:" + Menu.NL + encryptedText);

            return(encryptedText);
        }
Exemplo n.º 2
0
        public string Decode(string text)
        {
            string decryptedText = "";
            string upperText     = text.ToUpper();
            int    code;

            for (int i = 0; i < text.Length; i++)
            {
                switch (TextCheck.WhatLanguage(text[i]))
                {
                case (int)Languages.Russian:
                    code           = (int)'Я' - ((int)Languages.RusAlphabetLength - 1) - upperText[i] + (int)'Я';
                    decryptedText += TextCheck.ProperCaseChar(text, i, code);
                    break;

                case (int)Languages.English:
                    code           = (int)'Z' - ((int)Languages.EngAlphabetLength - 1) - upperText[i] + (int)'Z';
                    decryptedText += TextCheck.ProperCaseChar(text, i, code);
                    break;

                case (int)Languages.Unknown:
                    decryptedText += text[i];
                    break;

                default:
                    break;
                }
            }


            Console.WriteLine(Menu.NL + " Your text:" + Menu.NL + text);
            Console.WriteLine(Menu.NL + " Decrypted text:" + Menu.NL + decryptedText);

            return(decryptedText);
        }