-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecrypt.java
96 lines (88 loc) · 1.4 KB
/
Decrypt.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Scanner;
import java.math.*;
class pair1
{
int n;
int e;
}
class base1
{
private int a=59;
private int b=53;
pair1 getPublicKey()
{
pair1 p=new pair1();
p.n=a*b;
p.e=3;
return p;
}
int getPrivateKey()
{
return (a*b-a-b+1);
}
}
class privatekey1
{
base1 b;
pair1 p;
int phi;
int k;
int d;
privatekey1()
{
b=new base1();
p=b.getPublicKey();
phi=b.getPrivateKey();
k=2;
d=(k*phi + 1)/p.e;
}
}
class Decryption
{
int decr(int a)
{
base1 b=new base1();
pair1 p=new pair1();
p=b.getPublicKey();
privatekey1 d=new privatekey1();
//System.out.println(a);
BigInteger bi1,bi2,bi3,exp;
bi1=new BigInteger(Integer.toString(a));
bi2=new BigInteger(Integer.toString(p.n));
exp=new BigInteger(Integer.toString(d.d));
bi3=bi1.modPow(exp, bi2);
return bi3.intValue();
}
int[] dec(int[] a,int n)
{
for(int i=0;i<n;i++)
{
a[i]=decr(a[i]);
//System.out.print(a[i]+" ");
}
return a;
}
}
public class Decrypt
{
public static void main(String []deep)
{
Scanner sc=new Scanner(System.in);
int []b=new int[10000];
int ii=0,flag=-1;
while(flag==-1)
{
b[ii]=sc.nextInt();
//System.out.print(b[ii]+" ");
if(b[ii]==-1)
flag=0;
ii++;
//System.out.print("a");
}
ii--;
Decryption d=new Decryption();
int []done=d.dec(b,ii);
for(int i=0;i<ii;i++)
System.out.print((char)(done[i]));
}
}