Cryptography Reference
In-Depth Information
//Challenger will send back a 0 or a 1
int challenge=Integer.parseInt(in.readLine());
//If a 0 was sent, return r to the challenger
if (challenge==0) out.println(r.toString());
//Otherwise, send tr modulo the modulus to the challenger
else
out.println(t.multiply(r.modInverse(modulus)).mod(modulus).toString());
//Challenger will now either send “Y” (approved) or “N” (not approved)
approved=in.readLine().toUpperCase();
} while (!approved.equals(“Y”));
//If we get here, we succeeded
System.out.println(“Your claim of identity has been accepted.”);
k.readLine();
}
}
The Challenger class is a server which loops forever simply listening for connections on
port 12345. (I didn't choose this port for any particular reason.) It establishes a socket with
a respondent using the accept() method. So that the challenger can deal with multiple respon-
dents at once, it is threaded. It will produce a new Challenger object (a subclass of Thread)
for each new connection. If any response from a respondent does not check, the challenger
closes the connection immediately.
import java.math.*;
import java.net.*;
import java.io.*;
import java.security.*;
public class Challenger extends Thread {
static BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
//socket is the connection between challenger and respondent
Socket socket=null;
//trials is the number of challenges the respondent must satisfy
static int trials=0;
static SecureRandom r=null;
//The constructor only sets the socket field
public Challenger(Socket s) {
socket=s;
}
public static void main(String[] args) throws IOException {
Search WWH ::




Custom Search