All pastes #911547 Raw Edit

Untitled

public c v1 · immutable
·published 2008-02-20 19:59 UTC
rendered paste body
/*Custom encoding with numbers of chars matching the last word first, then therest of the word encoded with a 5-bit dictionary00-17 normal chars, except 0x01 which is an escape code for the lesser used chars (zjwfxvb-NDk)18 le19 te20 en21 an22 th23 ae24 on25 or\n26 on\n27 us\n28 a\n29 s\n30 e\n31\nThe order of the chars/sequences is shuffled to minimize the number of escaped chars in the data*/unsigned char* t=    "h!duoytrgsalceminplteataooouase" /* lookup for the first character */    "ennhenrns" /* lookup for the second character */            "zjwfxvb-NDk" /* lookup for escaped characters */    "removed";    /* ^^^^ the actual compressed data stream */char n[99]; /* word buffer */int b,c,i,j,o,r,s; /* some variables */int g(m) /* function for getting N bits from the data stream */{    if (s<m)    {        /* adds the next byte to the buffer if there's not enough bits */        b|=(t[i++]<<s);        s+=8;    }        /* extract bits from buffer */    r=b&((1<<m)-1);    b>>=m;    s-=m;    return r;}int main(){    for(j=1032,i=51;j--;)    {        /* gets number of bytes that's equal to the previous word */        o=g(1)?g(3):g(1)+2;                for(;;)        {            /* if the read code is the escape code, get char from escape table */            if((c=g(5))==1)                n[o++]=t[g(4)+38];            else            {                /* if the code isn't 31, add char from lookup */                if(c<31)                     n[o++]=t[c];                                    /* if the code is between 18 and 27, add a second char from lookup */                if(c>17&&c<28)                    n[o++]=t[c+12];                                /* if the code is 25 or more, add null, uppercase first letter, then break */                if(c>24)                {                    n[o++]=0;                    n[0]&=223;                    break;                }            }        }                puts(n);    }        exit(0);}