#include #include #include #include #include #include namespace bg = boost::gregorian; #include "DemoUtil.h" bg::date stringToDate( const std::string &dtStr ) { bg::date dt( bg::from_simple_string(dtStr) ); return dt; } int main( int argc, char *argv[] ) { bool obf = true; if( argc > 1 ) { std::string arg( argv[1] ); if( "-d" == arg ) obf = false; else if( "-h" == arg ) { std::cout << "Usage: obfutil [-h | -d | -o]" << std::endl; std::cout << " -h: This help message." << std::endl; std::cout << " -d: De-obfuscate standard input each line of which should contain an integer." << std::endl; std::cout << " -o: Obfuscate each line of standard input which should contain a date." << std::endl; exit(0); } } DemoUtil *util = new DemoUtil; while( !std::cin.eof() ) { std::string line; std::getline( std::cin, line ); if( line.length() > 0 ) { if( obf ) { bg::date dt = stringToDate( line ); // convert it to a number and obfuscate tm _tm = bg::to_tm( dt ); int num = mktime(&_tm); num = util->pub_obfuscate(num); std::cout << line << " = " << num << std::endl; } else { int num; std::istringstream istr(line); if( istr >> num ) { num = util->pub_deobfuscate(num); bg::date dt = bg::date_from_tm( *localtime( &num ) ); std::cout << line << " = " << dt.year() << '-' << dt.month() << '-' << dt.day() << std::endl; } } } } return 0; }