-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
40 lines (38 loc) · 1.35 KB
/
Main.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
import java.math.BigInteger;
public class Main {
/* public static BigInteger binPow(BigInteger a, BigInteger b, BigInteger m) {
a %= m;
if (b == 0) return 1;
else if (b % 2 == 0) {
return binPow((a.multiply(a)).remainder(m), b.divide(BigInteger.valueOf(2)), m);
}
else return (a.multiply( binPow(a, b.subtract(BigInteger.valueOf(1)), m))).remainder( m);
}
*/
public static void main(String[] args) {
BigInteger N=BigInteger.valueOf(2048);
String text="Text";
BigInteger q=Utils.getPrime(1024);
BigInteger p=Utils.getPrime(1024);
BigInteger n=q.multiply(p);
BigInteger fi=q.subtract(BigInteger.valueOf(1)).multiply(p.subtract(BigInteger.valueOf(1)));
BigInteger e=BigInteger.valueOf(65537);
BigInteger d;
BigInteger k=BigInteger.valueOf(2);
for(;;) {
if(k.multiply(fi).add(BigInteger.valueOf(1)).remainder(e).equals(BigInteger.valueOf(0))){
d=k.multiply(fi).add(BigInteger.valueOf(1)).divide(e);
break;
}
else {
k=k.add(BigInteger.valueOf(1));
}
}
BigInteger bits =new BigInteger(text.getBytes());
System.out.println(bits.toString());
bits=bits.modPow(e, n);
System.out.println(bits.toString());
bits=bits.modPow(d, n);
System.out.println(bits.toString());
}
}