Solved

Obscure C code

Posted on 2004-09-30
11
827 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
ID: 12189757
put in a header file?
then we include it.
0
 
LVL 1

Author Comment

by:mikrotuho
ID: 12189813
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:Kent Olsen
ID: 12189877

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:mikrotuho
ID: 12190093
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:
Kent Olsen earned 250 total points
ID: 12190367

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

Expert Comment

by:PaulCaswell
ID: 12190715
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:Kent Olsen
ID: 12190778

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
ID: 12190836
>>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
ID: 12192031
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:Kent Olsen
ID: 12192238

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
ID: 12192695
I have to try this last one sometime. :)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

809 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