If you are using ascii, use hexadecimal character notation...
void formatString(char *buffer, char *input) {
char *pos = buffer;
while (*input != '\0') {
sprintf(pos, "\\x%02x", (int)*input);
input++;
pos += 4;
}
}
void main() {
char buffer[100]; // 4 chars for every char in the input
char *original = "ABCD";
int size = formatString(buffer, original);
}
This should give you a resulting string like "\x41\x42\x43\x44" that you can put in your program. Unfortunately when you XOR some of the resulting bytes might be null. If you end up with "\x57\x00\x68\xf7" in your program then the string will only report as one character long since the null will terminate it, so you need to store the size of the string separately. This could be handled by Base64 encoding the encrypted string. Otherwise if you only use ASCII 0-127, you could set bit 7 on each character and end it with a null. If your XOR values were 0x55, 0x42, 0x55, 0x55 that would convert "ABCD" to 0x14, 0x00, 0x16, 0x11, by setting bit 7 you would get 0x94, 0x80, 0x96, 0x91:
void main() {
char encryptedString = "\x94\x80\x96\x91";
char buffer[100];
decryptString(buffer, encryptedString);
printf("Original: %s\n", buffer);
}
Where decryptString does the XOR then strips bit 7 by anding with 0x7f.
There's lots of free code out there for Base64 though, so I would just Base64 encode the resulting bytes after XOR, then Base64 decode the string before XORing back to the original.