Example #1
0
        }                       //Секретный ключ

        public string Encrypt() //Шифрование
        {
            foreach (var ch in message)
            {
                int charIndex;
                if (Alphabet.GetCharCode(ch) >= 192 && Alphabet.GetCharCode(ch) <= 223)
                {
                    charIndex = Alphabet.GetCharCode(ch) - 191;
                }
                else if (Alphabet.GetCharCode(ch) >= 224 && Alphabet.GetCharCode(ch) <= 255)
                {
                    charIndex = Alphabet.GetCharCode(ch) - 223;
                }
                else
                {
                    throw new Exception($"Неверный символ!");
                }



                maxCharCode = charIndex > maxCharCode ? charIndex : maxCharCode;
                if (maxCharCode >= n)
                {
                    throw new Exception($"Индекс символа {Alphabet.GetChar(maxCharCode)} = {maxCharCode} больше или равно n = {n}");
                }

                var res = BigInteger.ModPow(charIndex, e, n);
                encryptedMessage += res + " ";
            }

            return(encryptedMessage);
        }
Example #2
0
 public string Decrypt() //Дешифрование
 {
     foreach (var ch in enMsg.Trim().Split(' '))
     {
         var res = BigInteger.ModPow(int.Parse(ch), d, n);
         deMsg += Alphabet.GetChar(((int)res + n) % n + 191);
     }
     return(deMsg); //Расшиврованное сообщение
 }
Example #3
0
        public string Decrypt() //Расшифрование
        {
            foreach (var ch in encryptedMessage.Trim().Split(' '))
            {
                var res = BigInteger.ModPow(int.Parse(ch), d, n);
                decryptedMessage += Alphabet.GetChar(((int)res + n) % n + 191);
            }

            return(decryptedMessage);
        }
Example #4
0
        public string Encrypt()
        {
            foreach (var ch in message)
            {
                int charIndex = Alphabet.GetCharCode(ch);

                maxCharCode = charIndex > maxCharCode ? charIndex : maxCharCode;
                if (maxCharCode >= n)
                {
                    throw new Exception($"Индекс буквы {Alphabet.GetChar(maxCharCode)} = {maxCharCode} больше/равно n = {n}");
                }

                var res = BigInteger.ModPow(charIndex, e, n);
                encryptedMessage += res + " ";
            }

            return(encryptedMessage);
        }