#include #include #include #define comp 1 #define m 1024 typedef unsigned char ch; typedef struct {ch s[256]; ch i; ch j;} state; typedef void MV(ch *, state *, int); void initst(state *, ch *); MV mv, mv1; void pr(ch* s){ int j; for(j=0; j<256; ++j) printf("%s%02x", j&31?"":"\n", s[j]); printf("\n");} int main(int argc, char * * args){ void try(ch* k, MV mv, state * st){initst(st, (ch*)args[1]); {int jx=1<<17; while(jx--) mv(k, st, m);} // Histogram: if(0){int h[256]; {int j = 256; while (j--) h[j] = 0;} {int j = m; while(j--) ++h[k[j]];} {int j; for(j=0; j<256; ++j){if(!(j&15)) printf("\n %02x ", j); printf("%d ", h[j]);} printf("\n");}} // Test if state is still a permutation. {ch x[256]; {int j=256; while(j--) x[j]=1;} {int j=256; while(j--) x[st->s[j]]=0;} {int j=256; while(j--) if(x[j]) printf("No %d\n", j);}}} if(argc <2) exit(printf("Gimme key!!\n")); if(comp) { state st, st1; ch k[m], l[m]; try(k, mv, &st); try(l, mv1, &st1); {int j=m; while(j--) if(k[j]!=l[j]) printf("differs at %d\n", j);} {int j=256; while(j--) if(st.s[j]!=st1.s[j]) exit(printf("Differs at %d %02x %02x\n", j, st.s[j], st1.s[j]));} if(1) pr(st.s); printf("Good stuff\n");} return 0;}