// http://en.wikipedia.org/wiki/RC4_(cipher) typedef unsigned char ch; typedef struct {ch s[256]; ch i; ch j;} state; void mv(ch * out, state * s, int n){ ch i = s->i, j = s->j; int z; for(z = 0; zs[++i]; j += si; ch sj = s->s[j]; s->s[i]=sj; s->s[j]=si; out[z] = s->s[255&(sj + si)];} s->i = i; s->j = j;} #include void initst(state * st, ch * key) {{int j=256; while(j--) st->s[j] = j;} {int i, j=0, len = strlen((char*)key); for(i=0; i<256; ++i) {j = (j + st->s[i] + key[i%len])&255; {ch t=st->s[i]; st->s[i]=st->s[j]; st->s[j]=t;}} st->i = st->j = 0;}}