home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff216.lzh / Wanderer / src / encrypt.c < prev    next >
C/C++ Source or Header  |  1989-06-02  |  1KB  |  55 lines

  1. #include "wand_head.h"
  2.  
  3. /* Uses seeded random xor to encrypt because setkey doesnt work on our
  4.    system.                                 */
  5.  
  6. /* this is the randon number seed */
  7. #define BLURFL 32451    /* the word blurfl is used for historical reasons */
  8.                         /* but it can be any nuber */
  9. crypt_file(name)
  10. char *name;
  11. {
  12. char buffer[1024];
  13. int fd,length,loop;
  14.  
  15. if((fd = open(name,O_RDONLY)) == -1) {
  16.     endwin();
  17.     sprintf(buffer,"Wanderer: cannot open %s",name);
  18.     perror(buffer);
  19.     exit(1);
  20. }
  21. if((length = read(fd,buffer,1024)) < 1) {
  22.     endwin();
  23.     sprintf(buffer,"Wanderer: read error on %s",name);
  24.     perror(buffer);
  25.     exit(1);
  26. }
  27. close(fd);
  28.  
  29. /* Right, got it in here, now to encrypt the stuff */
  30.  
  31. addstr("Running crypt routine...\n");
  32. refresh();
  33.  
  34. srand(BLURFL);
  35. for(loop=0;loop<length;loop++)
  36.     buffer[loop]^=rand();
  37.  
  38. if((fd = open(name,O_WRONLY|O_TRUNC))== -1) {
  39.     endwin();
  40.     sprintf(buffer,"Wanderer: cannot write to %s",name);
  41.     perror(buffer);
  42.     exit(1);
  43. }
  44. if(write(fd,buffer,length)!=length) {
  45.     endwin();
  46.     sprintf(buffer,"Wanderer: write error on %s",name);
  47.     perror(buffer);
  48.     exit(1);
  49. }
  50. close(fd);
  51.  
  52. /* ok, file now contains encrypted/decrypted game. */
  53. /* lets go back home... */
  54. }
  55.