It's difficult to understand exactly what you need. A stripped-down example would be useful.
You won't be able to decrypt string constants in place. You need a string variable with enough space to decrypt to.
Code:
#define GREETING_ENC "YW_XZ\x11""F[QGT"
char GREETING[sizeof GREETING_ENC];
int main(void) {
const char *key = "12345";
crypto(GREETING, GREETING_ENC, key);
printf("%s\n", GREETING);
return 0;
}
Here's a program to convert plain strings to encrypted C string constants.
Code:
#include <stdio.h>
#include <ctype.h>
char *crypto(char *out, const char *from, const char *key) {
const char *k = key;
char *to = out;
while (*from) {
*to++ = *from++ ^ *k++;
if (*k == '\0') k = key;
}
*to = '\0';
return out;
}
void output(const char *s) {
printf("\"");
for ( ; *s; s++) {
// Escape double-quote and backslash.
if (*s == '"' || *s == '\\')
putchar('\\');
// If *s is a printable character, print as is.
if (isprint(*s))
printf("%c", *s);
// Otherwise convert to two-digit hex value.
else
// After the two-digit hex value, two double-quotes
// are output to separate it from further hex digits
// (unless it's the last character)
printf("\\x%02x%s", (unsigned char)*s,
!*(s+1) ? "" : "\"\"");
}
printf("\",\n");
}
int main(void) {
const char *plain[] = {
"hello there",
"another string",
"more stuff",
NULL
};
char cipher[200], *key = "12345";
for (const char **p = plain; *p; p++) {
crypto(cipher, *p, key);
output(cipher);
}
return 0;
}