Hey all, I'm currently trying to write a compile-time string encryption (using the words 'string' and 'encryption' quite loosely) lib.
What I have so far is as follows:
// Cacluate narrow string length at compile-time
template <char... ArgsT>
struct CountArgs
{
template <char... ArgsInnerT> struct Counter;
template <char Cur, char... Tail>
struct Counter<Cur, Tail...>
{
static unsigned long const Value = Counter<Tail...>::Value + 1;
};
template <char Cur>
struct Counter<Cur>
{
static unsigned long const Value = 1;
};
static unsigned long const Value = Counter<ArgsT...>::Value;
};
// 'Encrypt' narrow string at compile-time
template <char... Chars>
struct EncryptCharsA
{
static const char Value[CountArgs<Chars...>::Value + 1];
};
template<char... Chars>
char const EncryptCharsA<Chars...>::Value[CountArgs<Chars...>::Value + 1] =
{
Chars...
};
However I can't figure out how to perform operations on the characters as I expand them into the static array. I'd just like to execute a simple operation on each character (e.g. '(((c ^ 0x12) ^ 0x55) + 1)' where c is the character).
A shove in the right direction would be greatly appreciated.
Thanks all.