fork download
  1. // file XOR test 3
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <boost/filesystem.hpp>
  6. void XOR(const std::string& filePath, const std::string& outputPath, const std::string& key)
  7. {
  8. std::ifstream in(filePath, std::ios::binary);
  9. std::ofstream out(outputPath, std::ios::binary);
  10.  
  11. const int blocksize = 10240;
  12. char buffer[blocksize];
  13. const int keyBufSize=64;
  14. char keyBuf[keyBufSize];
  15.  
  16. for(int i=0; i<keyBufSize; i++)
  17. keyBuf[i] = key[ i % key.size() ];
  18.  
  19. while(in.read(buffer, blocksize), in.gcount() > 0)
  20. {
  21. int j=0;
  22. for( ; j < blocksize - blocksize%keyBufSize; j += keyBufSize) {
  23. for(int k=0; k<keyBufSize; k++)
  24. buffer[j+k] ^= keyBuf[k];
  25. }
  26.  
  27. for( ; j<blocksize; j++) // won't happen
  28. buffer[j] ^= key[j%key.size()];
  29. out.write(buffer, in.gcount());
  30. }
  31. }
  32. int main()
  33. {
  34. XOR("test.bin", "test.out", std::string(32, '*'));
  35. std::cout << "File size: " << boost::filesystem::file_size("test.bin") << '\n';
  36.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:32: fatal error: boost/filesystem.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty