Advertisement
oaktree

xor encrypt

Jul 24th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. namespace XOR {
  7.     std::vector<unsigned char>
  8.     encrypt(const std::vector<unsigned char> str, const std::string& key)
  9.     {
  10.         std::vector<unsigned char> res(str.begin(), str.end());
  11.  
  12.         for (int i = 0, n = str.size(), m = key.length(); i < n; i++) {
  13.             res[i] ^= key[i % m];
  14.         }
  15.  
  16.         return res;
  17.     }
  18.  
  19.     std::vector<unsigned char>
  20.     decrypt(const std::vector<unsigned char>& str, const std::string& key)
  21.     {
  22.         return encrypt(str,key);
  23.     }
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement