12 days of christmas

obfuscated C

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 12029 Views - Last Post: 30 May 2009 - 03:12 PM Rate Topic: -----

#1 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

12 days of christmas

Posted 29 May 2009 - 01:24 PM

I snagged this Obfuscated C code which prints out the 12 Days Of Christmas song, however, WTF?! I don't see how any of this can print out the actual verses and everything correctly it's just a bunch of symbols. Crazy. Anyone wanna help in breaking this down and figuring out it means?

I know the point of the Obfuscated C is to keep people from reading your code, however, this is ridic-uh-lous.

#include <stdio.h>
main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
}'+}##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
  :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}



Is This A Good Question/Topic? 0
  • +

Replies To: 12 days of christmas

#2 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: 12 days of christmas

Posted 29 May 2009 - 01:29 PM

:/ Ah! I'll let someone else get this one... :lol:
Was This Post Helpful? 0
  • +
  • -

#3 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 29 May 2009 - 01:31 PM

Haha, yeah, I have been on and off looking at this through the past week and a half, and still, I got nothing. It is quite obfuscated... well i'd be pretty pissed off if I were on a project with someone and for their portion they handed this to me, impressed, but pissed. I guess it could cause job security as they're the only person who knows how it works. LoL.
Was This Post Helpful? 0
  • +
  • -

#4 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: 12 days of christmas

Posted 29 May 2009 - 01:40 PM

True. Could contains Skynet information though. 0_0
Was This Post Helpful? 0
  • +
  • -

#5 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 29 May 2009 - 02:10 PM

LoL. Skynet. They couldn't find a elephant in a house if they tried.
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: 12 days of christmas

Posted 29 May 2009 - 02:14 PM

Well I believe that this code requires an older compiler. Usually if I can get them to compile that I have made some headway into deciphering them. Many of the IOCCC entries just don't compile on modern compilers.

Did you see my pitiful attempt at obfuscation?

I was trying to get it really small but this is where I stopped messing with it:
#include <iostream>
//by me
#define O int
#define R return
#define A void
using namespace std;

				A
			   o(O
			  s) {O
			 I=2,l=1
			,m=1+I*s,
		   i=0,c=(m-l)
		  /I;while(l>0)
		 { cout << (  i 
		<c +l ? ( i++ <c
	   ? ' ' :'*' ) : (i=
		0, l+=(l ==m? I=
		 -I :I),c=(m -l
		   )/2,'\n'));
			}}O main(
			 ){for(O
			  i=0;i
			   <15
			   ;

i++ ) {o(i);}R 0;}

Was This Post Helpful? 0
  • +
  • -

#7 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: 12 days of christmas

Posted 29 May 2009 - 02:21 PM

:cry2:
Was This Post Helpful? 0
  • +
  • -

#8 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 29 May 2009 - 06:30 PM

Not bad at all, I just don't understand it cause it compiles fine with no other header files or anything else required, just a simple copy, paste, compile and run. I don't get it, it's absolutely ludicrous.
Was This Post Helpful? 0
  • +
  • -

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: 12 days of christmas

Posted 29 May 2009 - 07:07 PM

My code is really just simple substitution.

I started by trying to make my code as small as possible by substituting meaningful variable names with single letters. Then I replaced if's with ?: and creatively used the comma operator. I used a couple of macros to shorten some of the common symbols.

There are many other things that you can do. The code that you presented earlier uses recursion to mask what it is doing. Plus in previous versions of the C standard things were a little more lax (like not having to give a return type) and that code obviously makes use of some of these features.

Some obfuscated code includes misleading information such as functions that don't really do anything, or functions that are defined inside of comments or macros.

Preprocessor metaprogramming often comes into play. especially since you can define and undefine and redefine the same symbol so just when the follower thinks they understand what something does it changes.

One of the big tools is to use misdirection -- make the user think they are looking at a string when in fact the quotation marks are part of two macros and so only seem to be delimiting a string.

Sometimes the magic is actually in the make file which defines 1 macro which expands to flash out the real code -- since the macro is not in the code it form a sort of "key" to compiling the program.
Was This Post Helpful? 0
  • +
  • -

#10 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 29 May 2009 - 07:24 PM

Oh, so that is most likely what is happening in the program above than huh? Cause I made an obfuscated C++ program but I had to make a defines.h file to include all the things I had defined.
Was This Post Helpful? 0
  • +
  • -

#11 Ambercroft  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 129
  • Joined: 05-January 07

Re: 12 days of christmas

Posted 30 May 2009 - 08:06 AM

That code is pretty cool.

Compiled with only one warning of 'return type defaults to "int"'.

I used gcc 4.1.2


B)
Was This Post Helpful? 0
  • +
  • -

#12 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 30 May 2009 - 09:54 AM

Yeah, it's neat huh? I get no errors, but I mean, it still compiles and I can't even figure out how a word is designed, let alone the entire song. Its just a paragraph of random cahracters.
Was This Post Helpful? 0
  • +
  • -

#13 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: 12 days of christmas

Posted 30 May 2009 - 10:34 AM

well I believe the first clue is the Unix format for main():
int main(int , char **, char **); - I have intentionally remove the names because in this program those will be meaningless (except for the first use of main).

Also note that the string in the middle is NOT (as I initially thought) some kind of preprocessor magic. The string is encoded (at least from what I got from Wikipedia).
Was This Post Helpful? 0
  • +
  • -

#14 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: 12 days of christmas

Posted 30 May 2009 - 11:02 AM

Oh very nice.
Was This Post Helpful? 0
  • +
  • -

#15 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: 12 days of christmas

Posted 30 May 2009 - 11:44 AM

Damn, that's amazing!!

This post has been edited by apw5020: 30 May 2009 - 11:44 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2