Using Using Using Using Namespace Class: "Enter P" "P " "Enter Q" "Q "
Using Using Using Using Namespace Class: "Enter P" "P " "Enter Q" "Q "
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RSA
{
class rsa
{
//p=11 q=3
public double d=1, p, q, n, phi, e = 3;
public int i = 0,k=0;
public string plain;
double [] plain1 = new double[25];
Console.WriteLine("enter p");
p = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("p=");
Console.WriteLine(p);
Console.WriteLine("enter q");
q = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("q=");
Console.WriteLine(q);
n = p * q;
Console.WriteLine("n=p*q");
Console.WriteLine(n);
phi = (p - 1) * (q - 1);
Console.WriteLine("phi=(p-1)*(q-1)");
Console.WriteLine(phi);
Console.WriteLine("e=");
Console.WriteLine(e);
/*
d = (Math.Pow(e, -1)) % phi;* */
while (((d * e) % n) != 1)
{
d++;
Console.WriteLine("d=");
Console.WriteLine(d);
}
int g = 0;
while (g != 1)
{
i = 0;
Console.WriteLine("enter plaintext");
plain = Console.ReadLine();
foreach (char c in plain)
{
plain1[i] = (c - 97);
i++;
}
double[] cipher1 = new double[i];
int g = 0;
while (g != 1)
{
k = 0;
string cipher;
Console.WriteLine("enter ciphertext");
cipher = Console.ReadLine();
foreach (char c in cipher)
{
cipher2[k] = (c - 97);
k++;
}
double[] plain2 = new double[k];
for (int j = 0; j < k; j++)
{
plain2[j] = (Math.Pow(cipher2[j], d)) % n;
Console.Write(Convert.ToChar(Convert.ToInt16(plain2[j] + 97)));
} Console.WriteLine();
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1=encryption");
Console.WriteLine("2=decryption");
int s;
s =Convert .ToInt16 ( Console.ReadLine());
}
}
}