User Tools

Site Tools


Sidebar

projects

  • cci0 (due 20150909)
  • mms0 (due 20150916)
  • dow0 (due 20150923)
  • mbe0 (due 20150930)
  • mbe1 (due 20151007)
  • cos0 (due 20151028)
  • afn0 (due 20151104)
  • sam0 (due 20151111)
  • cbf0 (due 20151118)
haas:fall2015:cprog:projects:sam0

Corning Community College

CSCS1320 C/C++ Programming

~~TOC~~

Project: Data Obfuscation - SECRET AGENT MESSAGES (sam0)

Objective

To explore the implementation of caesar cipher encoding and decoding programs.

Background

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:

  • encoding - taking the readable text and making it obfuscated, according to a set process
  • decoding - taking the obfuscated text and making it readable, by reversing the process

Program

You are to implement two programs (or at least a program with two fundamental modes of operation):

  • encode program: takes plain text message as input, along with a cipher key, and outputs the encoded (obfuscated) result
    • key should be provided via command-line argument (or, if present, a file in the current directory called 'cipher.key')
  • decode program: takes the encoded (obfuscated) message, along with a cipher key, and outputs the decoded (readable, plain text) result
    • key should be provided via command-line argument (or, if present, a file in the current directory called 'cipher.key')

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).

You can implement this as two separate programs, or as one program that behaves fundamentally different depending on how it is named (ie encode-sam0 operates in encode mode, decode-sam0 operates in decode mode).

Your program(s) should:

  • load the provided input (via STDIN) into an array for processing (you may want to check for an EOF character to terminate input)
    • you may assume a maximum input size of 4096 bytes
    • use the fgetc() function instead of fscanf() for reading input from STDIN
  • obtain the signed char key value from the command-line, if present, or read from the 'cipher.key' file
    • if neither command-line nor key file are available, display error and exit
  • appropriately “shift” the alphabet according to the key (magnitude and direction and mode), storing the results in an array
  • for encoding, display the resultant enciphered string to STDOUT
  • for decoding, display the resultant deciphered string to STDOUT

Sample execution: encode

Via positive command-line key:

lab46:~/src/cprog/sam0$ ./encode-sam0 2
hello
jgnnq
^D
lab46:~/src/cprog/sam0$ 

Via negative command-line key:

lab46:~/src/cprog/sam0$ ./encode-sam0 -3
hello there
ebiil qebob
^D
lab46:~/src/cprog/sam0$ 

Without command-line nor cipher.key file:

lab46:~/src/cprog/sam0$ ./encode-sam0
ERROR: key not found
lab46:~/src/cprog/sam0$ 

With 4 in the cipher.key file:

lab46:~/src/cprog/sam0$ ./encode-sam0
hello there
lipps xlivi
^D
lab46:~/src/cprog/sam0$ 

With 4 in the cipher.key file, decoding previous message:

lab46:~/src/cprog/sam0$ ./decode-sam0
lipps xlivi
hello there
^D
lab46:~/src/cprog/sam0$ 

Via positive command-line key, decoding:

lab46:~/src/cprog/sam0$ ./decode-sam0 2
jgnnq 
hello
^D
lab46:~/src/cprog/sam0$ 

You can also save typing, by providing your input via a here string (also a nice way to check for EOF):

lab46:~/src/cprog/sam0$ ./decode-sam0 2 <<< "jgnnq" 
hello
lab46:~/src/cprog/sam0$ 

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
  • Output must be correct, and resemble the form given in the sample output above.
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must utilize the algorithm presented above
  • Code must be commented
    • have a properly filled-out comment banner at the top
    • have at least 20% of your program consist of //-style descriptive comments
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

$ submit cprog sam0 sam0-encode.c sam0-decode.c
Submitting cprog project "sam0":
    -> sam0-encode.c(OK)
    -> sam0-decode.c(OK)

SUCCESSFULLY SUBMITTED

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.

haas/fall2015/cprog/projects/sam0.txt · Last modified: 2015/10/29 12:26 by wedge