18 February 2017

// // Leave a Comment

Program in C language for RSA Algorithm


RSA stands for Rivest-Shamir-Adlemen. RSA is one of the first practical public-key cryptosystems and is widely used for secure data transmission. Let's take a look at its definition.

What is RSA Algorithm?

RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is an asymmetric cryptographic algorithm. Asymmetric means that there are two different keys. This is also called public key cryptography, because one of them can be given to everyone. The other key must be kept private.

Program demostrating the implementation of RSA Algorithm

Hello guys! Below is a program in C programming language which shows how to implement RSA algorithm.

#include 

int ex_gcd(int a,int b,int n) //computes the GCD using the Extended Euclid method
{
int x=0,y=1,lastx=1,lasty=0;
int temp,q;
while(b!=0)
{
temp =b;
q = a/b;
b = a%b;
a = temp;

temp=x;
x = lastx - q*x;
lastx = temp;

temp =y;
y = lasty - q*y;
lasty = temp;
}
if(n==1) return a;
else return lasty;
}

long en_de(int base, int exp,int n)
{
int b[30],i,c=0;
long d=1;
for(i=0;exp!=0;exp/=2,i++)
b[i]=exp%2;

i--;
for(;i>=0;i--)
{
c = 2*c;
d = (d*d) %n;
if(b[i]==1)
{
c = c+1;
d = (d*base)%n;
}
}
return d;
}

void main()
{

int p,q,i;
int pt,ct;
int e,d,et,n,temp;

printf("Enter prime No.s p,q :");
scanf("%d %d",&p,&q);

n = p*q;
et=(p-1)*(q-1);

for(i=2;i

Share:

0 comments:

Post a Comment