PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : An alle C-Coder: The International Obfuscated C Code Contest


Exxtreme
2002-08-11, 17:00:41
An alle C-Progger. Kennt ihr das schon? Das nennt sich übersichtlicher und verständlich geschriebener Code.
;)
Guckst du hier:
http://www0.us.ioccc.org/years.html

Nur ein Beispiel:

typedef struct n{int a:3,
b:29;struct n*c;}t;t*
f();r(){}m(u)t*u;{t*w,*z;
z=u->c,q(z),u->b=z->b*10,
w=u->c=f(),w->a=1,w->c=z->
c;}t*k;g(u)t*u;{t*z,*v,*p,
*x;z=u->c,q(z),u->b=z->b,v
=z->c,z->a=2,x=z->c=f(),x
->a=3,x->b=2,p=x->c=f(),p
->c=f(),p->c->a=1,p->c->c=
v;}int i;h(u)t*u;{t*z,*v,*
w;int c,e;z=u->c,v=z->c,q(
v),c=u->b,e=v->b,u->b=z->b
,z->a=3,z->b=c+1,e+9>=c&&(
q(z),e=z->b,u->b+=e/c,w=f(
),w->b=e%c,w->c=z->c,u->c=
w);}int(*y[4])()={r,m,g,h};
char *sbrk();main(){t*e,*p,*o;
o=f(),o->c=o,o->b=1,e=f(),
e->a=2,p=e->c=f(),p->b=2,
p->c=o,q(e),e=e->c,(void)write
(1,"2.",2);for(;;e=e->c){q(e),
e->b=write(1,&e->b["0123456789"],
1);}}t*f(){return i||(i=1000,
k=(t*)sbrk(i*sizeof(t))),k+--i;
}q(p)t*p;{(*y[p->a])(p);}


Gruß
Alex

FragMaztah
2002-08-11, 17:09:24
printf ("???");

;D

Exxtreme
2002-08-11, 17:14:44
Man muss aber aufpassen. Es kann sein, daß der Code nicht läuft da man spezielle Make-Files braucht.

Gruß
Alex

DR.DEATH
2002-08-11, 21:44:29
Kann der Code ueberhaupt laufen ?
Fehlt nicht ne include Datei ? Oder laufen die ganzen Funktionen schon so ?

Und geht das : for(;;e=e->c) ueberhaupt ? die for Schleife braucht doch min. 3 Angaben. 1;2;3.

Xmas
2002-08-11, 21:58:12
Also wenn das lauffähiger C-Code ist, dann sind mir wohl einige C-Konstrukte bisher entgangen...

DR.DEATH,
das mit der for-Schleife geht schon. Nur ist das eine Endlosschleife, weil sie keine Bedingung hat.

ow
2002-08-11, 22:00:17
Originally posted by DR.DEATH
Kann der Code ueberhaupt laufen ?
Fehlt nicht ne include Datei ? Oder laufen die ganzen Funktionen schon so ?

Und geht das : for(;;e=e->c) ueberhaupt ? die for Schleife braucht doch min. 3 Angaben. 1;2;3.

Sind doch 3 Argumnte drin, getrennt mit Semikolon. Die ersten 2 Args sind halt leer. -> Endlosschleife.

ow
2002-08-11, 22:05:13
Originally posted by Xmas
Also wenn das lauffähiger C-Code ist, dann sind mir wohl einige C-Konstrukte bisher entgangen...

DR.DEATH,
das mit der for-Schleife geht schon. Nur ist das eine Endlosschleife, weil sie keine Bedingung hat.


ok, warst schneller als ich:D

Ich denke schon, dass das lauffähiger C-Code ist.

/offtopic:

hier ein perl-Skript zum extrahieren von DVDs (DeCSS), Quelle: http://www-2.cs.cmu.edu/~dst/DeCSS/Gallery/qrpff.pl



#!/usr/bin/perl
# 472-byte qrpff, Keith Winstein and Marc Horowitz <sipb-iap-dvd@mit.edu>
# MPEG 2 PS VOB file -> descrambled output on stdout.
# usage: perl -I <k1>:<k2>:<k3>:<k4>:<k5> qrpff
# where k1..k5 are the title key bytes in least to most-significant order

s''$/=\2048;while(<>){G=29;R=142;if((@a=unqT="C*",_)[20]&48){D=89;_=unqb24,qT,@
b=map{ord qB8,unqb8,qT,_^$a[--D]}@INC;s/...$/1$&/;Q=unqV,qb25,_;H=73;O=$b[4]<<9
|256|$b[3];Q=Q>>8^(P=(E=255)&(Q>>12^Q>>4^Q/8^Q))<<17,O=O>>8^(E&(F=(S=O>>14&7^O)
^S*8^S<<6))<<9,_=(map{U=_%16orE^=R^=110&(S=(unqT,"\xb\ntd\xbz\x14d")[_/16%8]);E
^=(72,@z=(64,72,G^=12*(U-2?0:S&17)),H^=_%64?12:0,@z)[_%8]}(16..271))[_]^((D>>=8
)+=P+(~F&E))for@a[128..$#a]}print+qT,@a}';s/[D-HO-U_]/\$$&/g;s/q/pack+/g;eval



wer so skripte schreibt hat IMO einen an der Waffel.;);):D

Exxtreme
2002-08-11, 22:27:55
Originally posted by ow
wer so skripte schreibt hat IMO einen an der Waffel.;);):D
Oder ist ein verkanntes Genie... :| ;)

Gruß
Alex

Magnum
2002-08-12, 00:13:13
OK, das hier ist vielleicht nicht ganz so kompliziert, wie das Zeugs oben! Aber wer sich traut kann ja mal sagen, was es ausgibt!

class P {
static int k = 2;
class Q {
int i; int j; int k = 1;
public Q() { i=3; j=5; k = this.k; }
}
class R extends Q {
int i; int j;
public R(int i) { this.j = 2+i; this.i = 2+j; }
}
int i=7; int j=9;
Q q; R r; Q s;
public P(int i) {
q = new Q(); q.i = this.i;
r = new R(i+this.i);
s = new R(0);
}
public static void main (String argv[]) {
P p = new P(1);
System.out.println(" "+p.i +" "+p.j +" "+p.k+
" "+p.q.i+" "+p.q.j+" "+p.q.k+
" "+p.r.i+" "+p.r.j+" "+p.r.k+
" "+p.s.i+" "+p.s.j+" "+p.s.k);
}
}

Wems nicht aufgefallen ist, es handelt sich hier um ganz normalen Java-Code! *g*

ow
2002-08-12, 09:36:07
Originally posted by Exxtreme

Oder ist ein verkanntes Genie... :| ;)

Gruß
Alex


Das liegt ja dicht beisammen. Genie und Wahnsinn.:D

zeckensack
2002-08-12, 13:43:42
Ich warte immer noch auf Kommentare zu meinem Stil:
http://www.forum-3dcenter.net/vbulletin/showthread.php?threadid=25110

:|

Exxtreme
2002-08-12, 15:23:22
Originally posted by zeckensack
Ich warte immer noch auf Kommentare zu meinem Stil:
http://www.forum-3dcenter.net/vbulletin/showthread.php?threadid=25110

:|
Eigentlich sehr sauber, IMHO. Meinem Stil sehr ähnlich. Aber Sachen wie:
"while (1)" sollte man vermeiden. Wenn was schief läuft, gibt's eine Endlosschleife. Dann lieber doch eine do-while-Schleife.

Gruß
Alex

Xmas
2002-08-12, 19:21:22
Originally posted by zeckensack
Ich warte immer noch auf Kommentare zu meinem Stil:
http://www.forum-3dcenter.net/vbulletin/showthread.php?threadid=25110
:|

Ich würde wohl mehr Leerzeichen verwenden ;)
Ansonsten muss ich in diesem Fall Exxtreme recht geben, die beiden while(1) hättest du problemlos ersetzen können. Es gibt aber Situationen, in denen man dann eine Bedingung zweimal prüfen müsste, und dann finde ich while(1) besser.

Ach, und noch etwas Code:

#include <stdio.h>
int main(){int k=5;float i,j,r,x,y=-16;while(puts(""),y++<15)for(x=0;x++<79;putchar(" .:-;!/>)|&IH%*#"[k & 15]))
for(i=k=r=0;j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}


Stammt übrigens von einem Mann der für seinen "Lärm" bekannt ist ;)
Ich habs ein ganz klein wenig angepasst.

GloomY
2002-08-15, 22:33:58
Interessant, was man so alles compilieren kann: ;)


void main() {

(*(void(*)())0)();

}

Bei Verständnisfragen kann ich eine mehrseitige Erklärung liefern, wenn's sein muss ;)

Xmas
2002-08-15, 23:02:51
Originally posted by GloomY
Interessant, was man so alles compilieren kann: ;)


void main() {

(*(void(*)())0)();

}

Bei Verständnisfragen kann ich eine mehrseitige Erklärung liefern, wenn's sein muss ;)
LOL, ich denke das würde (in Assembler) auf ein simples CALL [0] rauskommen, oder?

GloomY
2002-08-15, 23:27:32
Ja, genau :D

Respekt, ich hab' einige Tage daran rumgeknobelt und hab's nicht rausbekommen.
Für alle anderen hier mal die Lösung:

Quote aus "C Traps" von Andrew Koenig (AT&T Bell Laboratories):

I once talked to someone who was writing a C program that was going to run stand-alone in a small microprocessor. When this machine was switched on, the hardware would call the subroutine whose address was stored in location 0.
In order to simulate turning power on, we had to devise a C statement that would call this subroutine explicitly. After some thought, we came up with the following:

(*(void(*)())0)();

Expressions like these strike terror into the hearts of C programmers. They needn’t, though, because they can usually be constructed quite easily with the help of a single, simple rule: declare it the way you use it.
Every C variable declaration has two parts: a type and a list of stylized expressions that are expected to evaluate to that type. The simplest such expression is a variable:

float f, g;

indicates that the expressions f and g, when evaluated, will be of type float. Because the thing declared is an expression, parentheses may be used freely:

float ((f));

means that ((f)) evaluates to a float and therefore, by inference, that f is also a float. Similar logic applies to function and pointer types. For example,

float ff();

means that the expression ff() is a float, and therefore that ff is a function that returns a float. Analogously,

float *pf;

means that *pf is a float and therefore that pf is a pointer to a float. These forms combine in declarations the same way they do in expressions. Thus

float *g(), (*h)();

says that *g() and (*h)() are float expressions. Since () binds more tightly than *, *g() means
the same thing as *(g()): g is a function that returns a pointer to a float, and h is a pointer to a function
that returns a float.
Once we know how to declare a variable of a given type, it is easy to write a cast for that type: just remove the variable name and the semicolon from the declaration and enclose the whole thing in parentheses. Thus, since

float *g();

declares g to be a function returning a pointer to a float, (float *()) is a cast to that type.
Armed with this knowledge, we are now prepared to tackle (*(void(*)())0)(). We can analyze this statement in two parts. First, suppose that we have a variable fp that contains a function pointer and we want to call the function to which fp points. That is done this way:

(*fp)();

If fp is a pointer to a function, *fp is the function itself, so (*fp)() is the way to invoke it. The parentheses in (*fp) are essential because the expression would otherwise be interpreted as *(fp()). We have now reduced the problem to that of finding an appropriate expression to replace fp.
This problem is the second part of our analysis. If C could read our mind about types, we could write:

(*0)();

This doesn’t work because the * operator insists on having a pointer as its operand. Furthermore, the operand must be a pointer to a function so that the result of * can be called. Thus, we need to cast 0 into a type loosely described as ‘‘pointer to function returning void.’’
If fp is a pointer to a function returning void, then (*fp)() is a void value, and its declaration would look like this:

void (*fp)();

Thus, we could write:

void (*fp)();
(*fp)();

at the cost of declaring a dummy variable. But once we know how to declare the variable, we know how to cast a constant to that type: just drop the name from the variable declaration. Thus, we cast 0 to a ‘‘pointer to function returning void’’ by saying:

(void(*)())0

and we can now replace fp by (void(*)())0:

(*(void(*)())0)();

The semicolon on the end turns the expression into a statement.
At the time we tackled this problem, there was no such thing as a typedef declaration. Using it, we could have solved the problem more clearly:

typedef void (*funcptr)();
(* (funcptr) 0)();