Skip to content

Instantly share code, notes, and snippets.

@skeeto
Created May 9, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skeeto/45d825c01b00c10452634933d03e766d to your computer and use it in GitHub Desktop.
Save skeeto/45d825c01b00c10452634933d03e766d to your computer and use it in GitHub Desktop.
Mystery obfuscated C program (by yours truly)
/**** cc -Ofast x.c -lm && ./a.out | mpv --no-correct-pts --fps=60 --fs - ****/
#include<math.h>
#include<stdio.h>
#include<string.h>
#define L long
#define F float
#define T 4e-3f
#define X(x,y,z) 10*(y-x)
#define Y(x,y,z) x*(28-z)-y
#define Z(x,y,z) x*y-2.6666667f*z
typedef struct{L x,y;}P;typedef struct{F x,y,z;}C;P g(C p,F o,F e){F x=p.x*cosf
(o)-p.y*sinf(o),y=p.x*sinf(o)+p.y*cosf(o);return(P){20*x+960,20*(y*sinf(e)+(p.z
-28)*cosf(e))+540};}char B[02070][03600][3];D(L x,L y,L c){y<02070ul&&(B[y][x][
0]=c>>16)&&(B[y][x][1]=c>>8)&&(B[y][x][2]=c);}l(P a,P b,L c){L dx=fabsf(b.x-a.x
),dy=fabsf(b.y-a.y),sx=b.x<a.x?-1:1,sy=b.y<a.y?-1:1;if(dx>dy){L d=2*dy-dx,x,y=a
.y;for(x=a.x;x!=b.x;x+=sx){D(x,y,c);if(d>0){y+=sy;d-=2*dx;}d+=2*dy;}}else{L d=2
*dx-dy,x=a.x,y;for(y=a.y;y!=b.y;y+=sy){D(x,y,c);if(d>0){x+=sx;d-=2*dy;}d+=2*dx;
}}D(b.x,b.y,c);}C S(C s){F x=s.x,y=s.y,z=s.z,a=X(x,y,z),b=Y(x,y,z),c=Z(x,y,z),d
=x+a*T/2,e=y+b*T/2,f=z+c*T/2,g=X(d,e,f),h=Y(d,e,f),i=Z(d,e,f),j=x+g*T/2,k=y+h*T
/2,l=z+i*T/2,m=X(j,k,l),n=Y(j,k,l),o=Z(j,k,l),p=x+m*T,q=y+n*T,r=z+o*T,t=X(p,q,r
),u=Y(p,q,r),v=Z(p,q,r);s.x=x+(a+2*g+2*m+t)*T/6;s.y=y+(b+2*h+2*n+u)*T/6;s.z=z+(
c+2*i+2*o+v)*T/6;return s;}main(){L c[256],s=1;L n,i,j,h=0,t=0;static C p[256][
64];F o=0,v=0,e;for(i=0;i<256;i++){c[i]=(s*=0x9c15df3dul)>>8|0x404040;p[i][0].x
=p[i][0].y=25+i*1e-4f;}for(;;){memset(B,0,sizeof(B));n=(h+1)%64;if(n==t)t=(t+1)
%64;e=sinf(v)*0.5f;for(i=0;i<256;i++){p[i][n]=S(p[i][h]);for(j=h;j!=t;j=(j+64-1
)%64){P a=g(p[i][j],o,e),b=g(p[i][(j+64-1)%64],o,e);l(a,b,c[i]);}}h=n;puts("P6"
"\n1920\0401080\012255");fwrite(B,sizeof(B),1,stdout);v+=0.01f;o+=2.8285e-3f;}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment