I experimented with a simple XOR-based text obfuscation algorithm. Presumably, when the algorithm runs twice in a series, I should return the original input, but in my implementation this only happens sometimes. Here is my code, with some random text, to demonstrate the problem:
#include <stdio.h> void obfuscate(char *text) { char i = 0, p = 0; while (text[i] != 0) { text[i] = (text[i] ^ (char)0x41 ^ p) + 0xfe; p = i++; } } int main(int argc, char **argv) { char text[] = "Letpy,Mprm` Nssl'w$:0==!"; printf("%s\n", text); obfuscate(text); printf("%s\n", text); obfuscate(text); printf("%s\n", text); return 0; }
How can I fix this algorithm so that it really is its own inverse? Any suggestions for improving obfuscation?
c obfuscation
thkala
source share