/* Program to Encrypt A file */ #include #include int main (int argc, char *argv[]) { void crypt (); char *arg[4]; if (argc != 4) //if no arguments or wrong arguments then take i/p interactively { printf ("Please enter password\n"); gets (arg[1]); printf ("Please enter the file to be encrypted/decrypted\n"); gets (arg[2]); printf ("Please enter the output filename\n"); gets (arg[3]); crypt (arg); } else crypt (argv); printf ("\n Success! \n"); return 0; } void crypt (char *cr_arg[]) { FILE *fi, *fo; char *cp; int c; if ((cp = cr_arg[1]) == NULL) { printf ("Invalid password\n"); exit (1); } if ((fi = fopen (cr_arg[2], "rb")) == NULL) { perror ("Unable to open input file "); exit (1); } if ((fo = fopen (cr_arg[3], "wb")) == NULL) { perror ("Unable to create output file "); exit (1); } while ((c = getc (fi)) != EOF) { if (!*cp) cp = cr_arg[1]; c ^= *(cp++); //Uses XOR algorithm putc (c, fo); } fclose (fo); fclose (fi); return; }