-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifihelman_client_is7.java
44 lines (41 loc) · 1.56 KB
/
difihelman_client_is7.java
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
package substitution_transposition_cipher;
/**
*
* @author admin
*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
public class difihelman_client_is7 {
public static void main(String[] args) throws IOException
{
int n=11,g=7;
Scanner sc = new Scanner (System.in);
InetAddress ip = InetAddress.getLocalHost();
Socket s = new Socket(ip, 5000);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
System.out.println("connection done !");
DataInputStream d1 = new DataInputStream(s.getInputStream());
DataOutputStream d2 = new DataOutputStream(s.getOutputStream());
System.out.println("Enter B's private key" );
double y=sc.nextDouble();
double b=(Math.pow(g, y))% n;
String str = d1.readUTF(); System.out.println("received msg from Server" + str);
System.out.println("sent msg to server"+b );
d2.writeUTF(b+"");
double a = Double.valueOf(str);
double k2 = (Math.pow(a, y))%n;
System.out.println("sent msg to server"+k2 );
d2.writeUTF(k2+"");
str = d1.readUTF();
System.out.println("received msg from Server "+ str);
if(str.equals(k2+""))
System.out.println("Keys matched");
else
System.out.println("Keys are not matched");
}
}