Abdulg

Simple XOR encryption

Aug 18th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int main(int argc, char** argv)
  6. {
  7.     if (argc != 3)
  8.     {
  9.         printf("Usage: %s file key\n", argv[0]);
  10.         return -1;
  11.     }
  12.  
  13.     FILE *fp = fopen(argv[1], "r");
  14.  
  15.  
  16.     if (fp == NULL)
  17.     {
  18.         printf("Could not open %s\n", argv[1]);
  19.         return -1;
  20.     }
  21.    
  22.    
  23.     int keyLen = strlen(argv[2]);
  24.     char c;
  25.     for (int n = 0; (c = fgetc(fp)) != EOF; n++, n %= keyLen)
  26.     {
  27.         printf("%c", c ^ argv[2][n]);
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment