This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:spring2016:cprog:projects:sam0 [2015/10/29 12:26] – external edit 127.0.0.1 | haas: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 | + | You are to implement |
- | * encode | + | |
- | * key should be provided via command-line argument (or, if present, a file in the current directory called ' | + | * key should be provided via command-line argument (or, if present, a file in the current directory called '**cipher.key**') |
- | * decode | + | |
- | * key should be provided via command-line argument (or, if present, a file in the current directory called ' | + | * 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 | + | The **encode** |
- | Your program(s) should: | + | Operating mode will be determined by the program's 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, | + | * Mode auto-detection |
+ | * 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 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 " | * appropriately " | ||
- | | + | |
- | * for decoding, | + | * the cipher should work only on upper and lowercase letters of the alphabet. Any punctuation, |
+ | * the encoding and decoding | ||
+ | * 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/ | ||
+ | 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: | + | lab46: |
- | hello | + | "hello"!! |
- | jgnnq | + | "jgnnq"!! |
^D | ^D | ||
lab46: | lab46: | ||
</ | </ | ||
+ | |||
+ | (**NOTE:** ^D indicated the CTRL-d sequence, which generates an EOF). | ||
Via negative command-line key: | Via negative command-line key: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | hello there | + | hello, there... |
- | ebiil qebob | + | ebiil, qebob... |
^D | ^D | ||
lab46: | lab46: | ||
</ | </ | ||
- | Without command-line nor cipher.key file: | + | //Without// command-line |
<cli> | <cli> | ||
- | lab46: | + | lab46: |
ERROR: key not found | ERROR: key not found | ||
lab46: | lab46: | ||
</ | </ | ||
- | With 4 in the cipher.key file: | + | With **4** in the **cipher.key** file: |
<cli> | <cli> | ||
- | lab46: | + | lab46: |
+ | lab46: | ||
hello there | hello there | ||
lipps xlivi | lipps xlivi | ||
Line 86: | Line 103: | ||
</ | </ | ||
- | With 4 in the cipher.key | + | Same thing, but saving |
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | lipps xlivi | + | lab46: |
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | |||
+ | With **4** in the **cipher.key** file, decoding previous message (redirected to **code.out**): | ||
+ | |||
+ | < | ||
+ | lab46: | ||
hello there | hello there | ||
^D | ^D | ||
lab46: | lab46: | ||
</ | </ | ||
+ | |||
+ | 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: | + | lab46: |
- | jgnnq | + | "jgnnq" |
- | hello | + | "hello"!! |
^D | ^D | ||
lab46: | lab46: | ||
</ | </ | ||
- | 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: | + | lab46: |
- | hello | + | hello. |
lab46: | lab46: | ||
</ | </ | ||
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/ |
* 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 " | Submitting cprog project " | ||
- | -> sam0-encode.c(OK) | + | -> sam0.c(OK) |
- | -> sam0-decode.c(OK) | + | |
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED |