1 /* File encrypt.c */
2 /***************************************************************************
3 * Copyright 2003 - Steven Shipway <steve@cheshire.demon.co.uk> *
4 * Put "nospam" in subject to avoid spam filter *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA *
19 * 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #include "wand_head.h"
24
25 /* Uses seeded random xor to encrypt because setkey doesnt work on our
26 system. */
27
crypt_file(name)28 crypt_file(name)
29 char *name;
30 {
31 char buffer[1024];
32 int fd,length,loop;
33
34 if((fd = open(name,O_RDONLY)) == -1) {
35 endwin();
36 sprintf(buffer,"Wanderer: cannot open %s",name);
37 perror(buffer);
38 exit(1);
39 }
40 if((length = read(fd,buffer,1024)) < 1) {
41 endwin();
42 sprintf(buffer,"Wanderer: read error on %s",name);
43 perror(buffer);
44 exit(1);
45 }
46 close(fd);
47
48 /* Right, got it in here, now to encrypt the stuff */
49
50 addstr("Running crypt routine....\n");
51 refresh();
52
53 srand(BLURFL);
54 for(loop=0;loop<length;loop++)
55 buffer[loop]^=rand();
56
57 if((fd = open(name,O_WRONLY|O_TRUNC))== -1) {
58 endwin();
59 sprintf(buffer,"Wanderer: cannot write to %s",name);
60 perror(buffer);
61 exit(1);
62 }
63 if(write(fd,buffer,length)!=length) {
64 endwin();
65 sprintf(buffer,"Wanderer: write error on %s",name);
66 perror(buffer);
67 exit(1);
68 }
69 close(fd);
70
71 /* ok, file now contains encrypted/decrypted game. */
72 /* lets go back home... */
73 }
74