static void Main(string[] args) { Console.WriteLine("Введите стороку для зашифрования"); var str = Console.ReadLine(); Console.WriteLine("El-Gamal"); var elgamalCrypted = ElGamal.EnCrypt(str); Console.WriteLine("Зашифрованная строка = " + elgamalCrypted); var elgamalDecrypted = ElGamal.DeCrypt(elgamalCrypted); Console.WriteLine("decrypted = " + elgamalDecrypted); Console.ReadLine(); }
/// <summary> /// Криптоанализ /// </summary> /// <param name="ciphermesage">Зашифрованное сообщение</param> /// <param name="p">Модуль</param> /// <param name="g">Генератор группы по модулю</param> /// <returns></returns> public static string GetPlainFromCipher(List <decimal[]> ciphermesage, decimal p, decimal g, decimal OpenKey) { string plain = ""; byte n; decimal k; for (int i = 0; i < ciphermesage.Count; i++) { k = ElGamal.MatchingAlgorithm(g, ciphermesage[i][0], p); n = (byte)((ElGamal.PowMod(ElGamal.EuclideanAlgorithm(p, OpenKey), k, p) * ciphermesage[i][1]) % p); Console.WriteLine($"{ciphermesage[i][0]} = {g}^k mod {p}\nk = {k}"); Console.WriteLine($"M = {n} = (({OpenKey})^-1)^{k} * {ciphermesage[i][1]} mod {p}"); plain += Encoding.ASCII.GetChars(new byte[] { n })[0]; } return(plain); }
static void Main(string[] args) { ElGamal q = new ElGamal(20996023); Console.WriteLine($"P: {q.P}\ng: {q.g}\nOpen: {q.KOpen}"); string message = "Test ElGamal"; Console.WriteLine("Input text: " + message); List <decimal[]> text = q.Encrypting(message); Console.WriteLine("Encrypted:"); Console.WriteLine(String.Join(" ", text)); Console.WriteLine("Decrypted..." + ElGamal.GetPlainFromCipher(text, q.P, q.g, q.KOpen)); Console.WriteLine("Decrypted:"); Console.WriteLine(q.Decrypting(text)); Console.ReadKey(); }
static void Main(string[] args) { // ElGamal q = new ElGamal(2147483647);//(20996023);//(7687); ElGamal q = new ElGamal(20996023); Console.WriteLine($"P: {q.P}\ng: {q.g}\nOpen: {q.KOpen}");//Close: {q.KClose}\n string message = "Valentina Maslennikova"; Console.WriteLine("Input text: " + message); List <decimal[]> text = q.Encrypting(message); Console.WriteLine("Encrypted..."); for (int i = 0; i < text.Count; i++) { Console.Write("{" + text[i][0] + ", " + text[i][1] + "}, "); } Console.WriteLine("\nCryptoanalisis..."); Console.WriteLine("Decrypted..." + ElGamal.GetPlainFromCipher(text, q.P, q.g, q.KOpen)); Console.WriteLine("Decrypted with key..."); Console.WriteLine(q.Decrypting(text)); }