CMSC 223 Systems Programming
Fall 2023


Assignment#4
Due in Class on Wednesday, November, 1

  1. Caesar Cipher
    One of the oldest known excryption techniques is the Caesar Cipher, attributed to Julius Caesar. It involves replacing each letter in a message with another letter that is a fixed number of positions later in the alphabet. For example, if each letter is replaced by one that is two positions after it, an A will be replaced by a C, an L by an N, etc. If the replacement goes past the letter Z, the cipher wraps around to the beginning of the alphabet. Thus, with the same shift (of two), a Y will be replaced by an A, and Z by B.

    Write a program that encrypts a message using the Caesar Cipher. The user will enter the message to be encrypted and the shift amount (number of positions by which letetrs should be shifted):

    Enter message to be encrypted: Go ahead, make my day.
    Enter shift amount (1-25): 3
    Ecrypted message: Jr dkhdg, pdnh pb gdb.


    You may assume that the message will not exceed 80 characters. Characters other than letters should be left unchanged. Lowercase letters remain in lowercase when encrypted, and uppercase letters remain uppercase.

    Hint: To handle the wrap around, use the expression ((ch-'A') + n) % 26 + 'A' to calculate the encryoted version of an uppercase letter, where ch stores the letter and n stores the shift amount. You will need a similar expression for lowercase letters.

    Task 1: Write, then use, a function called encrypt1() whose header is shown below:

    void encrypt1(char message[], char codedMsg[], int n, int shift);
    // Encrypts the text in message[0..n-1] using Caesar Cipher with shift (1 <= shift <= 26). Result is left in codedMsg[]

    Task 2: Write, then use, a function called encrypt2() whose header is shown below:

    void encrypt2(char *message, char *codedMsg, int shift);
    // Encrypts the string in message[] using Caesar Cipher with shift (1 <= shift <= 26). Result is left in codedMsg.


    This fucntion is the same as encrypt1() except, this time you will write it using pointers and pointer arithmetic, on a string (which is NULL terminated).

What to hand in:

Back to CMSC223 Home page