-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptor.java
More file actions
71 lines (65 loc) · 1.08 KB
/
Encryptor.java
File metadata and controls
71 lines (65 loc) · 1.08 KB
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
import java.util.*;
class pair
{
int n;
int e;
}
class base
{
private int a=59;
private int b=53;
pair getPublicKey()
{
pair p=new pair();
p.n=a*b;
p.e=3;
return p;
}
int getPrivateKey()
{
return a*b-a-b+1;
}
}
class privatekey
{
base b=new base();
pair p=b.getPublicKey();
int phi=b.getPrivateKey();
int k=2;
int d=(k*phi + 1)/p.e;
}
class Encrypt
{
public int encr(int a)
{
base b=new base();
pair p=new pair();
p=b.getPublicKey();
return (((int)Math.pow((double)a,(double)p.e)) % p.n);
}
public int[] enc(int []a)
{
for(int i=0;i<a.length;i++)
a[i]=encr(a[i]);
return a;
}
}
public class Encryptor
{
public static void main(String[] uday)
{
Scanner sc=new Scanner(System.in);
String message=sc.nextLine();
char a[]=message.toCharArray();
int []b=new int[message.length()+1];
for(int i=0;i<message.length();i++)
{
b[i]=(int)a[i];
// System.out.print(b[i]+" ");
}
Encrypt e=new Encrypt();
int []encrypted=e.enc(b);
for(int i=0;i<message.length();i++)
System.out.print(encrypted[i]+" ");
}
}