This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jdavis34:portfolio:cprogproject1 [2012/02/25 19:28] – [Code] jdavis34 | user:jdavis34:portfolio:cprogproject1 [2012/02/28 19:57] (current) – [Code] jdavis34 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | A project for C/C++ by Josh Davis during the Spring 2012. | ||
+ | |||
+ | This project was begun on 2/14/2012 and is anticipated to take 2.5 Decades to complete. Project was completed on MONTH DAY, YEAR. | ||
+ | |||
+ | =====Objectives===== | ||
+ | To write a program that depending on what it is asked to do will either cipher or decipher a message. | ||
+ | =====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 | ||
+ | |||
+ | |||
+ | Thought the above listed are what are required... My unorthodox approach to completing stuff seemed to lead me in a direction that was slight variations of this. | ||
+ | |||
+ | =====Background===== | ||
+ | Green with a blue border? | ||
+ | =====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). | ||
+ | |||
+ | **Note: since the odd way I wrote my Cipher it changed the way that worked in relation to this, but the decipher is that of which was asked.** | ||
+ | |||
+ | =====Code===== | ||
+ | |||
+ | The encipher code: | ||
+ | Original cipher (Not the one that was meant to be wrote) | ||
+ | <code c> | ||
+ | 1 /* | ||
+ | 2 * encipher.c - program that encodes a message according to a key | ||
+ | 3 * | ||
+ | 4 * | ||
+ | 5 * Compile with: gcc -o encipher encipher.c | ||
+ | 6 * | ||
+ | 7 * Place key value in: key.txt | ||
+ | 8 * Place message to encipher in: plain.txt | ||
+ | 9 * Enciphered message placed in: cipher.txt | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 14 | ||
+ | 15 #include < | ||
+ | 16 #include < | ||
+ | 17 int main(int argc, char **argv) | ||
+ | 18 { | ||
+ | | ||
+ | | ||
+ | 21 // char value = 0; | ||
+ | 22 // in=fopen(" | ||
+ | 23 // fscanf(in, " | ||
+ | | ||
+ | | ||
+ | 26 // char *input, *pick; | ||
+ | 27 // input=(char *)malloc(sizeof(char)*1); | ||
+ | 28 // pick=(char *)malloc(sizeof(char)*1); | ||
+ | 29 // *input=0; | ||
+ | 30 // *pick=0; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 35 // printf(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 45 // printf(" | ||
+ | | ||
+ | 47 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 52 // printf(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 63 // printf(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 69 | ||
+ | | ||
+ | 71 // for(q=0; q<argc; q++) | ||
+ | 72 // { | ||
+ | 73 // | ||
+ | 74 // printf(" | ||
+ | 75 // } | ||
+ | 76 // printf(" | ||
+ | | ||
+ | 78 // fprintf(out," | ||
+ | 79 // fclose(in); | ||
+ | | ||
+ | | ||
+ | 82 } | ||
+ | 83 | ||
+ | | ||
+ | </ | ||
+ | **NEW CIPHER** | ||
+ | < | ||
+ | 1 # | ||
+ | 2 # | ||
+ | 3 | ||
+ | 4 int main() | ||
+ | 5 { | ||
+ | 6 FILE *in, | ||
+ | 7 char c, fname[] = " | ||
+ | 8 // value = (char*)malloc(sizeof(char) * 250); | ||
+ | 9 char keyx =0; | ||
+ | 10 // char x =0; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 19 // fgets(value, | ||
+ | | ||
+ | 21 // while(*value != EOF) | ||
+ | 22 // { | ||
+ | 23 // printf(" | ||
+ | 24 // x=(value-keyx); | ||
+ | 25 // fprintf(out," | ||
+ | 26 // printf(" | ||
+ | 27 // fscanf(in, " | ||
+ | 28 // } c = fgetc(in); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 36 | ||
+ | | ||
+ | | ||
+ | 39 | ||
+ | | ||
+ | | ||
+ | 42 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 50 } | ||
+ | 51 | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Decipher code | ||
+ | < | ||
+ | |||
+ | 1 # | ||
+ | 2 # | ||
+ | 3 | ||
+ | 4 int main() | ||
+ | 5 { | ||
+ | 6 FILE *in, | ||
+ | 7 char c, fname[] = " | ||
+ | 8 // value = (char*)malloc(sizeof(char) * 250); | ||
+ | 9 char keyx =0; | ||
+ | 10 // char x =0; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 19 // fgets(value, | ||
+ | | ||
+ | 21 // while(*value != EOF) | ||
+ | 22 // { | ||
+ | 23 // printf(" | ||
+ | 24 // x=(value-keyx); | ||
+ | 25 // fprintf(out," | ||
+ | 26 // printf(" | ||
+ | 27 // fscanf(in, " | ||
+ | 28 // } c = fgetc(in); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 36 | ||
+ | | ||
+ | | ||
+ | 39 | ||
+ | | ||
+ | | ||
+ | 42 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 50 } | ||
+ | |||
+ | </ | ||
+ | =====Execution===== | ||
+ | |||
+ | <cli> | ||
+ | jdavis34@lab46: | ||
+ | please enter a value in which you feel safe: | ||
+ | 2 | ||
+ | your secret is safe with me: | ||
+ | Vjku yqtmu hkpcnn{ dgecwug ocvv rwv wr vjcv jkpv vjcpm {qw ocvv | ||
+ | jdavis34@lab46: | ||
+ | This works finally because matt put up that hint thank you matt | ||
+ | jdavis34@lab46: | ||
+ | |||
+ | </ | ||
+ | 2nd revision of the more intended main cipher(cipher2) | ||
+ | <cli> | ||
+ | |||
+ | jdavis34@lab46: | ||
+ | jdavis34@lab46: | ||
+ | Vjku oguucig ku c vguv vq ugg kh vjku yknn yqtm | ||
+ | |||
+ | jdavis34@lab46: | ||
+ | This message is a test to see if this will work | ||
+ | </ | ||
+ | =====Reflection===== | ||
+ | Comments/ | ||
+ | |||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * Matt? | ||
+ | * Jpettie? the PAlly | ||
+ | * Hint.c ( help with the fgetc vs using the fscanf or fgets) | ||
+ |