-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjava1
More file actions
50 lines (48 loc) · 1.2 KB
/
Copy pathjava1
File metadata and controls
50 lines (48 loc) · 1.2 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
import java.util.*;
import java.io.*;
class ras
{
static int mult(int x,int y,int n)
{
int k = 1;
int j;
for(int j = 0;j<y;j++)
k = (k*x)%n;
return (int)k;
}
public static void main(String args[])throws Exception
{
Scanner s = new Scanner(System.in);
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
String msg1;
int pt[]=new int[100];
int ct[] = new int[100];
int a,b,n,d,e,p,q,i,z;
System.out.println("enter the 2 prime number p and q");
p = s.nextInt();
q = s.nextInt();
n = p*q;
z= (p-1)*(q-1);
System.out.println("enter the value of e");
e = s.nextInt();
System.out.println("enter the message");
msg1= br.readLine();
char msg[] = msg1.toCharArray();
for(int i=0;i<msg.length;i++)
pt[i]= msg[i];
for(d=1;d<msg.length;++d)
if(((e*d)%z)==1)break;
System.out.println("p="+p+"\tq="+q+"\tn="+n+"\tz="+z+"\te="+e+"\td="+d);
System.out,println("cipher text is");
for(int i=0;i<msg.length;i++)
ct[i]=mult(pt[i],e,n);
for(int i=0;i<msg.length;i++)
System.out.println(ct[i]);
System.out,println("plaint text is");
for(int i=0;i<msg.length;i++)
pt[i]=mult(ct[i],e,n);
for(int i=0;i<msg.length;i++)
System.out.println((char)pt[i]);
}
}