public void Interact() { Console.WriteLine("Hi! I'm Alice."); while (true) { Console.WriteLine("\nWhat do you want me to do?\n"); Console.WriteLine("1. Generate private key and publish public key, then decipher a message."); Console.WriteLine("2. Get public key and encrypt a message."); Console.WriteLine("3. Generate private key and publish public key, then sign a message."); Console.WriteLine("4. Get message and public key, then verify the signature."); Console.WriteLine("0. Exit.\n"); Console.Write("Your choice is: "); string choice = Console.ReadLine(); while (choice.Length != 1) { Console.WriteLine("Wrong choice! Try again:"); choice = Console.ReadLine(); } switch (choice) { case "1": this.GenKeys(); Console.WriteLine("\n\n p = " + this.pqb[0].ToString("X") + "\n\n q = " + this.pqb[1].ToString("X")); Console.WriteLine("n = {0}", this.n.ToString("X")); Console.WriteLine("b = {0}", this.pqb[2].ToString("X")); Console.WriteLine(); this.CT = new BigInteger[3]; Console.WriteLine("Ciphertext: "); this.CT[0] = BigInteger.Parse("0" + Program.ReadLine(), NumberStyles.HexNumber); Console.WriteLine("Parity: "); this.CT[1] = BigInteger.Parse(Console.ReadLine()); Console.WriteLine("Jacobi Symbol: "); this.CT[2] = BigInteger.Parse(Console.ReadLine()); this.message = RabinSystem.Decrypt(this.CT, this.pqb); Console.WriteLine("\nMessage is: {0}", this.message); break; case "2": Console.WriteLine("n = "); this.n = BigInteger.Parse("0" + Program.ReadLine(), NumberStyles.HexNumber); Console.WriteLine("b = "); this.b = BigInteger.Parse("0" + Program.ReadLine(), NumberStyles.HexNumber); this.CT = RabinSystem.Encrypt("Yare, yare daze", this.n, this.b); Console.WriteLine("Encrypted message is: {0}\nRarity is: {1}\nJacobi Symbol is:{2}", this.CT[0].ToString("X"), this.CT[1], this.CT[2]); break; case "3": this.GenKeys(); Console.Write("\nSigned message is: "); string message = Console.ReadLine(); BigInteger[] sign = RabinSystem.Signature(message, this.pqb); Console.WriteLine("\nSign is: {0}\n\nModulo is: {1}", sign[0].ToString("X"), sign[1].ToString("X")); break; case "4": Console.Write("\nMessage to verify is: "); string signedmessage = Console.ReadLine(); Console.Write("\nIts signarute: "); string signarute = Program.ReadLine(); Console.Write("\nIts modulo: "); string n = Program.ReadLine(); Console.WriteLine("\nSignature is: " + RabinSystem.Verify(signedmessage, signarute, n)); break; case "0": return; } } }
public void SendMessageTo(Users user, string message) { user.SendPublicKeyTo(this); user.CT = RabinSystem.Encrypt(message, this.n, this.b); }