A project for C/C++ by Daniel McKinney during the fall 2012.
This project was begun on 2/24/12 and is anticipated to take 2 days to complete. Project was completed on 2/25/12.
create 2 programs, one to enchipher and one to dechipher a statment in a .txt file
In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
State the idea or purpose of the project. What are you attempting to pursue?
Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK.
Providing any links to original source material, such as from a project page, is a good idea.
You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.)
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:
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:
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).
The encipher code:
#include<stdio.h> #include<stdlib.h> int main() { char *message, *cipher, len=0, x, pos=0; int acipher; message=(char*) malloc(sizeof(char)*24); fprintf(stdout,"Enter a message to be encrypted:"); fscanf(stdin, "%s",message); fprintf(stdout,"Enter a cipher shift integer:"); fscanf(stdin, "%s",cipher); acipher=atoi(cipher); x=*(message+pos); while((x!='\0')&&(x!='\n')) { len++; pos++; x=*(message+pos); } for(pos=0;pos<len;pos++) { fprintf(stdout, "%c", *(message+pos)+acipher); } fprintf(stdout, "\n"); return(0); }
The Decipher code
#include<stdio.h> #include<stdlib.h> int main() { char *message, *cipher, len=0, x, pos=0; int acipher; message=(char*) malloc(sizeof(char)*24); fprintf(stdout,"Enter a message to be decipher:"); fscanf(stdin, "%s",message); fprintf(stdout,"Enter a cipher shift integer:"); fscanf(stdin, "%s",cipher); acipher=atoi(cipher); x=*(message+pos); while((x!='\0')&&(x!='\n')) { len++; pos++; x=*(message+pos); } for(pos=0;pos<len;pos++) { fprintf(stdout, "%c", *(message+pos)-acipher); } fprintf(stdout, "\n"); return(0); }
An example run of the enciphering process:
lab46:~$ ./encipher Enter a message to be encrypted:daniel Enter a cipher shift integer:1 ebojfm lab46:~$
Now, we switch gears and decipher a different (previously enciphered) message:
lab46:~$ ./decipher Enter a message to be decipher:daniel Enter a cipher shift integer:1 c`mhdk lab46:~$
In this project i learned how to shift chars to the right and left, to “encipher” and “decipher” a word.
In performing this project, the following resources were referenced:
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.)