1234567891011121314151617181920212223242526272829303132 |
- import java.io.*;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.Scanner;
- public class Server_Diffie_Hellman {
- public static void main(String[] args) throws IOException
- {
- long alpha=7,P=11,K,Xb=23,Ya,Yb;
- ServerSocket servsocket = new ServerSocket(4500);
- System.out.println("Server is ready");
- Yb = (long) (Math.pow(alpha, Xb)%P);
- Socket socket = servsocket.accept();
- OutputStream outputStream = socket.getOutputStream();
- PrintWriter printwrite = new PrintWriter(outputStream, true);
- InputStream inputStream = socket.getInputStream();
- BufferedReader receiveRead = new BufferedReader(new InputStreamReader(inputStream));
- String receiveMessage;
- if((receiveMessage = receiveRead.readLine()) != null)
- {
- System.out.println("Ya is "+receiveMessage+" Yb is "+Yb);
- }
- Ya = Long.parseLong(receiveMessage);
- K = (long) (Math.pow(Ya, Xb)%P);
- printwrite.println(Yb);
- System.out.println("Key is "+K);
- printwrite.flush();
- }
- }
|