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); }
} //Секретный ключ 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); }
} //Закрытый ключ 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); //Зашифрованное сообщение }
public static string StickedBinaryMsg(string msg) { StringBuilder stickedBinaryMsg = new StringBuilder(); foreach (char ch in msg) { stickedBinaryMsg.Append(ConverToBase2(Alphabet.GetCharCode(ch))); } return(stickedBinaryMsg.ToString()); }
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); }
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); }
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); //Хеш }