Caser Rsa
Caser Rsa
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class encr //ceaser encryption
{
public string x, yy;
public int z, m, ii = 0;
char[] yyy = new char[25];
Console.WriteLine("enter plaintext");
x = Console.ReadLine();
Console.WriteLine("ciphertext of caser is");
foreach (char c in x)
{
if (c == 32) { Console.Write("1"); }
else if (c == 90 || c == 122)
{
z = (m + c) - 26;
yy = (Convert.ToChar(z)).ToString();
Console.Write(yy);
yyy[ii] = Convert.ToChar(yy); ii++;
}
else
{
z = m + c;
if (z > 122) { z = z - 26; }
yy = (Convert.ToChar(z)).ToString();
Console.Write(yy);
yyy[ii] = Convert.ToChar(yy); ii++;
}
}
Console.WriteLine("\n");
//enc rsa
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;* */
Console.WriteLine("d=");
Console.WriteLine(d);
i = 0;
/// <summary>
/// ////////
/// </summary>
//dec rsa
k = 0;
//dec caser
Console.WriteLine("plaintext of caser is");
foreach (char c in plain2)
{
int dd = c + 97;
if (dd == 49) { Console.Write(" "); }
else if (dd == 65 || dd == 97)
{
z = (dd - m) + 26;
string y = (Convert.ToChar(z)).ToString();
Console.Write(y);
}
else
{
z = dd - m;
if (z < 97) { z = z + 26; }
string y = (Convert.ToChar(z)).ToString();
Console.Write(y);
}
}
Console.WriteLine("\n");
/// <summary>
/// ////////
/// </summary>
}
}
class Program
{
static void Main(string[] args)
{
encr t = new encr();
t.en();
}
}
}