Solved

Obscure C code

Posted on 2004-09-30
11
823 Views
Last Modified: 2011-10-03
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.
0
Comment
Question by:mikrotuho
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
put in a header file?
then we include it.
0
 
LVL 1

Author Comment

by:mikrotuho
Comment Utility
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
 
LVL 45

Expert Comment

by:Kdo
Comment Utility

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
 
LVL 1

Author Comment

by:mikrotuho
Comment Utility
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
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
Comment Utility

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:PaulCaswell
Comment Utility
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
 
LVL 45

Expert Comment

by:Kdo
Comment Utility

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
 
LVL 16

Expert Comment

by:PaulCaswell
Comment Utility
>>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
 
LVL 1

Author Comment

by:mikrotuho
Comment Utility
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
 
LVL 45

Expert Comment

by:Kdo
Comment Utility

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
 
LVL 1

Author Comment

by:mikrotuho
Comment Utility
I have to try this last one sometime. :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now