Exemplo n.º 1
0
        public int Hash() //Нахождение хеш-образа
        {
            hash = h0;

            foreach (var ch in message.Substring(0))
            {
                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($"Недопустимый символ!");
                }

                hash = f(hash, charIndex);
                Console.WriteLine(hash);
            }

            return(hash);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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($"Индекс выходит за границы");
                }
                var res = BigInteger.ModPow(charIndex, e, n);
                enMsg += res + " ";
            }
            return(enMsg); //Зашифрованное сообщение
        }
Exemplo n.º 4
0
        public static string StickedBinaryMsg(string msg)
        {
            StringBuilder stickedBinaryMsg = new StringBuilder();

            foreach (char ch in msg)
            {
                stickedBinaryMsg.Append(ConverToBase2(Alphabet.GetCharCode(ch)));
            }
            return(stickedBinaryMsg.ToString());
        }
Exemplo n.º 5
0
        public int Hash()
        {
            hash = f(h0, Alphabet.GetCharCode(message[0]));

            foreach (var ch in message.Substring(1))
            {
                hash = f(hash, Alphabet.GetCharCode(ch));
            }

            return(hash);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public int Hash() //Функция нахождения хеш-образа
        {
            hash = h0;

            foreach (var ch in mes.Substring(0))
            {
                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($"Недопустимое значение!");
                }
                hash = func(hash, charIndex);
                Console.WriteLine(hash);
            }
            return(hash); //Хеш
        }