Signature program

Signature program

A signature program is a small, highly condensed piece of code (commonly written in C or C++), usually three or fewer lines in length which when compiled produces an interesting pattern or function that is not always obvious from the code.

Signature programs are generally found in the signature section of user posts in forums, messages etc, particularly in technically oriented websites such as Slashdot.

Optimisation and example

In order for the program, often of great complexity, which would usually be represented with many lines of code, to fit into a single line, many compression techniques are used. The following program prints out an ASCII art version of the Sierpinski triangle fractal, shown in the illustration:

main(c,r){for(r=32;r;) printf(++c>31?c=!r--," ":c

An uncompressed "spelt out" version of this program may look like this:


#include int main(){

int c = 0; int r = 32;

while (r != 0) {

c = c + 1; if (c > 31) { c = !r; /* same as c = 0 */ r = r - 1; printf(" "); } else { if (c < r) { printf(" "); } else { if ((~c & r) != 0) { printf(" `"); } else { printf(" #"); } } }

Here we can see that many portions of code are missing from the signature program, most obviously the lack of #include , no return type of main() as well as the use of non-standard main(c,r). The ? operator plays a vital role in reducing the overall size of the program, allowing a single expression to replace the sizeable number of if/else logical conditionals. Size is also dramatically reduced by removing all whitespace and line breaks.

Signature programs often make use of undocumented or lesser-known features or quirks in a particular compiler which allow for smaller overall program size, as well as obscurity.

Obfuscated programs

A common theme in signature programs is to make the code so obfuscated that the outcome and purpose of the program is not apparent, at least to start with, or that the programs are masked to give the impression that the program performs one function when it actually does something completely different, sometimes with alarming or embarrassing outcomes.

MinRay

Computer graphics expert [http://www.cs.cmu.edu/~ph/ Paul Heckbert] took the condensed program concept to a new level by legibly printing the results of a contest for a minimal ray tracing program on the back of a business card. Code from the "Graphics Gems IV" [http://www.GraphicsGems.org/gemsiv/minray/ repository] is reproduced here. typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{ vec cen,color;double rad,kd,ks,kt,kl,ir}*s,*best,sph [] ={0.,6.,.5,1.,1.,1.,.9, .05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8, 1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,-3.,12.,.8,1., 1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A ,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a* A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt( vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s= sph+5;while(s-->sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s ->rad,u=u>0?sqrt(u):1e31,u=b-u>1e-7?b-u:b+u,tmin=u>=1e-7&&uir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen )));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->sph)if((e=l ->kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)=l)color=vcomb(e ,l->color,color);U=s->color;color.x*=U.x;color.y*=U.y;color.z*=U.z;e=1-eta* eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt (e),N,black))):black,vcomb(s->ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd, color,vcomb(s->kl,U,black))));}main(){printf("%d %d ",32,32);while(yx<32*32) U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/114.5915590261),U=vcomb(255., trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f ",U);}/*minray!*/While this is uncomfortably long for a signature, it is remarkably short (albeit inefficient) for a ray-tracer.

See also

*Programming
*Obfuscated code
*C Programming Language
*C++

External links

* [http://www.iwriteiam.nl/SigProg.html A huge resource for signature programs]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Signature Theatre — is a regional theater company based in Arlington, Virginia.. [ [http://www.jlpaf.org/grant.html Larson Awards] ] Cameron Mackintosh, Terrence McNally, John Kander, and Fred Ebb are among the talents that have presented works here. Since 1991,… …   Wikipedia

  • Signature image processing — (SIP) is a technology for analysing electrical data collected from welding processes usually automated, robotic welding. In developed countries, some form of welding is used in more than 50% of manufactured products. Acceptable welding requires… …   Wikipedia

  • Signature Theatre Company — The Signature Theatre Company is a not for profit theatre company in New York City dedicated to honoring and celebrating the work of the playwright. Founded in 1991 by Jim Houghton, Signature provides established playwrights with opportunities to …   Wikipedia

  • Signature block — For the use of signatures in Wikipedia, see Wikipedia:Signatures. A signature block (often abbreviated as signature, sig block, sig file, .sig, dot sig, siggy, or just sig) is a block of text automatically appended at the bottom of an e mail… …   Wikipedia

  • Signature BioScience — Infobox Company name = Signature BioScience foundation = 1998 location city = San Francisco (initially Hayward) location country = USA location = key people = Mark McDade industry = BioPharmaceutical Discovery and Development dissolved =… …   Wikipedia

  • Signature Guarantee — A form of authentication issued by a bank or other financial institution that verifies the legitimacy of a signature and the signatory s overall request. This type of guarantee is often used in situations where financial instruments are being… …   Investment dictionary

  • signature — /ˈsɪgnətʃə / (say signuhchuh) noun 1. a person s name, or a mark representing it, as signed or written by that person or by a deputy, as in subscribing a letter or other document. 2. the act of signing a document. 3. Music a sign or set of signs… …  

  • signature tune — noun a melody used to identify a performer or a dance band or radio/tv program • Syn: ↑signature, ↑theme song • Hypernyms: ↑tune, ↑melody, ↑air, ↑strain, ↑melodic line, ↑ …   Useful english dictionary

  • signature — signatureless, adj. /sig neuh cheuhr, choor /, n. 1. a person s name, or a mark representing it, as signed personally or by deputy, as in subscribing a letter or other document. 2. the act of signing a document. 3. Music. a sign or set of signs… …   Universalium

  • signature — sig•na•ture [[t]ˈsɪg nə tʃər, ˌtʃʊər[/t]] n. 1) a person s name, or a mark representing it, as signed personally or by deputy, as in subscribing a letter or other document 2) the act of signing a document 3) mad mus a sign or set of signs at the… …   From formal English to slang

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”