This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:sswimle1:portfolio:cprogproject1 [2012/02/24 16:25] – [Objectives] sswimle1 | user:sswimle1:portfolio:cprogproject1 [2012/02/28 23:28] (current) – [References] sswimle1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | A project for C/C++ Programing by Shane Swimley during the Spring 2012. | ||
+ | |||
+ | This project was begun on 2/24/12 and is anticipated to take 1 day to complete. Project was completed on MONTH DAY, YEAR. | ||
+ | |||
+ | =====Objectives===== | ||
+ | State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it? | ||
+ | |||
+ | Write a program that will encipher and decipher a given string of text. | ||
+ | =====Prerequisites===== | ||
+ | In order to successfully accomplish/ | ||
+ | |||
+ | * successful completion of project #0 and solid understanding of pertinent topics | ||
+ | * familiarity with memory allocation via **malloc(3)** | ||
+ | * familiarity with looking up C function parameters/ | ||
+ | * familiarity with if statements, especially in use for error detection | ||
+ | * familiarity with pointers and pointer arithmetic | ||
+ | * familiarity with loops | ||
+ | * file I/O | ||
+ | |||
+ | =====Background===== | ||
+ | State the idea or purpose of the project. What are you attempting to pursue? | ||
+ | |||
+ | Making a program that will take a message, encipher the message and print the encipher message out to the screen and a location in memory. | ||
+ | Then taking the enciphered message, and deciphering it back into the readable message, displaying that to the screen and in a location of memory. | ||
+ | =====Scope===== | ||
+ | This project will test your familiarity with more involved algorithms, storage, and control structures. | ||
+ | |||
+ | Encoding is the process of converting a message into a coded form. | ||
+ | |||
+ | Decoding is the reverse- retrieving that original message from an encoded form. | ||
+ | |||
+ | In this project you will write a 2 programs: one that will take a plain text message and convert it into a coded form (largely indecipherable to the regular english expecting eye) using a given cipher key, and another that will reverse the process (or decipher), when given the appropriate key. | ||
+ | |||
+ | The key is a numeric used to rotate the alphabet a set amount. Where A would normally equal 1, and Z 26, using a cipher key of 1 to shift 1 position to the right; A would now equal 2 (or B), B is now 3 (or C), and Z would be 1 (A). | ||
+ | |||
+ | Your encoding program can operate as follows: | ||
+ | |||
+ | * obtains its cipher key from a text file called " | ||
+ | * or, if you prefer, use command-line arguments to provide the key | ||
+ | * obtains the input message from a file called " | ||
+ | * if " | ||
+ | * outputs the ciphertext message to STDOUT **AND** saves it to a file called " | ||
+ | * implement error checking to avoid segfaults | ||
+ | |||
+ | The decoding operation is essentially the reverse (shifting to the left). I'd suspect you could reuse much of the same logic. | ||
+ | |||
+ | Your decoding program: | ||
+ | |||
+ | * obtains its cipher key from a text file called " | ||
+ | * or, if you prefer, use command-line arguments to provide the key | ||
+ | * obtains the input cipher from a file called " | ||
+ | * if " | ||
+ | * outputs the plaintext message to STDOUT **AND** saves it to a file called " | ||
+ | * implement error checking to avoid segfaults | ||
+ | |||
+ | If you want, you may implement both functionalities into one program so long as you provide a mechanism for the user to access both operations (but note this is not required for successful completion of this project). | ||
+ | |||
+ | =====Code===== | ||
+ | |||
+ | The encipher code: | ||
+ | |||
+ | <code c> | ||
+ | # | ||
+ | # | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | FILE *message, *key, *cipher; | ||
+ | char c, fname[] = " | ||
+ | char code[] = " | ||
+ | int keyvalue; | ||
+ | |||
+ | message = fopen(fname, | ||
+ | key = fopen(code, " | ||
+ | cipher = fopen(" | ||
+ | |||
+ | c = fgetc(message); | ||
+ | fscanf(key," | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | while(c != EOF) | ||
+ | { | ||
+ | fprintf(stdout, | ||
+ | c = fgetc(message); | ||
+ | } | ||
+ | |||
+ | fclose(message); | ||
+ | message = fopen(fname, | ||
+ | c = fgetc(message); | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | while(c != EOF) | ||
+ | { | ||
+ | if((c >= 65) && (c <= ' | ||
+ | c = c + keyvalue; | ||
+ | else if((c >= ' | ||
+ | c = c + keyvalue; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fprintf(cipher, | ||
+ | c = fgetc(message); | ||
+ | } | ||
+ | fclose(message); | ||
+ | fclose(key); | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Don't forget your deciphering code as well. | ||
+ | |||
+ | <code c> | ||
+ | # | ||
+ | # | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | FILE *cipher, *key, *decipher; | ||
+ | char c, fname[] = " | ||
+ | char code[] = " | ||
+ | int keyvalue; | ||
+ | |||
+ | cipher = fopen(fname, | ||
+ | key = fopen(code, " | ||
+ | decipher = fopen(" | ||
+ | |||
+ | c = fgetc(cipher); | ||
+ | fscanf(key," | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | while(c != EOF) | ||
+ | { | ||
+ | fprintf(stdout, | ||
+ | c = fgetc(cipher); | ||
+ | } | ||
+ | |||
+ | fclose(cipher); | ||
+ | cipher = fopen(fname, | ||
+ | c = fgetc(cipher); | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | while(c != EOF) | ||
+ | { | ||
+ | if((c >= 65) && (c <= ' | ||
+ | c = c - keyvalue; | ||
+ | else if((c >= ' | ||
+ | c = c - keyvalue; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fprintf(decipher, | ||
+ | c = fgetc(cipher); | ||
+ | } | ||
+ | fclose(cipher) | ||
+ | fclose(key); | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | =====Execution===== | ||
+ | |||
+ | An example run of the enciphering process: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | Message is: deadbeef | ||
+ | Cipher is: fgcfdggh | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Now, we switch gears and decipher a different (previously enciphered) message: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | Cipher is: fgcfdggh | ||
+ | Decipher is: deadbeef | ||
+ | </ | ||
+ | =====Reflection===== | ||
+ | Comments/ | ||
+ | |||
+ | I do not think that the overall concept behind the code is hard part of a project like this for me, I think starting something like this from scratch after having about 5 weeks of C/C++ face time is the difficult part. Once I was introduced to concepts for completing the task I found that with little to no guidence I could write the decipher program on my own, starting the cipher program was the difficult part. | ||
+ | |||
+ | Now that I have a working example I can take some more time to look at the code and improve my concept of creating something like this from scratch. | ||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | Matt's example posted. | ||
+ | |||
+ | Other students code. | ||
+ | |||
+ | Generally, state where you got informative and useful information to help you accomplish this project when you originally worked on it (from Google, other wiki documents on the Lab46 wiki, etc.) |