Advertisement
B1KMusic

file-enc.c improved

Oct 15th, 2015
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(int argc, char **argv){
  5.     FILE *in,
  6.          *out;
  7.     char *key;
  8.     int c,
  9.         len;
  10.  
  11.     if(argc != 4){
  12.         printf("Usage: %s [input file] [output file] [encryption key]", *argv);
  13.         return 1;
  14.     }
  15.  
  16.     in  = fopen(argv[1], "r");
  17.     out = fopen(argv[2], "w");
  18.     key = argv[3];
  19.     len = strlen(key);
  20.  
  21.     while( (c = fgetc(in)) != EOF){
  22.         fputc(c ^ *key, out);
  23.         key = key == argv[3] + len ? argv[3] : key + 1;
  24.     }
  25.  
  26.     fclose(in);
  27.     fclose(out);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement