document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4. #include <cstring>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. void encrypt(const string &key, ifstream &from, ofstream &to) {
  10. int key_size = key.size();
  11. char *key_cstr;
  12.  
  13. key_cstr = (char*) malloc(key_size*sizeof(char));
  14. strcpy(key_cstr, key.c_str());
  15.  
  16. char ch;
  17. int i=0;
  18. while (from.get(ch)) {
  19. int tex_c =(int) ch;
  20. int key_c =(int) key[i%key_size];
  21. to.put((char) tex_c^key_c);
  22. i++;
  23. }
  24. free(key_cstr);
  25. }
  26.  
  27. void error(const char* p1, const char* p2="") {
  28. cerr<<p1<<" "<<p2<<endl;
  29. exit(1);
  30. }
  31.  
  32. int main(int argc, char* argv[]) {
  33.  
  34. if (argc!=4) error("./ex key fromfile tofile");
  35.  
  36. string key;
  37. key.assign(argv[1]);
  38.  
  39. ifstream from(argv[2]);
  40. ofstream to(argv[3]);
  41. if (!from) error("cannot open file", argv[2]);
  42.  
  43. encrypt(key, from, to);
  44.  
  45.  
  46. return 1;
  47. }
');