import
java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import
java.io.InputStreamReader;
import java.io.PrintWriter;
import
java.net.InetAddress;
import
java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
public class RSA{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
RSA r=new RSA();
System.out.println("Enter value for p");
int p=s.nextInt();
System.out.println("Enter value for q");
int q=s.nextInt();
int n=(p*q);
int fai=((p-1)*(q=1));
System.out.println("Enter
value for e");
int e=s.nextInt();
while(true) {
if(GCD(fai,e)!=1) {
System.out.println("Enter value for
e");
e=s.nextInt();
}
else
break;
}
int d=FindD(e,fai);
System.out.println("Enter value for d="+d);
System.out.println("Enter Message");
int m=s.nextInt();
int c=(int)(Math.pow(m,e)%n);
System.out.println("Enter value for c="+c);
int x=(int)(Math.pow(c,d)%n);
System.out.println("Message at
decription="+x);
if(x==m) {
System.out.println("Matched");
}
else {
System.out.println("not Matched");
}
}
static int FindD(int E,int Fai) {
int s;
for(int i=0;i<Fai;i++) {
s=(i*E)%Fai;
if(s==1) {
return i;
}
}
return 0;
}
static int GCD(int FAI,int EEE) {
if(EEE==0) {
return FAI;
}
return GCD(EEE,FAI%EEE);
}
}
Comments
Post a Comment