Montana Tech of The University of Montana
Computer Science & Software Engineering

CSCI 135
Fundamentals of Computer Science I
Fall 2017



ASSIGNMENT 5

In this assignment, you will get experience using one-dimensional and two-dimensional arrays.


Password Challenge-Response
Traditional password entry schemes are susceptible to "shoulder surfing" in which an attacker watches an unsuspecting user enter his or her password or PIN number and uses it later to gain access to the account. One way to combat this problem is with a randomized challenge-response system. In these systems the user enters different information every time based on a secret in response to a randomly generated challenge. Consider the following scheme in which the password consists of a five-digit PIN number (00000 to 99999). Each digit is assigned a random number that is 1, 2, or 3. The user enters the random digits that correspond to their PIN instead of their actual PIN numbers.

For example, consider an actual PIN number of 12345. To authenticate, the user would be presented with a screen such as:
PIN: 0 1 2 3 4 5 6 7 8 9
NUM: 3 2 3 1 1 3 2 2 1 3
The user would enter 23113 instead of 12345. This doesn't divulge the password even if an attacker intercepts the entry because 23113 could correspond to other PIN numbers, such as 69440 or 70439. The next time the user logs in, a different sequence of random numbers would be generated, such as:
PIN: 0 1 2 3 4 5 6 7 8 9
NUM: 1 1 2 3 1 2 2 3 3 3
Write a program to simulate the authentication process. Store an actual PIN number in your program. The program should use an array to assign random numbers from 1 to 3 to the digits from 0 to 9. Output the random digits to the screen as shown above, get the input response from the user, and output whether or not the user's response correctly matches the PIN number.

For the purposes of this program, use the "actual" PIN number of 56789.Name this program Password.java The output on the screen should look like the following. In this first run, the user entered the converted password incorrectly.
PIN: 0 1 2 3 4 5 6 7 8 9
NUM: 2 1 2 3 3 2 3 1 3 1

Please enter your converted password: 23133
Incorrect.
In this run, the user entered the correct converted password.
PIN: 0 1 2 3 4 5 6 7 8 9
NUM: 3 1 3 2 1 1 2 2 3 3

Please enter your converted password: 12233
Correct.
FAQs:

Um. How do I extract individual digits from the 5 digit PIN that the user enters? Recall that the integer data type has two division type operators. The % operator gives you the remainder of a division operation. So if my entered PIN number is 12233, 12233 % 10 would give me the number 3, thus it extracts the last digit in the number. The integer division operator, /, returns the truncated result of the division, so 12233 / 10 results in 1223. If you use a loop to get through all the digits, you can extract them one by one this way.

There's a lot to this program. How do I get started? Read the problem carefully and write down what steps you need to do. The first thing might be to define the array that the "actual" PIN is stored in. Next you might want to define the array that stores the random digits from 1 to 3 that are associated with each real digit and display it to the user. Then get the user input, convert it into single digits, and check to see if each digit matches the correct entry in the random number array. I would suggest that you write code to do each part in sequence and test (by printing out intermediate results) to make sure it is correct before moving on to code for the next part.



Tic Tac Toe
Write a program called TicTacToe.java Store the game board as a two-dimensional array of type char that has three rows and three columns. Include code for players to make a move, to display the board, to tell whose turn it is (X or O), and to tell whether there is a winner, and which player that is.The game should allow two players to enter their moves by turn, and should check that a given move doesn't land on top of a previous move.

The character to dispay for a blank space is a dot '.'. Of course, the character for the player X is 'X' and the character for player O is 'O'. If you display the board with spaces between the characters, it makes it more readable. Here is an example of the output after two turns:
. . . 
. . . 
. . . 
X, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
1 1
. . . 
. X . 
. . . 
O, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
0 0
O . . 
. X . 
. . . 
X, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
Below is the output when a player tries to move where someone has already played:
O . . 
. X . 
. . . 
X, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
0 0
Invalid move - cannot overwrite a previous move.
X, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
When there is a winner, this is what the output looks like:
O X X 
O X . 
. . . 
O, it's your turn.
Enter two digits for the position of your move.
These must both be in the range of 0 to 2 and separated by a space.
2 0
O X X 
O X . 
O . . 
O is a winner!
At this point, once one of the players wins, or alternatively, when all 9 spaces are filled, the program should terminate.

FAQs:

There's way more to this program than the last one! How do I get started? Again, read the problem carefully and write down what steps you need to do.Here is an outline the might help: