// //////////////////////////////////////////////////////////
// HideString.cpp
// Copyright (c) 2011 Stephan Brumme. All rights reserved.
// see http://create.stephan-brumme.com/disclaimer.html
//
#include <string>

std::string decode(const std::string& input)
{
  // choose a power of two => then compiler can replace "modulo x" by much faster "and (x-1)"
  const size_t passwordLength = 16;
  // at least as long as passwordLength, can be longer, too ...
  static const char password[passwordLength] = "invalid pointer";

  // out = in XOR NOT(password)
  std::string result = input;
  for (size_t i = 0; i < input.length(); i++)
    result[i] ^= ~password[i % passwordLength];
  return result;
}

int main(int argc, char* argv[])
{
  // "Hello World !"
  printf(decode("\xde\xf4\xe5\xf2\xfc\xb6\xcc\xb0\xfd\xfc\xf2\xb1\xaa").c_str());

  // encrypt command line
  if (argc == 2)
  {
    // apply XOR
    std::string encrypt = decode(argv[1]);

    // display encrypted string
    printf("\ndecode(\"");
    for (size_t i = 0; i < encrypt.length(); i++)
      printf("\\x%02x", encrypt[i] & 0xFF);
    printf("\");");
  }

  return 0;
}
