// Node Code typedef unsigned short sh; typedef unsigned int ui; typedef unsigned int word; // perhaps long int. typedef struct {ui money; sh pls; char wc; char oc; word wrds[0];} SS; #define bpw (sizeof(word)*8) // static word rotr4(word s){return (s>>4) | (s<<(bpw-4));} static word rotl4(word s){return (s<<4) | (s>>(bpw-4));} word ref(word w){int j = bpw/4; word r = 0; while(j--) {r = (r<<4) | w&15; w >>= 4;} return r;} void reflect (SS * s){s->oc = bpw/4 - s->oc; int fw = !!(s->oc&((bpw/4)-1)); // where to start swapping words if (fw) s->wrds[0] = ref(s->wrds[0]); int lw = s->wc-1; while(fwwrds[fw]; s->wrds[fw] = ref(s->wrds[lw]); s->wrds[lw] = ref(t); ++fw; --lw;} if(fw==lw) s->wrds[fw] = ref(s->wrds[fw]);} int gt(SS * s, int rto){int oc; {word fw = rotl4(s->wrds[0]); oc = fw&15; s->wrds[0] = (fw&~15) | rto;} if(!(s->oc&15)) {s->oc = bpw/4-1; word ofw = s->wrds[0]; {int c = s->wc; if(c>1) {for(int j=1; jwrds[j-1] = s->wrds[j]; s->wrds[c-1] = ofw;}}} else --s->oc; return oc;} #include #include void ps(char * m, SS * s){ printf("%s, wc=%3d, oc=%3X ", m, s->wc, s->oc); for (int j=0; jwc; ++j) printf(" %08X", s->wrds[j]); printf("\n");} SS * init(int wc){SS * ss = (SS*)malloc(sizeof(SS)+wc*(bpw/8)); ss->wc = wc; ss->oc = bpw/4-1; for(int j=0; jwrds[j] = random(); return ss;} int main(){printf("sz=%d\n", (int)&(((SS*)0)->wrds[0])); {SS * ss = init(3); ps("before", ss); for(int y=0; y<3*8; ++y) printf("%X ", gt(ss, (y>>1)&15)); ps("\nafter", ss); free(ss);} {SS * ss = init(3); ps("B1", ss); reflect(ss); ps("B2", ss);} {SS * ss = init(3); ps("C1", ss); for(int y=0; y<11; ++y) printf("%X ", gt(ss, y&15)); ps("\nC2", ss); reflect(ss); ps("C3", ss); reflect(ss); ps("C4", ss); for(int y=0; y<11; ++y) printf("%X ", gt(ss, y&15)); ps("\nC5", ss);} return 0;} //void NewPacket(void * pp){char head = *pp; ...}