Programming Assignment 07


Due: Week of Oct. 24 in lab


  1. Write a library for encrypting and decrypting a message with a shift cipher (Caesar cipher). A shift cipher encodes a message by replacing each letter with a corresponding letter up or down by a specific amount in the alphebet. Write two clients for the library to aid a user in (1) encrypting a specific message and (2) decrypting an encoded message. Remember - BREAK THE PROBLEM DOWN INTO PIECES TO MAKE IT EASIER. Worth 60 pts. Messages are assumed to be upper case!
    Details for the library:
    • Name the file and program ShiftCipher.java
    • The API is as follows:
      • void encrypt(char[] msg, int shift)
      • void decrypt(char[] msg, int shift)
    • Encode a letter c with the following: (char)((c - 65 + shift) % 26 + 65)
    • Decode a letter c with the following: (char)((c - 65 - shift + 26) % 26 + 65)
    • Space characters should be ignored by encrypt and decrypt.
    • The main function for ShiftCipher.java should contain a well thought out unit test for encrypt and decrypt.

    Details for the encrypting client:
    • Name the file and program Encrypt.java
    • Request a one line message from the user from Standard Input. Use Scanner's nextLine() function, not any loops.
    • Request a shift size from the user from Standard Input.
    • Call the encrypt function, remember you have to convert the message to a char[] (toCharArray() in String).
    • Output the encoded message to a file. All of the message is on one line. The file name is given as a command-line argument to the program.

    Details for the decrypting client:
    • Name the file and program Decrypt.java
    • Read a one line encodes message from a file. The file's name is provided by a command-line argument to the program.
    • Request a shift size from the user from Standard Input.
    • Call the decrypt function, remember you have to convert the message to a char[] (toCharArray() in String).
    • Output the encoded message to standard output. All of the message is on one line.

    Examples:
    • Input:$ java ShiftCipher
      Output:(this is specific to your unit test)
    • Input:$ java Encrypt msg.txt
      Output:(user enters information when prompted)
      Please enter a message: HELLO THERE
      Please enter a shift: 3

      msg.txt contains: KHOOR WKHUH
    • Input:$ java Decrypt msg.txt (msg.txt contains KHOOR WKHUH)
      Output:(user enters information when prompted)
      Please enter a shift: 3
      HELLO THERE
  2. Write a program using a recursive function that reverses a String. The String is input as a command-line argument and output to the terminal in the main function. Name the file and program ch2sec3prob00.java. Worth 20pts. Use only length(), substring(), and charAt() from String. The recursive function is ~3 lines of code and main is ~1 line of code.
    Examples:
    • Input:$ java ch2sec3prob00 Hello
      Output:olleH
  3. Write a program using a recursive function that outputs the binary representation of an integer. The integer is input as a command-line argument. Name the file and program ch2sec3prob01.java. Worth 20pts. The recursive function is ~6 lines of code and main is ~2 line of code.
    Examples:
    • Input:$ java ch2sec3prob01 10
      Output:1010


Grading

Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.

Specific instructions. Failure to do these steps will result in a loss of points.

Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).

If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).