Professional Documents
Culture Documents
DKFJD
DKFJD
-04
Timely Total
Understanding
Submission Pyochialrtty (15)
Practical
e223
Incharge
EXPERIMENT NO-04
Aim: Developa program to implementRSA algorithm for encryption and decryption. This
is one the initial system. It remains most employed cryptosystem
cryptosystem
even today. The system was invented by three scholars Ron Rivest, Adi Shamir,
and Len Adleman and hence, it is termed as RSA cryptosystem. The two aspects
of the RSA cryptosystem, firstly generation of key pair and secondly encryption-
decryption algorithms
Theory:
key.
though n is part of
the public key, difficulty in
Interestingly,
ofRSA.
is unique number d.
Number d is the inverse of emodulo (p - 1)(q- 1). This means that
disthenumber less than (p- 1q- 1) such that when multiplied by
e, it is equal to I modulo (p -
1q
-
1).
as follows ed
This relationship-is written mathematically
=1 mod (p - 1)(q 1)
output.
ALGORITHM:
1. Key Generation
iv. Choose an e such that < e < o(n), and such that
1 eand
other than (e and p(n) are
o(n) share no divisors
1
key exponent
the
v. Determine d (using modular arithmetic) which satisfies
relation
congruence
de 1 (mod r(n)).
encryption) exponent
e. The private key has modulusn and the private (or
2. Encryption
c m°(mod n).
3. Decryption:
m = c° (mod n).
4. Stop.
PROGRAM:
import java.io.*;
import java.math.*;
import java.util.*
public class
RSA
double h)
public static double gcd(double a,
double temp;
while (true){
temp a %h;
=
if(temp=0)
return h;
a=h;
h= temp;
Console c =System.console);
try
the number P: ");
double p =Double.parseDouble(c.readLine("Enter the number Q: ")):
double q =Double.parseDouble(c.readLine("Enter
double n
double
p *9%
e= *
doublephi (p- 1) (q- 1); =
while (e< phi) {
if(gcd(e, phi)== 1)
break;
else
et+
int
k =2;
double d=(1 +(k phi))/e;
= * the Message: ");
double msg Double.parseDouble(c.readLine("Enter
"
** ****** ******* ********** ");
System.out.println("..
data =
**********************
+ msg);
System.out.println("Message
double ca =
Math.pow(msg, e);
ca ca % n; = ="+
data ca);
=
System.out.println("Encrypted
double m
m =m % n
Math.pow(ca, d)
="+ m);
Sent
System.out.println("Original Message
}catch(NumberFormatException e){
Numbers Allowed");;
System.out.println("Only
OUTPUT:
UPTER
PROBLEMS 10 OUTPUT DEBUC CONSOLETERMNAL
RuntRailFe
Windaws PowerShell
All rights reserved.
Rur RSA
PoerShell https://aka.ns/pscores
Try the new cross-platfor
iisInëxCepticniessagescp C:sers
PS C:Project \CSS> & 'C:Progran Files Javal jdk-18.8.2\binijava.ere-0K:+Shoutodebeta
ysiCSs_ bbabbc15\bin
Vinayak v Utekar\AppDatatRoaming\Code\Usertuorkspacesturagel15%c2e5edado62971fdëb6ebe189a72e\redhat.java\jot
FSA
Enter the nunber P
:7
Enter the number Q:
Enter tne iessa *****************°****
12.08
essage data
Encrypted data 3.8
=
12.0
Original Message Sent
PS C:\Project\cSs>
In 46.Col2A1RA
VTnayak V. Ukkor OATE
Ta-BLormps41
Pan
QWhat s RSA3
AThe RSA Algtt n aymnet tPtngnphy algarthm thsg.
Onyon&
Th The
ofHom The
ae enevgh numberS hat_ReA users
pne Number beytm Sntes
n4er
he nmbe
l
at
o_ptmesss bhan o egal on
is a asynp tvbaly n.
Thes hat the nmbey
eanf a prm nmbea ef ergth 512
bRSoX ssS
hon he nmbe
lo
So
of atoms tn
h s
h
o nmber 9eat
9Pen hiese
A at Koy
Ser
Tt arned
Pblrc y- thae
as Ha
) AeHred as ha kdntue
hat vses
bo drtleent Key
atuseS Stngle a
shotd Koy
encpt docayt k er
enyptran kdocayptvon
messoe
Kehoiga
tbt mesoge
omont
v)Apot hom Snds etves |* 1 h to use
prote ay fs kpt
Secet k
not pblfc
DRTE
AJRSA
both
an amtsc
&pat key
algorfhm h£r
A doneS
ens vjes
tt ves
geiteA_pslkc
both pule) Pc