NS9_userB.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.*;
  4. public class NS9_userB{
  5. public static int find_pow(int a, int b,int c) {
  6. int i,final_ans=1;
  7. for(i=0;i<b;i++)
  8. final_ans=(final_ans*(a%c))%c;
  9. return final_ans%c;
  10. }
  11. public static void main(String[] args) throws IOException {
  12. Scanner sc = new Scanner(System.in);
  13. System.out.println("Enter value of P");
  14. int P = sc.nextInt();
  15. System.out.println("Enter value of a");
  16. int a = sc.nextInt();
  17. System.out.println("Enter value of Xb");
  18. int Xb = sc.nextInt();
  19. int Yb;
  20. Yb=find_pow(a,Xb,P);
  21. Socket s = null;
  22. s = new Socket("127.0.0.1",7777);
  23. DataOutputStream dos = new DataOutputStream(s.getOutputStream());
  24. DataInputStream dis = new DataInputStream(s.getInputStream());
  25. String Ya = dis.readUTF();
  26. dos.writeUTF(Integer.toString(Yb));
  27. int k;
  28. k=find_pow(Integer.parseInt(Ya),Xb,P);
  29. System.out.println("Key is "+k);
  30. }
  31. }