Coding Challenge #4: Make an obfuscated 4-ch logo (30)

1 Name: #!/usr/bin/anonymous : 2006-04-21 21:36 ID:bBAXtCdY

As suggested by http://4-ch.net/code/kareha.pl/1144364264/23,26, here is the fourth 4-ch coding challenge: Output a 4-ch logo, in any form, with code that is as hard to understand as possible!

Any language is accepted, but reasonably cross-platform code that can be easily tested is preferred, as is well-known language that more people are able to understand - obfuscating by using a language nobody knows isn't all that clever, unless just making it is clever in itself.

I suggest we play this by posting pieces of code as entries, and then try to understand everybody else's code. If somebody does understand your code, and can post a clear explanation of how it works, you lose!

The form the output can take is anything you can think up. Text, ASCII, bitmaps, 3D graphics, anything goes. The main thing is that it should be hard to understand how or why the program produces this output!

2 Name: #!/usr/bin/anonymous : 2006-04-21 21:41 ID:bBAXtCdY

I'll repost my entry here from the other thread:

@r=d('<,=@;,>B;,?<<;,<<<;,<<;,C=@:,C=A:,<<<<;<,<<<<:::::,<<<<<::=:,<B'.
'<<::::,<@<<:::<:,<,<,<');@c=d(';,<,=,>,<;,<;,I,I,I,;,,;,<;<,=;=,=;=,'.
';;,;;,;;,<<,<<,;;,,E,E,@,;,;,@,@,?,,:,,>,:,:,=,,<,:::,:::,;:,,:,@,:');
@f=map "." x@c,@r;for(a,b){for(0..$#r){foreach$c(0..$#c){$n=x ((join"",
map{substr$f [$_],$c,1}(0..$#r)),@{$c [$c]});(substr$f[$_],$c,1)=substr
$n,$_,1for(0..$#r);}$f [$_]=x($f[$_],@{$r[$_]});}}printf"$_\n"for@f;sub
x{$f=shift;my$l=length$f;return" "x$l if!@_;return c (grep m/^$f/,map{(
" "x$_).(X x$_[0]).(" "x($l-$_[0]-$_))}(0..$l-$_[0]))if@_==1;my$r+=($_+
1)for@_;$n=shift;return c(grep length$_==$l,map$$_[0].x($$_[2],@_),grep
$$_[0]=~/^$$_[1]/,map[(" " x$_).(X x$n)." ",$f=~/(.{$_}.{$n}.)(.*)/],(0
..$l-$r-1))}sub c{$r=shift;$r=~s/(.)/(substr$_, pos$r, 1)eq$1?$1:'.'/ge
for@_;$r}sub d{map[map ord($_)-57,/./g],split',',$_[0]}

I'll even post a first hint for those who want to try and crack it: Move the print statement two loops in to see the algorithm work:

@r=d('<,=@;,>B;,?<<;,<<<;,<<;,C=@:,C=A:,<<<<;<,<<<<:::::,<<<<<::=:,<B'.
'<<::::,<@<<:::<:,<,<,<');@c=d(';,<,=,>,<;,<;,I,I,I,;,,;,<;<,=;=,=;=,'.
';;,;;,;;,<<,<<,;;,,E,E,@,;,;,@,@,?,,:,,>,:,:,=,,<,:::,:::,;:,,:,@,:');
@f=map "." x@c,@r;for(a,b){for(0..$#r){foreach$c(0..$#c){$n=x ((join"",
map{substr$f [$_],$c,1}(0..$#r)),@{$c [$c]});(substr$f[$_],$c,1)=substr
$n,$_,1for(0..$#r);}$f [$_]=x($f[$_],@{$r[$_]});printf"$_\n"for@f;}}sub
x{$f=shift;my$l=length$f;return" "x$l if!@_;return c (grep m/^$f/,map{(
" "x$_).(X x$_[0]).(" "x($l-$_[0]-$_))}(0..$l-$_[0]))if@_==1;my$r+=($_+
1)for@_;$n=shift;return c(grep length$_==$l,map$$_[0].x($$_[2],@_),grep
$$_[0]=~/^$$_[1]/,map[(" " x$_).(X x$n)." ",$f=~/(.{$_}.{$n}.)(.*)/],(0
..$l-$r-1))}sub c{$r=shift;$r=~s/(.)/(substr$_, pos$r, 1)eq$1?$1:'.'/ge
for@_;$r}sub d{map[map ord($_)-57,/./g],split',',$_[0]}

3 Name: #!/usr/bin/anonymous : 2006-04-22 18:16 ID:Heaven

someone needs to write an obfuscated java program that outputs the 4-ch logo as a .wmf file.
i'd do it, but i've forgotten all the java i learned when i was in high school.

4 Name: #!/usr/bin/anonymous : 2006-04-24 14:51 ID:fMlkPbXp

>>2
Bump for justice. I think I'm getting a handle on what's going on here, but it'll be a looong time before I know it intimately enough to explain it clearly. Top stuff.

5 Name: #!/usr/bin/anonymous : 2006-04-26 13:23 ID:icFgoQJY

what fun

6 Name: #!/usr/bin/anonymous : 2006-08-15 20:57 ID:bBAXtCdY

Come on, people! This Coding Challenge needs some action!

Here's something much shorter and simpler:

@b=d(9015634002495);@a=d(7479707035031);
sub d{$c=-1;map {("_"x$_)!~/^(..+)\1+$/&&++$c&&!($_[0]%$_)?($c):()}(2..222);}
print map{lc chr$b[$_]+44}map{$_-$s+($s=$_)-$s-1}@a;print"\n";

I have to admit that I stole the best part from another Perl contest somewhere, though. See if you can guess which part that is!

7 Name: #!/usr/bin/anonymous : 2006-08-16 03:34 ID:irINoLfl

function
w(o,r,l,d,z)
{
if (l<=r.length)
{
o+=z(d);
return(w(o,r,++l,d+r[--l],z));
} else {
return(o);
}
}

var omg_hax=new Array(7);
omg_hax[-(omg_hax[3]=-58)-(omg_hax[1]=((omg_hax[0]=-7)+1)*(omg_hax[(omg_hax[6]=(omg_hax[2]=5)*3)/3]=-9))]=64;

var p = document.createElement("p");
var h=document.createTextNode(w('',omg_hax,0,52,function(n){return(eval(unescape('%53%74%72%69%6e%67%2e%66%72%6f%6d%43%68%61%72%43%6f%64%65%28')+n+unescape('%29%3b')));}));
p.appendChild(h);
document.body.appendChild(p);

8 Name: #!/usr/bin/anonymous : 2006-08-16 12:44 ID:P1ratiUD

The statement that initializes omg_hax evaluates as:

omg_hax[3]=-58;
omg_hax[0]=-7;
omg_hax[2]=5;
omg_hax[6]=omg_hax[2]*3; // 5*3 -> 15
omg_hax[omg_hax[6]/3]=-9;
// omg_hax[15/3]=-9
// omg_hax[5]=-9
omg_hax[1]=(omg_hax[0]+1)*(omg_hax[5]) // (-7+1)*-9 = 54
omg_hax[-omg_hax[3]-omg_hax[1]]=64;
// omg_hax[-(-58)-54]=64
// omg_hax[4]=64;

That is, omg_hax ends up having the value -7,54,5,-58,64,-9,15.

function(n){return(eval(unescape('%53%74%72%69%6e%67%2e%66%72%6f%6d%43%68%61%72%43%6f%64%65%28')+n+unescape('%29%3b')));} creates an anonymous function that just does String.fromCharCode() on its argument.

So we create a text element with the result of w('',[-7,54,5,-58,64,-9,15],0,52,fromCharCode).

w(o,r,l,d,z) is a recursive function that builds its result in o, and uses l as a counter. It is functionally equivalent to:

o='';
r=[-7,54,5,-58,64,-9,15];
d=52;

for(l=0;l<=r.length;l++)
{
o+=String.fromCharCode(d);
d+=r[l];
}

Thus, omg_hax encodes the differences in ASCII values between the successive characters of "4-ch.net", assuming the first character is "52" (that is, the '4' in 4-ch).

9 Name: #!/usr/bin/anonymous : 2006-08-16 15:02 ID:P1ratiUD

Oh, and if we're playing with Javascript and HTML, how about this simple little trick?

<html><head><style>
body { background: #000; color: #fff; font-family: sans-serif; }
b { position: absolute };
</style></head><body>
<div style="position:absolute;left:300px;top:300px">
<b>4</b><b>-</b><b>c</b><b>h</b><b>.</b><b>n</b><b>e</b><b>t</b><b> </b><b> </b>
</div><script>
x=document.getElementsByTagName("b");setInterval(function() {
x[i].style.left=(e-=f*(a-=(b+=a/64)/64))+(g-=h*(c-=(d+=c/45)/45))+"px";
x[i].style.top=((f+=e*a)+(h+=g*c))+"px";i=(i+9)%10;},40);
</script></body>

10 Name: #!/usr/bin/anonymous : 2006-08-16 16:03 ID:bBAXtCdY

What the hell, a line disappeared from >>9 for some reason. Here's a version that should actually work:

<html><head><style>
body { background: #000; color: #fff; font-family: sans-serif; }
b { position: absolute }
</style></head><body>
<div style="position:absolute;left:300px;top:300px">
<b>4</b><b>-</b><b>c</b><b>h</b><b>.</b><b>n</b><b>e</b><b>t</b><b> </b><b> </b>
</div><script>
a=0,b=0.17,c=0,d=0.3,e=0,f=-100,g=0,h=-50,i=0;
x=document.getElementsByTagName("b");setInterval(function() {
x[i].style.left=(e-=f*(a-=(b+=a/64)/64))+(g-=h*(c-=(d+=c/45)/45))+"px";
x[i].style.top=((f+=e*a)+(h+=g*c))+"px";i=(i+9)%10;},40);
</script></body>

11 Name: #!/usr/bin/anonymous : 2006-08-18 21:06 ID:Heaven

10 PRINT "4-ch.net | Now that's DQN quality!"
20 GOTO 10

12 Name: #!/usr/bin/anonymous : 2006-09-01 22:59 ID:z2YPX6MU

function what(a,b,c,d,e){
if(e<=a.length){
b[e]=d;
return(what(a,b,c,c(d,a,e),++e));
}else return(b);}
a=new Array()
a[0]=[1933];
a[1]=new Array();
a[2]=new Array();
a[3]=new Array();
a[4]=new Array();
a[5]=new Array();
a[6]=new Array();
a[7]=new Array();
a[8]=new Array();
b=new Array()
b[0]=[3349];
b[1]=new Array();
b[2]=new Array();
b[3]=new Array();
b[4]=new Array();
b[5]=new Array();
b[6]=new Array();
c=[-1175,-17,593,-792,785,-682];
for(i=0;i<6;i++)
what(b[i],b[i+1],function(a,b,c){return(a+b[c]);},c[i],0);
for(i=0;i<7;i++)
what(a[i],a[i+1],function(a,b,c){return(a+b[c]);},b[6][i],0);
a[7][8]=8238;
what(a[7],a[8],function(a,b,c){return(String.fromCharCode(b[c])+a);},'',0);
p=document.createElement("p");
h=document.createTextNode(a[8][9]);
p.appendChild(h);
document.body.appendChild(p);

13 Name: #!/usr/bin/anonymous : 2006-09-03 14:23 ID:bBAXtCdY

>>12

what() is used for two purposes: Decoding a list of integers stored as the differences between sucessive values, and building a string out of charater codes.

The program builds a list of character codes by successively applications of a difference decoder. This is done in two passes. c contains the initial values for the first set of passes, and creates a list of initial values for the second set, that creates the list of character codes.

The string is built backwards, and then displayed the right way with a unicode right-to-left override.

14 Name: #!/usr/bin/anonymous : 2006-09-03 16:47 ID:Heaven

>>13
fails for not explaining how what() works.
also fails for not explaining why it breaks in firefox if you try to add another pass using an array called d for the initial values and using c for the first pass.

15 Name: #!/usr/bin/anonymous : 2006-09-03 17:13 ID:Heaven

>>14

Oh, I though what() was simple enough anyway. It's just the equivalent of a for(i=0;i<=a.length;i++) loop that applies c to d and a[i], and stores the result in b (although not in that order).

I have no idea about the second, though.

16 Name: #!/usr/bin/anonymous : 2006-11-03 15:09 ID:irINoLfl

function ms(){
var h=document.createElement('span');
h.style.fontFamily='sans-serif';
h.style.fontSize='xx-large';
h.style.background='white';
return h;
}
var s2=ms();
s2.style.color='blue';
s2.style.border='1px solid gray';
var h=1;
s2.appendChild(document.createTextNode((function(h){
h=h<<1;
window.h=arguments.callee;
return h!=1<<2?arguments.callee(h):h
})(h)));
var s1=ms();
s1.style.color='gray';
s1.appendChild(document.createTextNode((function(h){
for(var i=0;i<h.length;i++) {
if(h[i]!=undefined&&(h[i]-h[i]==0)) {
h[i]=(window.h.toString()[h[i]]);
return arguments.callee(h);
}
}
return h;
})([4,11,58,3,53,62,60]).join('')));
var b=document.createElement('body');
b.appendChild(s1);
b.appendChild(s2);
h='data:text/html,'+b.innerHTML;
location.href=h

17 Name: #!/usr/bin/anonymous : 2006-11-03 16:31 ID:Heaven

>>16
works in firefox, but not in konqueror or opera.

18 Name: #!/usr/bin/anonymous : 2006-11-04 14:57 ID:Heaven

modified version of >>16 that works in firefox (tested in 1.5.0.7), konqueror (tested in 3.5.4, text is unformatted), opera (tested in 9.00), and IE (tested in 7.0): http://thinkindifferent.net/~hotaru/channel4.html

19 Name: #!/usr/bin/anonymous : 2006-11-04 20:40 ID:Heaven

>>18
broken in safari

20 Name: #!/usr/bin/anonymous : 2006-11-05 00:15 ID:Heaven

>>19
Is that a joke, or is JavaScript seriously that broken?

21 Name: #!/usr/bin/anonymous : 2006-11-05 04:57 ID:Heaven

>>20
the only brokenness in javascript that shows up here is that the result of using a function as a string is just defined to be the source code of the function. and since white space doesn't matter in javascript, 'h'+alert can result in different strings in different browsers.
"hfunction alert() { [native code] }" in firefox.
"h function alert() { [native code] } " in IE (and i'm assuming the other browsers listed in >>18 return the same string).
that's why the script in >>18 adds 'h ' instead of 'h' for gecko-based browsers.

IE apparently doesn't support data: urls, so the script in >>18 uses a javascript: url if it's being run in IE (or some other browser with MSIE in the useragent string).

i'm guessing safari either returns the same string as firefox (in which case it would say "thlccre" instead of channel), or >>18 has modified the useragent string of safari so that it includes "rv:" ("nh uula" instead of "channel") or "MSIE" (uses a (probably broken) javascript: url instead of a data: url). or safari is horribly broken. or >>19 is lying. i don't have an os x machine here to test it on, so i don't know.

22 Name: #!/usr/bin/anonymous : 2006-11-05 10:14 ID:Heaven

checked more carefully. it actually says "chhnnhh4" in safari, does nothing in shiira (my main browser that i naively assumed would behave identically to safari, which it is based on) and works properly in camino

23 Name: #!/usr/bin/anonymous : 2006-11-05 11:11 ID:Heaven

> "chhnnhh4" in safari

wow. does safari support javascript: urls?
if so, would you mind telling me what it says if you put javascript:'"h'+alert+'"'; in the address bar?
also, does shiira support data: urls?

24 Name: #!/usr/bin/anonymous : 2006-11-06 07:42 ID:2PQLYlQ2

>javascript:'"h'+alert+'"';

(does nothing... doesn't look valid anyway? that's just a string...)

>javascript:window.alert('h'+alert+'');

alerts:

h[function]

25 Name: #!/usr/bin/anonymous : 2006-11-06 17:24 ID:Heaven

>>24
that's interesting...
what about javascript:alert(alert.toString());?
i'd expect alert(alert.toString()) and alert(alert) to give the same result, and if they do then safari's Function.prototype.toString() is broken. [function] definitely does not have the syntax of a function declaration.

from http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf:

> Function.prototype.toString ( )
> An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation string is implementation-dependent. The toString function is not generic; it throws a TypeError exception if its this value is not a Function object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

26 Name: #!/usr/bin/anonymous : 2006-11-07 10:50 ID:2PQLYlQ2

> javascript:function foo() { alert('hi') }; alert(foo);

does as expected - alerts with the source of foo.

>javascript:function foo(){alert('hi')}; alert(foo.toString());

does so too

>javascript:function foo(){alert('hi')}; alert(foo.toString);

alerts "(Internal Function)" rather than the source code of toString (different than a non-builtin function, but reasonable -- since the builtin probably isn't implemented in JS...)

>javascript:function foo(){alert('hi')}; alert(alert);

alerts "[function]" as discussed

>javascript:function foo(){alert('hi')}; alert(alert.toString);

alerts "undefined" -- guess alert doesn't have stringification, which makes sense since since it's probably not implemented in JS itself

>javascript:function foo(){alert('hi')}; alert(foo.toString.toString);

alerts "(Internal Function)", curiously enough -- alert doesn't have a stringification, but the stringification function does?

>javascript:function foo(){alert('hi')}; alert(foo.toString.toString());

also alerts "(internal function)", but note it's being called this time rather than referenced

i'm not sure what's up with alert, or why it's acting differently to other internal functions. but in any case, it would appear that Safari's interpreting stringification of internal functions (for however it defines internal) as being different from that of user-defined functions.

27 Name: #!/usr/bin/anonymous : 2006-11-07 14:32 ID:Heaven

> >javascript:function foo(){alert('hi')}; alert(alert.toString);
> alerts "undefined" -- guess alert doesn't have stringification, which makes sense since since it's probably not implemented in JS itself

except that alert is a function, so alert.toString() should return some string with the correct function declaration syntax. if it doesn't it's broken (doesn't follow the ecmascript specification).

28 Name: #!/usr/bin/anonymous : 2006-11-08 08:12 ID:Heaven

shrug don't tell me that; I'm hardly about to do something about it ;)

29 Name: #!/usr/bin/anonymous : 2006-11-08 19:23 ID:Heaven

i'd file a bug report but shitty bugzilla wants me to create an account first and i don't care enough to do that.

30 Name: #!/usr/bin/anonymous : 2006-11-09 07:50 ID:Heaven

see what i mean?

This thread has been closed. You cannot post in this thread any longer.