• 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))
(__,O,_n_(a_o(o,__)[o++]))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.
LVL 1
mikrotuhoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongjunCommented:
put in a header file?
then we include it.
0
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.
0
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:

  (o1[idx]^os[idx])

  instead of the traditional

  (o[idx])

*/

Even the embedded array is now encoded.


Kent

0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

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.
0
Kent OlsenData 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] = {
    '0x10',
    '0x27',
    '0x7F',
    '0x6C',
    '0x62',
    '0x39',
    '0xD3',
    '0x8B',
    0};

(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.


Kent

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulCaswellCommented:
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.

Paul

0
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.  :)

Kent

---------------------------------------------------------
If you don't have fences, you don't need Gates!
0
PaulCaswellCommented:
>>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!
0
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.
0
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  */

HAPPY VALENTINE'S DAY



The only restriction is that the messages be the same length.
0
mikrotuhoAuthor Commented:
I have to try this last one sometime. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

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.