Cryptography Reference
In-Depth Information
//Raise g to this power
BigInteger gtox=pandg[1].modPow(x,pandg[0]);
//Open a connection with a server waiting for info
System.out.println(“Enter host name or IP address of server:”);
String host=k.readLine();
//Server should be listening on port 11111
Socket socket=new Socket(host,11111);
//Open input and output streams on the socket
BufferedReader in=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintStream out=new PrintStream(socket.getOutputStream());
//Send the values p,g,gtox to server
out.println(pandg[0]);
out.println(pandg[1]);
out.println(gtox);
//Get the gtoy value from server
BigInteger gtoy=new BigInteger(in.readLine());
//Raise gtoy to x power-this is the secret key
BigInteger key=gtoy.modPow(x,pandg[0]);
System.out.println(“The secret key is:\n”+key);
k.readLine();
}
}
Here is a sample run of the server (which was started first) and the client (started second
on a different machine).
Server:
The secret key with **********/********** is:
12114199636606924797266840610171527288281060629502849488049381607979
21289097119134252210652032462292962890192274749104820619339989532999
29747753068016087465910738004515719368489010404514526849086194982928
86796661064671158843778504644018420014267514586262260562581776028857
52446509603402778647138069775001533301
Client:
Enter host name or IP address of server:
**********
The secret key is:
12114199636606924797266840610171527288281060629502849488049381607979
Search WWH ::




Custom Search