Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. FILE *mozpan; //encrypted data file
  5. FILE *notmozpan; // decrypted data file
  6.  
  7. void encryptDecrypt(char *input, char *output)
  8. {
  9.     char key[] = {'T', 'A', 'L'}; //the key of the encryption
  10.  
  11.     int i;
  12.     for(i = 0; i < strlen(input); i++)
  13.         {
  14.         output[i] = input[i] ^ key[i % (sizeof(key)/sizeof(char))]; // using XOR encryption(^).
  15.         }
  16. }
  17.  
  18. int main()
  19.  {
  20.     char baseStr[] = "DOR"; // The string to encrypt
  21.  
  22.     char encrypted[strlen(baseStr)]; // encrypting using XOR
  23.     encryptDecrypt(baseStr, encrypted);
  24.     printf("Encrypted:%s\n", encrypted);
  25.  
  26.     mozpan = popen(encrypted,"w"); // writing the data to a file
  27.  
  28.     char decrypted[strlen(baseStr)]; // decrypting using XOR
  29.     encryptDecrypt(encrypted, decrypted);
  30.     printf("Decrypted:%s\n", decrypted);
  31.  
  32.     notmozpan = popen(decrypted,"w");//writing decrypted data to a file
  33.  
  34.     printf(mozpan);
  35.     printf(notmozpan);
  36.     fclose(mozpan);
  37.     fclose(notmozpan);
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement