0% found this document useful (0 votes)
14 views

Caser Rsa

The document describes an encryption program that implements Caesar and RSA encryption and decryption. It takes in plaintext, applies Caesar encryption, then RSA encryption and prints the ciphertexts. It also decrypts by first applying RSA decryption and then Caesar decryption to recover the original plaintext.

Uploaded by

Mohamd barca
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Caser Rsa

The document describes an encryption program that implements Caesar and RSA encryption and decryption. It takes in plaintext, applies Caesar encryption, then RSA encryption and prints the ciphertexts. It also decrypts by first applying RSA decryption and then Caesar decryption to recover the original plaintext.

Uploaded by

Mohamd barca
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

using System;

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];

public double d = 7, p, q, n, phi, e = 3;


public int i = 0, k = 0;

public void en()


{
Console.WriteLine("enter the key");
m = Convert.ToInt16(Console.ReadLine());

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

double[] plain1 = new double[25];

int[] cipher2 = new int[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;* */
Console.WriteLine("d=");
Console.WriteLine(d);

i = 0;

foreach (char c in yyy)


{
plain1[i] = (c - 97);
i++;
}
double[] cipher1 = new double[i];

Console.WriteLine("ciphertext of rsa is");


for (int j = 0; j < i; j++)
{
cipher1[j] = (Math.Pow(plain1[j], e)) % n;
Console.Write(Convert.ToChar(Convert.ToInt16(cipher1[j] + 97)));
} Console.WriteLine();

/// <summary>
/// ////////
/// </summary>
//dec rsa

k = 0;

foreach (char c in cipher1)


{
cipher2[k] = (c);
k++;
}
double[] plain2 = new double[k];
Console.WriteLine("plaintext of rsa is");
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();

//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();

}
}
}

You might also like