davek@lakesys.UUCP (Dave Kraft) (05/03/89)
Hi, I was trying to think up a way of en/decrypting a file, and I was wondering if there was any way to invert a binary number like the following example: 10101010 (decimal 170) 01010101 (decimal 85) If anyone could help me here, I would be really greatful. Thanks in advance. Dave -- davek@lakesys.lakesys.com -OR- uunet!marque!lakesys!davek ------------------------------------------------------------------------------- "The mystical divinity of unashamed felinity. 'Round the cathedral rang 'Vivat!' Life to the everlasting Cat!" --'Cats'
davek@lakesys.UUCP (Dave Kraft) (05/03/89)
Hi, Aftter a few hours of research, I solved my own problem. I have alos posted the finished product, wich works quite well. If you have any questions, please send them in email. Thanks. /* crypt.c --Encrypts/decrypts files. Works both on Unix/Xenix and * Turbo C 2.0. * Direct mail enquiries to: davek@lakesys.lakesys.com -OR- * uunet!marque!lakesys!davek */ #include <stdio.h> main() { char fn1[30],fn2[30],c; int i; FILE *f1,*f2,*fopen(); scanf("%s%s",fn1,fn2); f1 = fopen(fn1,"r"); if(f1 == NULL){ printf("Error opening %s.\n",fn1); exit(1); } f2 = fopen(fn2,"w"); if(f2 == NULL){ printf("Error opening %s.\n",fn2); exit(2); } while(feof(f1) == 0){ c = fgetc(f1); fputc(~c,f2); } fclose(f1); fclose(f2); } I know I could've used argc and argv, but, this was quicker. -- davek@lakesys.lakesys.com -OR- uunet!marque!lakesys!davek ------------------------------------------------------------------------------- "The mystical divinity of unashamed felinity. 'Round the cathedral rang 'Vivat!' Life to the everlasting Cat!" --'Cats'