Advertisement
Guest User

Untitled

a guest
Feb 20th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <sys/stat.h>
  6. #define XOR_BYTE 0xAA
  7. #define JOB_CRYPT 1
  8. #define JOB_DECRYPT 2
  9. int xorFile(char *infile, char *outfile) {
  10.   char ch;
  11.   FILE *source = fopen(infile, "rb");
  12.   if(source==NULL) {
  13.     fprintf(stderr,"Enter valid file\n");
  14.     fclose(source);
  15.     exit(EXIT_FAILURE);
  16.   }
  17.   FILE *target = fopen(outfile,"wb");
  18.   if(target==NULL) {
  19.   }
  20.   while((ch=fgetc(source))!=EOF)
  21.   {
  22.     ch ^= XOR_BYTE;
  23.     fputc(ch,target);
  24.   }
  25.   fclose(target);
  26.   fclose(source);
  27.   return 0;
  28. }
  29. int main(int argc, char *argv[]) {
  30.   xorFile(argv[1],argv[2]);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement