-
Notifications
You must be signed in to change notification settings - Fork 1
/
RSA.java
45 lines (32 loc) · 816 Bytes
/
RSA.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//package netsec;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.math.BigInteger;
/**
*
* @author APARNA
*/
public class RSA {
private BigInteger n,d,e;
public RSA(BigInteger p,BigInteger q, BigInteger e)
{
this.e=e;
n=p.multiply(q);
BigInteger phi= (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
d = e.modInverse(phi);
}
public BigInteger rsaEncrypt(BigInteger message)
{
return message.modPow(e, n);
}
public BigInteger rsaEncrypt(BigInteger message,BigInteger e,BigInteger n)
{
return message.modPow(e, n);
}
public BigInteger rsaDecrypt(BigInteger c)
{
return c.modPow(d, n);
}
}