home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / cpgms.zip / CRYPT.C < prev    next >
Text File  |  1985-08-05  |  2KB  |  93 lines

  1. /*
  2.  * crypt: a file encryption utility
  3.  *
  4.  * by Andrew Scott Beals
  5.  * 9178 Centerway Rd.
  6.  * Gaithersburg MD 20879
  7.  * (301) 926-0911
  8.  * last update->26 June 1982
  9.  *
  10.  */
  11.  
  12. #include "stdio.h"
  13.  
  14.  
  15. main(argc,argv)
  16. int    argc;
  17. char    *argv[]; 
  18. {
  19.     char    rotor[128];
  20.     char    rotsiz;
  21.     int    byte;
  22.     char    rotptr;
  23.     char    filout;
  24.     FILE    *input, *output;
  25.  
  26.     if(argc == 2 && argv[1][0] == '?') {
  27.         printf("crypt is a program designed to provide\n");
  28.         printf("the user with a means to protect his data\n");
  29.         printf("from the perusal of others, even if they\n");
  30.         printf("can get their hands on his file\n\n");
  31.         printf("usage: crypt [ -K <key> ] <input file> [ <output file> ]\n");
  32.         exit(1);
  33.     }
  34.  
  35.     if(argc > 5 || argc < 2) {
  36.         printf("usage: crypt [ -K <key> ] <input file> [ <output file> ]\nfor more information, enter: crypt ?");
  37.         exit(1);
  38.     }
  39.  
  40.     if(argv[1][0] == '-' && argv[1][1] == 'K') {
  41.         strcpy(rotor,argv[2]);
  42.         argc-=3;    /* make argc == # of files spec */
  43.         argv+=3;    /* argv now points to the first file name */
  44.     } 
  45.     else {
  46.         printf("key? ");
  47.         scanf("%s",rotor);
  48.         argc--;
  49.         argv++;
  50.     }
  51.  
  52.     if((input = fopen(argv[0], "r")) == NULL) {
  53.         printf("can't open %s for input",argv[0]);
  54.         exit(1);
  55.     }
  56.  
  57.     if(argc == 2) {        /* open up the output file */
  58.         filout=1;
  59.         if((output = fopen(argv[1], "w")) == NULL) {
  60.             printf("can't open %s for output",argv[1]);
  61.             exit(1);
  62.         }
  63.     } 
  64.     else
  65.         filout=0;
  66.  
  67.     rotsiz=strlen(rotor);
  68.     if(!rotsiz) {
  69.         printf("funny guy...the key must be at least 1 character");
  70.         exit(1);
  71.     }
  72.  
  73.     rotptr=1;
  74.  
  75.     printf("Working...");
  76.  
  77.     while((byte=getc(input)) != EOF) {
  78.         byte ^= rotor[rotptr++];
  79.         rotptr %= rotsiz;
  80.         if(filout)
  81.             putc(byte, output);
  82.         else
  83.             putchar(byte);
  84.     }
  85.  
  86.     if(filout) {
  87.         fclose(output);
  88.     }
  89.  
  90.     exit(0);
  91. }
  92.  
  93.