home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 193_01 / cypher.c < prev    next >
Text File  |  1985-11-14  |  1KB  |  63 lines

  1. /*    
  2. ** cypher.c        File Cypher Program    by F.A.Scacchitti  9/11/85
  3. **
  4. **        Written in Small-C Version 2.10 or later
  5. **
  6. **        Copies from original file to encrypted file
  7. **        using cypher key(s) passed to  encode or decode.
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define BUFSIZE 16384
  13.  
  14. int fdin, fdout;    /* file  i/o channel pointers */
  15. int n, count;
  16. char *inbuf, *key;
  17.  
  18. main(argc,argv) int argc, argv[]; {
  19.  
  20.    inbuf = malloc(BUFSIZE);
  21.  
  22. /*
  23. ** Open file streams
  24. */
  25.    if(argc < 4) {
  26.       printf("\ncypher usage: cypher <source file> <new file> <key1> <key2> . . . <keyN> <CR>\n");
  27.       exit();
  28.    }
  29.    if((fdin = fopen(argv[1],"r")) == NULL) {
  30.       printf("\nUnable to open %s\n", argv[1]);
  31.       exit();
  32.    }
  33.    if((fdout = fopen(argv[2],"w")) == NULL) {
  34.       printf("\nUnable to create %s\n", argv[2]);
  35.       exit();
  36.    }
  37.  
  38. /*
  39. ** Read file - encode it - write new file 
  40. */
  41.    do {
  42.       printf("-reading file\n");
  43.  
  44.       count = read(fdin,inbuf,BUFSIZE);
  45.  
  46.       n=3;
  47.  
  48.       while(n++ <argc){
  49.          key = argv[n-1];
  50.          cypher(inbuf,count,key);
  51.       }
  52.       printf("-writing %d byte file\n\n", count);
  53.  
  54.       write(fdout,inbuf,count);
  55.  
  56.    } while(count == BUFSIZE);
  57.  
  58.    /* close up shop */
  59.  
  60.       fclose(fdin);
  61.       fclose(fdout);
  62. }
  63.