The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2002
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
Thumbs up Obfuscated C

Well this year i decided to enter the International Obfuscated C Code Contest. This was my first attempt at writing obfuscated C (at least purposely), so I am sure that this is kids-stuff for the real obfuscation gurus. Anyway, the results are out, and I am not a finalist (I wasn't expecting to be), so I figured I would share my code with you all, just for fun. If anyone else made an entry this year, please share them!


Here are the remarks included with my entry:

This program grew out of a non-obfuscated utility that I threw
together a while ago. I use it as a reference from time to
time since different architectures produce different results (at
least, the output is different on my HP-UX box than it is on my
Intel box). It simply outputs a nicely formatted ascii character
table. It is run with no arguments and produces its report on
the standard out. I achieved obfuscation by using a couple of
levels of recursion, plus some confusingly named variables and
functions. I also included some additional code which does
absolutley nothing just to confuse things a little more.

I strived for "-Wall" cleanness. As a result I had to give up
a couple minor obfuscations, but I think it is still sufficiently
convoluted. This is my first attempt at obfuscated C -- it was
written over the course of several weeks as a diversion. By
the end it became very difficult to improve as I could no longer
understand how it worked without a serious amount of thought!

The code is neatly arranged in the form of my initials.



Code:
#  include  <stdio.h>
#          define d (
#          define I1 1<<
#          define b )
#          define Il(l) \
           return(l)
#          define lI \
I*((I1 3)-1)+(I*(I1\
1))-(I-\
(I1 4))
#define \
_l(l)  \
ll_l(l)
#define \
ll(l) l
#define \
l1 main(

long i,l,ll(I)=d(I1 5)-(I1 1)b;int _l(l)
{putchar d ll(l)b;Il(l);}int II(l,L){_l(
(l/L)+48);l-=((l/L)*L);d L/=10 b?II(l,L)
          :0;Il(l);}int l1 
          b{*d d l b?&I:&l
          b=I;if d l>(I1 8
          b b Il(I1 0);_l(
          32);_l(I1 5);II(
          l,25<<2);_l(58);
          _l(I1 5);_l(ll(l
          ));l%(I1 2)?0:_l
          ((I1 3)+(ll(I1 1)
          )b;l++;Il(l1 l));
}
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-28-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Stumble this Post!
Hey, I like that!
I've moved it to $HOME/bin since it is a lot better than "man ascii"...
Here's one of my favorites:
Code:
 main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}
It was written by David Korn, and won Best One-Liner in 1987.
Another one I think is awesome is thadgavin.c, a winner in 2000 (source too long to post here).

Also, a stongly suggested entry to look at in jarijyrki.c in 2000. I've actually used that program before for work purposes!

Lookin' good PxT!
Reply With Quote
  #3 (permalink)  
Old 04-03-2002
Registered User
 

Join Date: Mar 2002
Location: Bangalore,Karnataka State,India
Posts: 18
Stumble this Post!
One liner is not working!!!! by david korn

That one liner is not working.
What include files should I have in the code ?

thank you,
sharath chandra
Reply With Quote
  #4 (permalink)  
Old 04-03-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
Dr. Korn's one liner seems to have been written in the days of K&R C. LivinFree uses HP-UX. HP-UX includes a old K&R C compiler for free as part of the OS. I am sure that he is using this compiler to compile the one liner.

The old C preprocessor seems to set the symbol "unix" to be "1" for some odd reason. And I guess that ansi cleaned up the name space. I never noticed this before and now I wonder what old C compilers did on, say, an old IBM pc. Set unix to 0? Or leave unix undefined and set ms-dos to 1?

In any event, I got the one liner to work with ansi C by adding a line "#define unix 1".
Reply With Quote
  #5 (permalink)  
Old 04-03-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Stumble this Post!
I also got it compiled on a Linux machine with gcc.
I checked the Makefile, and I didn't see any extra options either that may be needed on some systems. I also checked the hint file again to see if some compilers didn't like it... The commands I used were:
$ gcc -o korn korn.c
$ ./korn
unix

What system are you using to compile? What compiler?
Reply With Quote
  #6 (permalink)  
Old 04-03-2002
Registered User
 

Join Date: Mar 2002
Location: Bangalore,Karnataka State,India
Posts: 18
Stumble this Post!
Nice

Hi,
It was nice and could't trace how it is printing.

Awesome..................

thank you,
K.S.SHARATH CHANDRA
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0