// file XOR test 1
#include <string>
#include <iostream>
#include <fstream>
#include <boost/filesystem.hpp>
bool XOR(const std::string& filePath, const std::string& outputPath, const std::string& key)
{
std::ifstream in(filePath.c_str(), std::ios::binary);
std::ofstream out(outputPath.c_str(), std::ios::binary);
//files succesfully opened?
if(!in || !out)
return false;
std::string::const_iterator keyChr = key.begin();
//start encryption
char chr;
while(in.get(chr) && out)
{
out << char(chr ^ (*keyChr));
if(++keyChr == key.end())
keyChr = key.begin();
}
in.close();
out.close();
return true;
}
int main()
{
XOR("test.bin", "test.out", std::string(32, '*'));
std::cout << "File size: " << boost::filesystem::file_size("test.bin") << '\n';
}
Ly8gZmlsZSBYT1IgdGVzdCAxCiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxib29zdC9maWxlc3lzdGVtLmhwcD4KYm9vbCBYT1IoY29uc3Qgc3RkOjpzdHJpbmcmIGZpbGVQYXRoLCBjb25zdCBzdGQ6OnN0cmluZyYgb3V0cHV0UGF0aCwgY29uc3Qgc3RkOjpzdHJpbmcmIGtleSkKewogICAgc3RkOjppZnN0cmVhbSBpbihmaWxlUGF0aC5jX3N0cigpLCBzdGQ6Omlvczo6YmluYXJ5KTsKICAgIHN0ZDo6b2ZzdHJlYW0gb3V0KG91dHB1dFBhdGguY19zdHIoKSwgc3RkOjppb3M6OmJpbmFyeSk7CgogICAgLy9maWxlcyBzdWNjZXNmdWxseSBvcGVuZWQ/CiAgICBpZighaW4gfHwgIW91dCkKICAgICAgICByZXR1cm4gZmFsc2U7CgogICAgc3RkOjpzdHJpbmc6OmNvbnN0X2l0ZXJhdG9yIGtleUNociA9IGtleS5iZWdpbigpOwoKICAgIC8vc3RhcnQgZW5jcnlwdGlvbgogICAgY2hhciBjaHI7CiAgICB3aGlsZShpbi5nZXQoY2hyKSAmJiBvdXQpCiAgICB7CiAgICAgICAgb3V0IDw8IGNoYXIoY2hyIF4gKCprZXlDaHIpKTsKCiAgICAgICAgaWYoKytrZXlDaHIgPT0ga2V5LmVuZCgpKQogICAgICAgICAgICBrZXlDaHIgPSBrZXkuYmVnaW4oKTsKICAgIH0KCiAgICBpbi5jbG9zZSgpOwogICAgb3V0LmNsb3NlKCk7CgogICAgcmV0dXJuIHRydWU7Cn0KaW50IG1haW4oKQp7CiAgICBYT1IoInRlc3QuYmluIiwgInRlc3Qub3V0Iiwgc3RkOjpzdHJpbmcoMzIsICcqJykpOwogICAgc3RkOjpjb3V0IDw8ICJGaWxlIHNpemU6ICIgPDwgYm9vc3Q6OmZpbGVzeXN0ZW06OmZpbGVfc2l6ZSgidGVzdC5iaW4iKSA8PCAnXG4nOwp9Cg==
/home/VU1qjY/ccB9mvds.o: In function `global constructors keyed to _Z3XORRKSsS0_S0_':
prog.cpp:(.text+0x2c): undefined reference to `boost::system::get_system_category()'
prog.cpp:(.text+0x36): undefined reference to `boost::system::get_generic_category()'
prog.cpp:(.text+0x40): undefined reference to `boost::system::get_generic_category()'
prog.cpp:(.text+0x4a): undefined reference to `boost::system::get_generic_category()'
prog.cpp:(.text+0x54): undefined reference to `boost::system::get_system_category()'
/home/VU1qjY/ccB9mvds.o: In function `boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, unsigned long long>::type boost::filesystem::file_size<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
prog.cpp:(.text._ZN5boost10filesystem9file_sizeINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EEyE4typeERKS7_[boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, unsigned long long>::type boost::filesystem::file_size<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)]+0x53): undefined reference to `boost::filesystem::detail::file_size_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status