Sie sind auf Seite 1von 6

EXPERIMENT NO: 02

Name:Kunda Najan.

TITLE: RSA ALGORITHM

Class:BE/B1

AIM: To write a program for RSA algorithm

Roll No.:02

Objective:

Encryption and Decryption of data


To provide security

Scope:

The RSA algorithm is used worldwide to secure Internet, banking and credit card

transactions.
The cryptographic telephone applications developed by Kryptotel use this algorithm
together with the AES to enable the encryption on the Iphone

Theory:
Introduction:
RSA is one of the first practical public-key cryptosystems and is widely used for secure data
transmission. In such cryptosystem, the encryption key is public and differs from the decryption
key which is kept secret. In RSA, this asymmetry is based on the practical difficulty
of factoring the product of two large prime numbers, the factoring problem. RSA is made of the
initial letters of the surnames of Ron Rivest, Adi Shamir, and Leonard Adleman, who first
publicly described the algorithm in 1977
A user of RSA creates and then publishes a public key based on two large prime numbers, along
with an auxiliary value. The prime numbers must be kept secret. Anyone can use the public key
to encrypt a message, but with currently published methods, if the public key is large enough,
only someone with knowledge of the prime numbers can feasibly decode the message. Breaking
RSA encryption is known as the RSA problem; whether it is as hard as the factoring problem
remains an open question.

STEPS:
The RSA algorithm involves three steps: key generation, encryption and decryption.
RSA involves a public key and a private key. The public key can be known by everyone and is
used for encrypting messages. Messages encrypted with the public key can only be decrypted in
a reasonable amount of time using the private key. The keys for the RSA algorithm are generated
the following way
1.
2.
3.
4.

Choose two large prime numbers P and Q.


Calculate N=P*Q ; N is in bits and is the key length
Select Public key (Encryption key) E such that it is not a factor of (P-1)(Q-1).
Select Private key (Decryption key) D such that:
(D*E) mod (P-1)(Q-1)=1

5. For encryption calculate the cipher text CT from the plain text PT.
E
CT= PT mod N

6. Send CT as a cipher text to the receiver


E
7. For Decryption PT= CT mod N

Example:

Choose P= 7and Q = 17,PT=10


Compute N=P*Q = 7*17 = 119
Choose E ; (P - 1) * (Q - 1) = (7-1)*(17-1) = 96
E=5 . (E should not be factor of (P-1)*(Q-1))
Compute a value for D such that
(D*E) mod (P-1)(Q-1)=1
(D*5) mod96=1
D=77
. (By trial and error)
5
CT= 10 mod 119

CT=40

.... (By Calculating)

77

And PT= 40

mod 119

PT=10
Attacks
There are a number of attacks against plain RSA as described below.

When encrypting with low encryption exponents and small values of the keys. In this
case, cipher texts can be easily decrypted the cipher text over the integers.

If the same clear text message is sent to recipients in an encrypted way, and the receivers
share the same exponent, but different P, Q, and then it is easy to decrypt the original
clear text message via the Chinese remainder theorem. Johan Hstad noticed that this
attack is possible even if the clear texts are not equal, but the attacker knows a linear
relation between them. This attack was later improved by Don Coppersmith.

Because RSA encryption is a deterministic encryption algorithm an attacker can


successfully launch a attack against the cryptosystem, by encrypting likely plaintexts
under the public key and test if they are equal to the cipher text.

RSA has the property that the product of two cipher texts is equal to the encryption of the
product of the respective plaintexts. Because of this multiplicative property a chosencipher text attack is possible.

Program:
#include< stdio.h>
#include< conio.h>
int phi,M,n,e,d,C,FLAG;
int check()
{

int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG = 1;
return;
}
FLAG = 0;
}
void encrypt()
{
int i;
C = 1;
for(i=0;i< e;i++)
C=C*M%n;
C = C%n;
printf("\n\tEncrypted keyword : %d",C);
}
void decrypt()
{
int i;
M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
printf("\n\tDecrypted keyword : %d",M);
}

void main()
{

int p,q,s;
clrscr();
printf("Enter Two Relatively Prime Numbers\t: ");
scanf("%d%d",&p,&q);
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do
{
printf("\n\nEnter e\t: ");
scanf("%d",&e);
check();
}while(FLAG==1);
d = 1;
do
{

s = (d*e)%phi;
d++;

}while(s!=1);
d = d-1;
printf("\n\tPublic Key\t: {%d,%d}",e,n);
printf("\n\tPrivate Key\t: {%d,%d}",d,n);
printf("\n\nEnter The Plain Text\t: ");
scanf("%d",&M);
encrypt();

printf("\n\nEnter the Cipher text\t: ");


scanf("%d",&C);
decrypt();
getch();
}
Output:

Conclusion: Thus we have studies program for RSA algorithm.