SHARE
TWEET

Untitled

a guest Jul 21st, 2019 67 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.  
  5. int main(int argc, char **argv)
  6. {
  7.     FILE *infile;
  8.     FILE *outfile;
  9.     char ch = '\0';
  10.     char newch = '\0';
  11.     int x = 0;
  12.     int pwsMask = 0;
  13.     int Magic = 1163;
  14.     int r = 0;
  15.  
  16.     if(argc != 5){
  17.         printf("The syntax of the command is incorrect.\n");
  18.         return 0;
  19.     }
  20.     else{
  21.         if(argv[3][1] != 'p'){
  22.             printf("You need to include a password.\n");
  23.             return 0;
  24.         }
  25.         //Start reading input file name.
  26.         infile = fopen(argv[1],"rb");
  27.  
  28.         if(infile == NULL){
  29.             printf("Unable to open input file name.\n\%s\n",argv[1]);
  30.             return 0;
  31.         }
  32.         //See if we can write output file
  33.         outfile = fopen(argv[2],"wb");
  34.  
  35.         if(outfile == NULL){
  36.             printf("Unable to write output file name.\n\%s\n",argv[2]);
  37.             return 0;
  38.         }
  39.  
  40.         //Build a sum of all the chars in the password.
  41.         while(x < strlen(argv[4])){
  42.             pwsMask+= (int)argv[4][x];
  43.             x++;
  44.         }
  45.         //Mask pwsMask with Magic and multiply by the length of the password.
  46.         pwsMask = (pwsMask ^ Magic) * strlen(argv[4]);
  47.  
  48.         //Reset x
  49.         x = 0;
  50.  
  51.         //Start reading and encoding the file data.
  52.         while(!feof(infile)){
  53.             //Read input char
  54.             ch = fgetc(infile);
  55.             //If not at end of the input file start encrypting.
  56.             if(!feof(infile)){
  57.                 //Get random number from pwsMask and MOD by 255
  58.                 r = rand() * pwsMask % 0xff;
  59.                 //XOR ch with r
  60.                 newch = (ch ^ r);
  61.                 //Write to the output file name.
  62.                 fputc(newch,outfile);
  63.                 //INC x
  64.                 x++;
  65.             }
  66.         }
  67.         //Close both file handles
  68.         fclose(outfile);
  69.         fclose(infile);
  70.     }
  71.     return 0;
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top