Solved

Obscure C code

Posted on 2004-09-30
11
824 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:Kdo
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
 
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:
Kdo 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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:Kdo
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:Kdo
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which version of C should I use when Perl is too slow? 13 173
How do I install gcc 4.8.4 on a Linux Ubuntu 14.04 machine? 5 1,567
C++ vs C compilers 13 157
distributed computing in Python 4 114
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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

911 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

22 Experts available now in Live!

Get 1:1 Help Now