public string Encryption(string text) { PublicKey = MakePublicKey(); string EncryptedText = String.Empty; foreach (char Char in text) { ModCalculator Calculation = new ModCalculator(Char, PublicKey[0], PublicKey[1]); EncryptedText += Calculation.GetRemainder().ToString() + ","; } return EncryptedText; }
public string Decryption(string Text) { List<long> Publickey = GetPublicKey(); List<long> PrivateKey = MakePrivateKey(Publickey); string DecryptedText = String.Empty; List<string> IntegersInText = Text.Split(',').ToList(); IntegersInText.RemoveAt(IntegersInText.Count - 1); List<long> Chars = new List<long>(); foreach (string Integer in IntegersInText) Chars.Add(Convert.ToInt64(Integer)); foreach (long Char in Chars) { ModCalculator Calculation = new ModCalculator(Char, PrivateKey[0], PrivateKey[1]); DecryptedText += Convert.ToChar(Convert.ToInt64(Calculation.GetRemainder()));//.ToString(); } return DecryptedText; }
public static void ModCalc() { Console.Write("Enter expression. \n Base: "); Int32 Base = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\n Degre: "); Int32 Degree = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\n Divider: "); Int32 Divider = Convert.ToInt32(Console.ReadLine()); ModCalculator Exp = new ModCalculator(Base, Degree, Divider); Console.WriteLine("\n Remainder: " + Exp.GetRemainder()); Console.ReadKey(); }