• C

Obscure C code

I have written this little program in c:

#define a ;
#define a_o_ exit
#define _ 100
#define _n_ putchar
#define a_o(_l,l_)_l##l_
#define _a_(_l,l_)a_o(l_,_l)
#define ___ _n_(_-68)
int o__[_-93]={_-27,_+8,_+18,1+_,_+21,_+17,_-67} a int o=_-_ a
_a_(a_o(i,n),a_o(m,a))(__o,O,__){if(++__==_-26||__--==_+2)(___) a
if(__==_+8||__==_+((O=26)-5)) a_o((_n_(_+11)),a
if)((o)>7)a_o_(_n_(o+O-24))a _a_(a_o(i,n),a_o(m,a))

Yes, it may look a bit unclear but that is the point. The idea of the program is to output a simple message onto the screen. This message is concealed in the array o__. My question is whether I can change the program so that its purpose becomes even less obvious from looking at the code? I would like to get rid of the array somehow but still output the same message.
Who is Participating?
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:

Guess that I wasn't very clear.  I was suggesting a way to encode the string in the program so that it's not visible AND adding another level of calculations to the process.

char o1[100];
char o2[100];

int main (int argc, char **argv)
  int idx;
  char *Text;

  Text = argv[1];  /* insert sanity checks  */

  for (idx = 0; Text[idx]; idx++)
    o1[idx] = Text[idx] ^ rand();  /*  if this results in 0, pick a new random  */
    o2[idx] = o1[idx] ^ Text[idx];
  o1[idx] = 0;

  fprintf (stdout, "  char o1[100] = {\n");
  for (idx = 0; Text[idx]; idx++)
    fprintf (stdout, "    '0x%2.2X',\n", o1[idx]);
  fprintf (stdout, "    0};\n")

  fprintf (stdout, "  char o2[100] = {\n");
  for (idx = 0; Text[idx]; idx++)
    fprintf (stdout, "    '0x%2.2X',\n", o2[idx]);
  fprintf (stdout, "    0};\n")


This piece of code will generate the two arrays for you.

RunProgram  "Hi Honey"

  char o1[100] = {

(repeated for o2)

Copy these two arrays into your program and then generate o[idx] via (o1[idx]^o2[idx]).  The message will never appear in the program in text form.


P.S.  When I sent encoded messages to members of the opposite sex, my intentions were seldom noble.  ;)

put in a header file?
then we include it.
mikrotuhoAuthor Commented:
If I put the array in a header file, the whole thing becomes too complicated. I mean to send the program as a simple e-mail and the recipient can then compile the program and run it to read the message.
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Kent OlsenData Warehouse Architect / DBACommented:

This looks like the driver to some obfuscated HTML that gets past my spam filter.  I.E.  I suspect that you're up to no good with this.

Nevertheless, I'll bite.

How long is your array?  You can always make it even less clear by splitting the array.

/*  Generate a split array of a character string array  */

int o[somesize];

int o1[somesize];
int o2[somesize];

strcpy (o, "Hello World");

for (idx = 0; o[idx]; idx++)
  o1[idx] = random_number () & 0xFF;
  o2[idx] = o[idx] ^ o1[idx];
o1[idx] = 0;

/*  Now your display function builds the character at each position with two array lookups:


  instead of the traditional



Even the embedded array is now encoded.


mikrotuhoAuthor Commented:
thank you for your idea Kent, but if I want to encode the string I need to include it in the program in plain text anyway, or did I not understand your idea?

ps. I am just trying to say something to a girl I know, so in this case my intentions are entirely noble.
Have you thought of a further level of obfuscation? How about encode the source using a very simple cifer. Write a very small program to uncifer it. Write a batch file that creates the de-cifer program then executes it and then executes the compiler to comile it, link it and run it.

OOps! That's assuming you're rinning windoze. Oh well, you get the idea.


Kent OlsenData Warehouse Architect / DBACommented:

Hi Paul,

If it's on a Winblows box, there's a statistically significant likelihood that it will be printed as a cipher.  :)


If you don't have fences, you don't need Gates!
>>If it's on a Winblows box, there's a statistically significant likelihood that it will be printed as a cipher.  :)
Thats assuming the maths co-processor gets the statistics right ;)

Gates, left open, swing in the wind!
mikrotuhoAuthor Commented:
I'm on a UNIX machine myself at the moment. The fairer number is using Linux. But I am using the UNIX machine over the network from a laptop with windows XP.  When I came home from work just now it dawned on me what Kent had ment with his two arrays. It gives me the level of obfuscation that I need and maybe something else as well. Time will tell.
Kent OlsenData Warehouse Architect / DBACommented:

Of course, you can SEED o1[] or o2[] with any text that you want and since the other array contains the decipher, the message gets REALLY bizarre.

o1[] = "I want a divorce NOW!";
o2[] = { /*  decihper values  */};

printf (f(o1, o2));  /*  Prints the following message  */


The only restriction is that the messages be the same length.
mikrotuhoAuthor Commented:
I have to try this last one sometime. :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.