Wednesday, December 20, 2006

Code that speaks multiple languages

The following was taken from this page

Amazing! Sadly I can't make heads or tails out of the actual source code.

---------------Quote---------------------------

Obfuscated source code

On the first day of Christmas... (xmas2005.c)

The C program source code below prints a well-known Christmas poem. However, if you compile it in C++, it still works, but prints the poem with a slight modification. Even more, the program is also a valid Perl script, and prints the poem with a different small modification. If you want to print the poem, compile the source code with plain TeX! If you have problems copy-pasting it, you can download the [source code]. The original C source is part of the programming folklore ([source code]), the C++ port and the Perl and TeX versions are my own work. Here it is:

int qq=0;/*\def~#1~{}~{{=;{#*/
#include
#define q(q) char w=0,v[]=q
q("@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}eK"
"K#}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' '># }'+}##/*\_/
{\if(%)}newpath/Times-Roman findfont 20 scalefont setfont(
%%)pop 72 72 moveto(Just another PostScript hacker,)show((
t)}. t:-write('Just another Prolog hacker,'),nl,halt. :-t.
:-initialization(t). end_of_file. %)pop pop showpage(-: */
int main(){return 0&printf("Just another C%s hacker,\n",1%
sizeof'2'*2+"++");}/*\fi}\csname @gobble\endcsname{\egroup
\let\LaTeX\TeX\ifx}\if00\documentclass{article}\begin{doc%
ument}\fi Just another \LaTeX\ hacker,\end{document}|if 0;
/(J.*)\$sh(.*)"/,print"$1Perl$2$/"if$_.=q # hack the lang!
/
sh=sh;test $BASH_VERSION &&sh=bash;test $POSIXLY_CORRECT&&
sh=sh;test $ZSH_VERSION && sh=zsh;awk 'BEGIN{x="%c[A%c[K"
printf(x,27,27)}';echo "Just another $sh hacker," #)pop%*/

What is the language of the following program, and what does it print?

[/dlflg/=u]dZ[lflglblp*lqlg*+lpla*lqlf*+sfsgsbdsalblex]dscZ[lb%O]sdzzKsa
[nlaldx*lflg%O*sfdsalblex]dsuZ[.]zsqsssgsbnsfspselsn[lcxsslqdlp+spz+sqdx]dx

----------------End Quote------------------------

No comments: