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

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:spring2016:cprog:projects:sam0 [2016/03/15 12:43] – [Submission] wedgehaas:spring2016:cprog:projects:sam0 [2016/03/15 13:04] (current) – [Submission] wedge
Line 35: Line 35:
 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).
  
-The **encode** and **decode** functionality should be located in functions, which your program's **main()** function calls upon determining the specified mode of operation.+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: Operating mode will be determined by the program's name:
Line 46: Line 46:
 Your program needs to: 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)   * 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 +    * assume a maximum input size of 4096 bytes 
-    * use the **fgetc(3)** function instead of **fscanf(3)** for reading input from STDIN+    * 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   * 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
Line 53: Line 53:
     * display the resultant string to STDOUT     * display the resultant 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 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 data, you 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 93: 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 124: 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)
haas/spring2016/cprog/projects/sam0.1458045810.txt.gz · Last modified: 2016/03/15 12:43 by wedge