# Homework #3 -- Due October 5

The client/server application is the one described in class on 13 September. The server models an eight-slice roulette wheel. The client places bets by naming an amount and a number between 0 and 7. It the client guess the correct number, the client wins seven times its bet. Otherwise, the client loses its bet.

In order to prevent the server from cheating, i.e., picking a number after the client makes its pick, we use a verification method based on number theory. The server chooses a number v between 0 and 999,999,999. The outcome, r, of the next spin of this number is calculated, using C integer division, as

• r = v / (1,000,000,000 / 8)

Before the client makes its ``call'', the server provides the client with the number w, the square of v modulo 2,000,000,137, a prime number. The abstract protocol loop is

1. the server chooses v, and consequently w and r;
2. the server transmits w to the client;
3. the client places its bet by sending a message to the server;
4. the server transmits v and r to the client; and, finally,
5. the client verifies v, w, and r.

Of course, there are certain other details, such as packet format and minimum bets. This are illustrated in the following sample run of the client and server shown in the left column. The server's responses are shown in boldface.

 BALANCE 1000000 Initial client balance is 1,000,000 VERIFIER SQUARED 919696766 Server transmits w WHAT COMMANDS Client sends a bad packet INVALID INPUT Server critiques the packet BALANCE 875000 Server extracts a bad packet penalty VERIFIER SQUARED 784423615 Server starts again BET 50 ON 4 BAD BET AMOUNT 50 Minimum bet is 100,000 BALANCE 765625 Another bad packet penalty VERIFIER SQUARED 710391967 BET 100000 ON 10 BAD BET NUMBER 10 Bets are from 0 to 7 BALANCE 669922 The penalties are mounting up VERIFIER SQUARED 473746622 Client transmits a blank line INVALID INPUT BALANCE 586182 Yep, another one VERIFIER SQUARED 544028316 BET 500000 ON INVALID INPUT BALANCE 512910 VERIFIER SQUARED 178991952 BET 500000 ON 7 A good bet at last! NUMBER 7 YOU WIN Client has won! VERIFIER 932968576 Server provides v BALANCE 4012910 VERIFIER SQUARED 261884547 BET 4000000 ON 7 NUMBER 7 YOU WIN VERIFIER 893211251 BALANCE 32012910 VERIFIER SQUARED 633585890 EXIT Client quits while well ahead CLIENT EXIT Server acknowledges BALANCE 32012910 EXITING

Right now the server is running on penrose.cs.unca.eduat port 7295. You can actually telnet to it directly by typing

```    telnet penrose 7295
```

Your assignment is to write a user-friendly client for this application. The client should prompt the user for a bet number and amount and then transmit the appropriate packets to the server. Your client should also verify that the server didn't cheat, by checking out the numbers returned in the VERIFIER SQUARED and VERIFIER packets. There are a few subroutines stored in the directory /usr/local/csci/363/roul that you will find very helpful.

Back to the Handout index