Corning Community College
CSCS1320 C/C++ Programming
To explore the implementation of caesar cipher encoding and decoding programs.
A cipher is defined as “a secret or disguised way of writing; a code”, and (as a verb): to put (a message) into secret writing; encode.
In the realm of secrecy (think elementary school secret agent), obfuscation is key. If we can remove direct accessibility to the message (encode), yet still preserve its intent, it can be transmit to a recipient who has the ability to retrieve the message (decode).
The caesar cipher (or shift cipher) is a relatively simple cipher, where each letter of the alphabet is shifted by a fixed amount, enabling a once legible message to appear unrecognizeable (at least directly).
Further background information can be found here:
There are two processes related to a lossless obfuscation of data:
Please NOT: What we are doing is encoding, and NOT encrypting.
You are to implement one program, which contains two fundamental modes of operation:
The key should be a signed char, allowing for a cipher shift of -128 to +127 (your shift can be left or right, depending on the sign of the number).
The encode and decode functionality will be located in functions you declare and define, which your program's main() function calls upon determining the specified mode of operation.
Operating mode will be determined by the program's name:
Your program needs to:
Your program should be a “one shot”. It should only perform its intended operation and exit. No prompting for encode/decode, no “do you want to go again”… just a read from input, process, output, and exit with appropriate return value. They should conform to the execution examples found in this project.
When compiling, an additional constraint is added: compile with the -Wall and --std=gnu18 flags.
Via positive command-line key:
lab46:~/src/SEMESTER/DESIG/sam0$ ./encode 2 "hello"!! "jgnnq"!! emmbzwc goodbye ^D lab46:~/src/SEMESTER/DESIG/sam0$
NOTE: ^D indicated the CTRL-d sequence, which generates an EOF. That is the keypress you use to terminate the program; do NOT have your program display '^D' and exit on its own after one input, for there may be many.
Via negative command-line key:
lab46:~/src/SEMESTER/DESIG/sam0$ ./encode -3 hello, there... ebiil, qebob... ^D lab46:~/src/SEMESTER/DESIG/sam0$
Without command-line nor cipher.key file:
lab46:~/src/SEMESTER/DESIG/sam0$ ./encode ERROR: key not found lab46:~/src/SEMESTER/DESIG/sam0$
With 4 in the cipher.key file:
lab46:~/src/SEMESTER/DESIG/sam0$ echo "4" > cipher.key lab46:~/src/SEMESTER/DESIG/sam0$ ./encode hello there lipps xlivi ^D lab46:~/src/SEMESTER/DESIG/sam0$
Same thing, but saving the encoded text to a file:
lab46:~/src/SEMESTER/DESIG/sam0$ echo "4" > cipher.key lab46:~/src/SEMESTER/DESIG/sam0$ ./encode <<< "hello there" > code.out lab46:~/src/SEMESTER/DESIG/sam0$
With 4 in the cipher.key file, decoding previous message (redirected to code.out):
lab46:~/src/SEMESTER/DESIG/sam0$ ./decode < code.out hello there ^D lab46:~/src/SEMESTER/DESIG/sam0$
Note that when you decode, you should get the original message before it was encoded.
Via positive command-line key, decoding:
lab46:~/src/SEMESTER/DESIG/sam0$ ./decode 2 "jgnnq"!! "hello"!! ^D lab46:~/src/SEMESTER/DESIG/sam0$
You can also save typing, by providing your input via a here string (also a nice way to check for EOF):
lab46:~/src/SEMESTER/DESIG/sam0$ ./decode 2 <<< "jgnnq." hello. lab46:~/src/SEMESTER/DESIG/sam0$
Your encode may end up flowing something like the following:
MODULE ENCODE (RECEIVES MESSAGE AND KEY): LOOP THROUGH EACH CHARACTER IN THE MESSAGE: CHARACTER IS SET TO NUMERIC VALUE OF CHARACTER PLUS THE KEY SHOULD THE CHARACTER EXCEED THE RANGE OF DISPLAYABLE CHARACTERS: RESET CHARACTER TO START OF RANGE PLUS REMAINING OFFSET OF KEY SHOULD THE CHARACTER GO BELOW THE RANGE OF DISPLAYABLE CHARACTERS: RESET CHARACTER TO END OF RANGE MINUS REMAINING OFFSET OF KEY SET MODIFIED CHARACTER TO RESULT MESSAGE END LOOP SEND BACK RESULT MESSAGE END MODULE
MODULE DECODE (RECEIVES MESSAGE AND KEY): LOOP THROUGH EACH CHARACTER IN THE MESSAGE: CHARACTER IS SET TO NUMERIC VALUE OF CHARACTER MINUS THE KEY SHOULD THE CHARACTER EXCEED THE RANGE OF DISPLAYABLE CHARACTERS: RESET CHARACTER TO START OF RANGE PLUS REMAINING OFFSET OF KEY SHOULD THE CHARACTER GO BELOW THE RANGE OF DISPLAYABLE CHARACTERS: RESET CHARACTER TO END OF RANGE MINUS REMAINING OFFSET OF KEY SET MODIFIED CHARACTER TO RESULT MESSAGE END LOOP SEND BACK RESULT MESSAGE END MODULE
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ make submit
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
What I will be looking for:
52:sam0:final tally of results (52/52) *:sam0:resources obtained via grabit by Sunday before deadline [6/6] *:sam0:sam0.c compiles cleanly, no compiler messages [7/7] *:sam0:sam0.c implements specified algorithm, using arrays [13/13] *:sam0:sam0.c changes pushed to lab46 semester repository [13/13] *:sam0:sam0 runtime output conforms to specifications [13/13]
Additionally: