User Tools

Site Tools


haas:spring2016:cprog:projects:sam0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
haas:spring2016:cprog:projects:sam0 [2015/10/29 12:26] – external edit 127.0.0.1haas:spring2016:cprog:projects:sam0 [2016/03/15 13:04] (current) – [Submission] wedge
Line 27: Line 27:
   * decoding - taking the obfuscated text and making it readable, by reversing the process   * decoding - taking the obfuscated text and making it readable, by reversing the process
 =====Program===== =====Program=====
-You are to implement two programs (or at least a program with two fundamental modes of operation)+You are to implement one program, which contains two fundamental modes of operation: 
-  * encode program: takes plain text message as input, along with a cipher key, and outputs the encoded (obfuscated) result +  * **encode** functionality: takes plain text message as input (via **stdin**), 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'+    * 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 +  * **decode** functionality: takes the encoded (obfuscated) message (via **stdin**), 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')+    * 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). 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).+The **encode** and **decode** functionality will be located in functions you declare and definewhich your program'**main()** function calls upon determining the specified mode of operation.
  
-Your program(sshould: +Operating mode will be determined by the program'name: 
-  * 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 +  * Naming your program **encode** will invoke the encoding functionality. 
-    * use the **fgetc()** function instead of **fscanf()** for reading input from STDIN +  * Naming your program **decode** will invoke the decoding functionality. 
-  * obtain the signed char key value from the command-line, if present, or read from the 'cipher.key' file+  * Mode auto-detection should work regardless of any prefixing path information (**./decode**, **/home/$USER/src/cprog/sam0/encode**, etc.) 
 +    * you may want to explore the **strtok(3)** function, or write your own. 
 + 
 +Your program needs to
 +  * load the provided input (via **stdin**) into an array for processing (you may want to check for an EOF character to terminate input) 
 +    * assume a maximum input size of 4096 bytes 
 +    * use the **fgetc(3)** function instead of **fscanf(3)** for reading input from STDIN (do NOT use any **scanf()** or **gets()** related function, **ONLY fgetc(3)**). 
 +  * 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     * 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   * 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 +    * display the resultant string to STDOUT 
-  for decoding, display the resultant deciphered string to STDOUT+    the cipher should work only on upper and lowercase letters of the alphabet. Any punctuation, number, whitespace, or other symbol should remain intact (knowing your ASCII table would be helpful). 
 +    * the encoding and decoding functionality needs to occur within declared/defined functions you create that are called from **main()** to perform the intended operation. 
 +      * As they will be performing operations on your array filled with the input datayou also need to make productive use of loops. 
 +      * all data needed by the function needs to be passed in by parameter! No global variables. 
 +      * The functions should return an integer containing the exact count of non-letters encountered (and therefore left unmodified from input to output). Your **main()** function needs to return this value when complete. 
 + 
 +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** flag.
 ====Sample execution: encode==== ====Sample execution: encode====
 Via positive command-line key: Via positive command-line key:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./encode-sam0 +lab46:~/src/cprog/sam0$ ./encode 2 
-hello +"hello"!! 
-jgnnq+"jgnnq"!!
 ^D ^D
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
 +
 +(**NOTE:** ^D indicated the CTRL-d sequence, which generates an EOF).
  
 Via negative command-line key: Via negative command-line key:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./encode-sam0 -3 +lab46:~/src/cprog/sam0$ ./encode -3 
-hello there +hellothere... 
-ebiil qebob+ebiilqebob...
 ^D ^D
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
  
-Without command-line nor cipher.key file:+//Without// command-line //nor// cipher.key file:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./encode-sam0+lab46:~/src/cprog/sam0$ ./encode
 ERROR: key not found ERROR: key not found
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
  
-With 4 in the cipher.key file:+With **4** in the **cipher.key** file:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./encode-sam0+lab46:~/src/cprog/sam0$ echo "4" > cipher.key 
 +lab46:~/src/cprog/sam0$ ./encode
 hello there hello there
 lipps xlivi lipps xlivi
Line 86: Line 103:
 </cli> </cli>
  
-With 4 in the cipher.key file, decoding previous message:+Same thing, but saving the encoded text to a file:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./decode-sam0 +lab46:~/src/cprog/sam0$ echo "4" > cipher.key 
-lipps xlivi+lab46:~/src/cprog/sam0$ ./encode <<< "hello there" > code.out 
 +lab46:~/src/cprog/sam0$  
 +</cli> 
 + 
 + 
 +With **4** in the **cipher.key** file, decoding previous message (redirected to **code.out**): 
 + 
 +<cli> 
 +lab46:~/src/cprog/sam0$ ./decode < code.out
 hello there hello there
 ^D ^D
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
 +
 +Note that when you decode, you should get the original message before it was encoded.
  
 Via positive command-line key, decoding: Via positive command-line key, decoding:
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./decode-sam0 +lab46:~/src/cprog/sam0$ ./decode 2 
-jgnnq  +"jgnnq"!!  
-hello+"hello"!!
 ^D ^D
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
  
-You can also save typing, by providing your input via a here string (also a nice way to check for EOF):+You can also save typing, by providing your input via a //here string// (also a nice way to check for EOF):
  
 <cli> <cli>
-lab46:~/src/cprog/sam0$ ./decode-sam0 2 <<< "jgnnq"  +lab46:~/src/cprog/sam0$ ./decode 2 <<< "jgnnq."  
-hello+hello.
 lab46:~/src/cprog/sam0$  lab46:~/src/cprog/sam0$ 
 </cli> </cli>
Line 117: Line 144:
  
   * Code must compile cleanly (no warnings or errors)   * Code must compile cleanly (no warnings or errors)
 +    * Use the **-Wall** flag when compiling.
   * Output must be correct, and resemble the form given in the sample output above.   * 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 be nicely and consistently indented (you may use the **indent** tool)
-  * Code must utilize the algorithm presented above+  * Code must utilize the algorithm/approach presented above
   * Code must be commented   * Code must be commented
     * have a properly filled-out comment banner at the top     * have a properly filled-out comment banner at the top
Line 129: Line 157:
  
 <cli> <cli>
-$ submit cprog sam0 sam0-encode.c sam0-decode.c+$ submit cprog sam0 sam0.c
 Submitting cprog project "sam0": Submitting cprog project "sam0":
-    -> sam0-encode.c(OK) +    -> sam0.c(OK)
-    -> sam0-decode.c(OK)+
  
 SUCCESSFULLY SUBMITTED SUCCESSFULLY SUBMITTED
haas/spring2016/cprog/projects/sam0.1446121617.txt.gz · Last modified: 2016/03/15 12:42 (external edit)