Lesson Plan: Java Caesar Cipher (High School)

Project: Java Caesar Cipher

Time Needed: 2 class periods (45–60 minutes each)

Suggested Grade Level: High School

Due Date: _______________________

Overview

Students will build a Caesar Cipher program in Java that can encrypt and decrypt messages using a shift key. Students will practice string processing, loops, conditionals, methods, and input validation.

Learning Targets

Materials

Teacher Hook (5–8 minutes)

Student Tasks (Procedure)

Day 1

  1. Read the spec sheet.
  2. Write pseudocode (use the structure below).
  3. Implement the encrypt() method.
  4. Test with required test cases.

Day 2

  1. Implement the decrypt() method.
  2. Add a menu loop (encrypt / decrypt / quit).
  3. Add key normalization (supports negative keys and keys > 26).
  4. Final testing + screenshot + submit files.

Spec Sheet (Student-Facing)

Project Name

P_CaesarCipher_Lastname

Goal

Write a Java program that can:

Program Requirements

Input

Processing Rules

Output

Must Include (Required Programming Concepts)

Required Test Cases (Must show in your output or in a screenshot)

Tip: Your screenshot should clearly show the input and output for at least 2 test cases, including one decrypt.

Pseudocode (Student Version)

START program

LOOP until user chooses Quit
    DISPLAY menu: 1 Encrypt, 2 Decrypt, 3 Quit
    GET userChoice

    IF userChoice is 3
        PRINT goodbye
        EXIT loop
    ENDIF

    PROMPT for message
    READ message (entire line)

    PROMPT for key (integer)
    READ key

    NORMALIZE key:
        key = key % 26
        if key < 0 then key = key + 26

    IF userChoice is 1
        result = encrypt(message, key)
        PRINT result
    ELSE IF userChoice is 2
        result = decrypt(message, key)
        PRINT result
    ELSE
        PRINT invalid choice
    ENDIF
END LOOP

END program


FUNCTION encrypt(text, key)
    CREATE empty result stringbuilder

    FOR each character ch in text
        IF ch is uppercase letter
            shift within 'A'..'Z' using wrap
            append shifted character
        ELSE IF ch is lowercase letter
            shift within 'a'..'z' using wrap
            append shifted character
        ELSE
            append ch unchanged
        ENDIF
    END FOR

    RETURN result string
END FUNCTION


FUNCTION decrypt(text, key)
    // decrypt is encrypt with (26 - key)
    RETURN encrypt(text, 26 - key)
END FUNCTION

Grading Rubric (100 points)

Category What You’re Looking For Points
A. Program Functionality Encrypt works correctly (20)
Decrypt works correctly (20)
Non-letters preserved (10)
50
B. Required Concepts Uses methods: encrypt/decrypt (10)
Uses loop for character processing (10)
Uses selection for upper/lower/non-letter (5)
25
C. User Experience + Validation Clear prompts/menu/output (10)
Handles invalid menu choice + invalid key (5)
15
D. Style + Documentation Good naming/indentation/comments (5)
Includes name/class period header comment (5)
10
Total 100

Google Classroom Turn-In (Files Students Submit)

Teacher Notes (Quick Tips)