I'm trying to obscure some code so when complied casual users can't see the plain text strings if they cat the file.
I've found this and it does do what I want.
string encryptDecrypt(string toEncrypt) {
char key = 'Q';
string output = toEncrypt;
for (int i = 0; i < toEncrypt.size(); i++)
output[i] = toEncrypt[i] ^ key;
return output;
}
It's run like:
foo[0] = encryptDecrypt("/path/jon/files");
cout << "Encrypted:" << foo[0] << "\n";
string decrypted = encryptDecrypt(foo[0]);
cout << "Decrypted:" << decrypted << "\n";
Which results in:
Encrypted:~!0%9~;>?~78=4"
Decrypted:/path/jon/files
My plan(!) was to create a new app that just produced the encrypted strings and then in my my app store all the encrypted strings in an array and decrypt then as needed.
From the above output I know the string /path/jon/files
is encrypted to ~!0%9~;>?~78=4"
but how do I write that into an array?
I had thought:
string foo[2];
foo[0] = "~!0%9~;>?~78=4"";
foo[1] = "XXXXXXX";
But I can't see that working becuase the string contains quotes.
Any way to do this?
UPDATE
I seem to have an issue when I have capital letters in my initial string.
string encrypted = encryptDecrypt("/Path/Jon/Files");
cout << "Encrypted:" << encrypted << "\n";
string decrypted = encryptDecrypt(encrypted);
cout << "Decrypted:" << decrypted << "\n";
string test = "~0%9~?~8=4\"";
decrypted = encryptDecrypt(test);
cout << "Decrypted:" << decrypted << "\n";
Results in:
Encrypted:~0%9~?~8=4"
Decrypted:/Path/Jon/Files
Decrypted:/ath/n/iles
Any idea how to get around that?