Sprout.Random でコンパイル時に暗号化の鍵を生成
やってみました。
[ソース]
#include <algorithm> struct ango{ explicit ango(int key) : key(key){} template<typename Range> Range operator ()(Range range) const{ typedef typename std::iterator_traits<decltype(std::begin(range))>::value_type value_type; auto result = std::move(range); std::transform(std::begin(result), std::end(result), std::begin(result), [this](value_type const& value){ return value ^ this->key; }); return result; } private: int key; }; #include <string> #include <iostream> #include <sprout/random.hpp> int main(){ static constexpr int key = sprout::default_random_engine(SPROUT_UNIQUE_SEED)(); ango filter(key); std::string str("satikokawaii"); auto crypted = filter(str); std::cout << crypted << std::endl; auto decoded = filter(crypted); std::cout << decoded << std::endl; return 0; }