home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CaesarCrypt v2.0
- Written By: E-HACK (epicurus@wilter.com)
-
- A simple example program to perform the "Caesar Cipher", an old, insecure
- encryption scheme. Can both encrypt and decrypt files. Not reccomended for
- anything other than novelty and/or study. This encryption algorythm is very
- easy to break even without a program to use.
-
-
- With the Caesar Cipher, each letter is moved over X spaces, much like the
- old "decoder rings" that you used to be able to get by sending in box tops
- and crap in the 50's.
-
- I've changed this around quite a bit from the original Caesar Cipher algorithm
- in that I've made it more practical for computers by letting it de/encrypt all
- 256 ascii charicter values.
-
- This program is copylefted, so you can do whatever you want with it, so have
- some fun, but please, don't use this for anything important, as it's simply
- not secure enough.
-
- Disclaimer:
- THIS PROGRAM IS DISTRIBUTED "AS IS," WITHOUT ANY IMPLIED OR EXPRESS WARRANTY
- AS TO ITS PERFORMANCE OR AS TO THE RESULTS THAT MAY BE OBTAINED BY ITS USE.
- E-HACK AND WILTERED FIRE ARE NOT LIABLE FOR DIRECT, INDIRECT, OR INCIDENTAL
- DAMAGES FROM ANY DEFECT, MALFUNCTION, INABLILITY OR OMISSION IN THE SOFTWARE
- OR MANUAL OR OTHER RELATED ITEMS AND PROCESSES, INCLUDING BUT NOT LIMITED TO
- SERVICE, LOSS OF BUSINESS, ANTICIPATED PROFIT, OR OTHER CONSEQUENTIAL DAMAGES.
-
- To compile on *NIX:
- cc -o caesar caesar.c
-
- Successfully tested(compiled and run w/out changes) on:
- BSDi 3.0
- MS-DOS 6.2
- Windows 95
-
- */
-
-
-
- #include <stdio.h> /* standard I/O functions */
-
-
- int main(void)
- {
- char infile[256], outfile[256], enc[1];
- int c, i, enci, key;
- FILE *ffp, *sfp;
-
- printf("CaesarCrypt v2.0\nWritten By: E-HACK\n\n");
- printf("Input File: ");
- scanf("%s", infile); /* gets the input file, it'll be opened as ffp */
- printf("Output File: ");
- scanf("%s", outfile); /* gets the output file, it'll be opened as sfp */
- printf("Key: ");
- scanf("%d", &key); /* gets the key to use for encryption/decryption */
-
- if(key < 0 || key > 255)
- {
- printf("Key must be an integer between 0 and 255!\n");
- return(0);
- }
-
- /* ask if they need to decrypt or encrypt */
- printf("Encrypt or Decrypt(E/D)? ");
- scanf("%s", enc);
- enci = 0;
- if(tolower(enc[0]) == 'd'){
- enci = 1;
- }
-
- /* open input file */
- ffp = fopen(infile, "r");
- if(ffp == NULL) {
- /* oops, can't open that one, it's not there */
- printf("Unable to open %s!\n", infile);
- return(0);
- }
- /* open the output file */
- sfp = fopen(outfile, "w");
- /* flush the contents of the output file */
- fflush(sfp);
-
- /* do this for every byte in the input file */
- while(c != EOF)
- {
- /* get one byte from the input file */
- c = getc(ffp);
- i = c;
- if(enci == 1)
- {
- i -= key;
- }
- if(enci != 1)
- {
- i += key;
- }
- /* get i between 0 and 255 */
- while(i < 0){ i += 256; }
- while(i > 255){ i -= 256; }
-
- /* print the encrypted charicter to the output file, unless it's the end of file */
- if(c != EOF) fprintf(sfp, "%c", i);
-
- }
- /* close input and output files */
- fclose(ffp);
- fclose(sfp);
-
- /* delete the input file...I decided to comment this out though
- unlink(infile); */
-
- /* tell the user that we're done encrypting or decrypting the data */
- if(enci == 1){
- printf("Decrypted %s to %s\n", infile, outfile);
- }
- else {
- printf("Encrypted %s to %s\n", infile, outfile);
- }
-
- /* done */
- return(0);
- }