//係数の逆元を返す unsigned char oinv(unsigned char a){ int i; for(i=0;i<M;i++){ if(gf[mlt(fg[a],i)]==1) return (unsigned char)i; } }
//多項式に値を代入した結果の数値 unsigned char trace(OP f,unsigned char x){ int i; unsigned char u=0; for(i=0;i<deg(o2v(f))+1;i++) u^=gf[mlt(fg[f.t[i].a],mltn(f.t[i].n,fg[x]))]; return u; }
void TextNode::_finalPass(Aligner& rd) { float scaleFactor = rd.getScale(); int offsetY = rd.bounds.pos.y; for (size_t i = 0; i < _data.size(); ++i) { Symbol& s = _data[i]; s.y += offsetY; if (s.gl.texture) s.destRect = RectF(mlt(s.x, scaleFactor), mlt(s.y, scaleFactor), mlt(s.gl.sw, scaleFactor), mlt(s.gl.sh, scaleFactor)); else s.destRect = RectF(0, 0, 0, 0); //s.destRect.size = Vector2(4.26666666f, 7.46666666f); } }
unsigned char equ(unsigned char a,unsigned char b){ int i; for(i=0;i<M;i++){ if(gf[mlt(fg[a],fg[i])]==b){ return i; } } }
int mltn(int n,int x){ int i,j; if(n==0) return 1; i=x; for(j=0;j<n-1;j++) i=mlt(i,x); return i; }
//単項式を多項式に掛け算する OP oterml(OP f,oterm t){ int i; OP h={0}; printf("deg=%d\n",deg(o2v(f))); for(i=0;i<deg(o2v(f))+1;i++){ h.t[i].n=f.t[i].n+t.n; h.t[i].a=gf[mlt(fg[f.t[i].a],fg[t.a])]; printf("%dx%d,",h.t[i].a,h.t[i].n); } printf("\n"); // exit(1); return h; }
//復号処理 OP decode(OP f,OP s){ int i,j,k; OP r={0},h={0},w,e={0}; oterm t1,t2; vec x={0}; printf("in decode\n"); r=vx(f,s); printpol(o2v(r)); // exit(1); x=chen(r); for(i=0;i<T;i++) printf("x=%d ",x.x[i]); printf("\n"); // exit(1); w=bibun(x); printpol(o2v(w)); printf("@@@@@@@@@\n"); h=ogcd(f,s); // exit(1); t1=LT(r); t2.a=t1.a; t2.n=0; w=oterml(w,t2); printpol(o2v(w)); printpol(o2v(h)); printf("%d\n",deg(x)+1); // exit(1); for(i=0;i<deg(x)+1;i++){ e.t[i].a=gf[mlt(fg[trace(h,x.x[i])],oinv(trace(w,x.x[i])))]; e.t[i].n=x.x[i]; } for(i=0;i<T;i++) printf("%d ",trace(h,x.x[i])); printf("\n"); for(i=0;i<T;i++) printf("%d ",oinv(trace(w,x.x[i]))); printf("\n"); return e; }
//チェン探索 vec chen(OP f){ vec e={0}; int i,count=0,n,x=0; unsigned char y[256]={0},z; // e=o2v(f); n=deg(o2v(f)); for(x=0;x<M;x++){ z=0; for(i=0;i<n+1;i++){ z^=gf[mlt(mltn(f.t[i].n,fg[(unsigned char)x]),fg[f.t[i].a])]; } if(z==0) e.x[count++]=(unsigned char)x; // printf("%d\n",x); } return e; }
/** * Gauss-Legendre quadature. * computes knots and weights of a Gauss-Legendre quadrature formula. * \param a Left endpoint of interval * \param b Right endpoint of interval * \param _t array of abscissa * \param _wts array of corresponding wights */ void gauss_legendre( double a, double b, const dvector& _t, const dvector& _wts ) // // Purpose: // // computes knots and weights of a Gauss-Legendre quadrature formula. // // Discussion: // // The user may specify the interval (A,B). // // Only simple knots are produced. // // Use routine EIQFS to evaluate this quadrature formula. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // September 2010 by Derek Seiple // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Input, double A, B, the interval endpoints, or // other parameters. // // Output, double T[NT], the knots. // // Output, double WTS[NT], the weights. // { dvector t=(dvector&) _t; dvector wts=(dvector&) _wts; if( t.indexmax()!=wts.indexmax() ) { cerr << "Incompatible sizes in void " "mygauss_legendre(double a, double b, const dvector& _t, const dvector& _wts)" << endl; ad_exit(-1); } t.shift(0); wts.shift(0); int nt = t.indexmax() + 1; int ub = nt-1; int i; int k; int l; double al; double ab; double abi; double abj; double be; double p; double shft; double slp; double temp; double tmp; double zemu; // Compute the Gauss quadrature formula for default values of A and B. dvector aj(0,ub); dvector bj(0,ub); ab = 0.0; zemu = 2.0 / ( ab + 1.0 ); for ( i = 0; i < nt; i++ ) { aj[i] = 0.0; } for ( i = 1; i <= nt; i++ ) { abi = i + ab * ( i % 2 ); abj = 2 * i + ab; bj[i-1] = sqrt ( abi * abi / ( abj * abj - 1.0 ) ); } // Compute the knots and weights. if ( zemu <= 0.0 ) // Exit if the zero-th moment is not positive. { cout << "\n"; cout << "Fatal error!\n"; cout << " ZEMU <= 0.\n"; exit ( 1 ); } // Set up vectors for IMTQLX. for ( i = 0; i < nt; i++ ) { t[i] = aj[i]; } wts[0] = sqrt ( zemu ); for ( i = 1; i < nt; i++ ) { wts[i] = 0.0; } // Diagonalize the Jacobi matrix. imtqlx (t, bj, wts ); for ( i = 0; i < nt; i++ ) { wts[i] = wts[i] * wts[i]; } // Prepare to scale the quadrature formula to other weight function with // valid A and B. ivector mlt(0,ub); for ( i = 0; i < nt; i++ ) { mlt[i] = 1; } ivector ndx(0,ub); for ( i = 0; i < nt; i++ ) { ndx[i] = i + 1; } dvector st(0,ub); dvector swts(0,ub); temp = 3.0e-14; al = 0.0; be = 0.0; if ( fabs ( b - a ) <= temp ) { cout << "\n"; cout << "Fatal error!\n"; cout << " |B - A| too small.\n"; exit ( 1 ); } shft = ( a + b ) / 2.0; slp = ( b - a ) / 2.0; p = pow ( slp, al + be + 1.0 ); for ( k = 0; k < nt; k++ ) { st[k] = shft + slp * t[k]; l = abs ( ndx[k] ); if ( l != 0 ) { tmp = p; for ( i = l - 1; i <= l - 1 + mlt[k] - 1; i++ ) { swts[i] = wts[i] * tmp; tmp = tmp * slp; } } } for(i=0;i<nt;i++) { t(i) = st(ub-i); wts(i) = swts(ub-i); } return; }
arrayn chash(unsigned char b[N]){ int i,j=0; arrayn n; unsigned char salt[64]={ 148, 246, 52, 251, 16, 194, 72, 150, 249, 23, 90, 107, 151, 42, 154, 124, 48, 58, 30, 24, 42, 33, 38, 10, 115, 41, 164, 16, 33, 32, 252, 143, 86, 175, 8, 132, 103, 231, 95, 190, 61, 29, 215, 75, 251, 248, 72, 48, 224, 200, 147, 93, 112, 25, 227, 223, 206, 137, 51, 88, 109, 214, 17, 172}; unsigned char z[N],w[N]; unsigned char m[N]={0},v[256]={0},g[N]={0},f[32]={0}; unsigned char inv_x[N],inv_y[N]; unsigned char s[64]={4,34,41,33,53,1,59,55,62,24,61,13,39,48,29,0,51,23,2,49,32,17,19,42,50,8,43,46,63,44,57,16,47,18,36,31,38,27,30,58,3,45,11,7,35,52,15,22,12,26,56,60,10,5,40,54,25,14,20,21,37,6,28,9};; unsigned char tt[64]={15,2,48,46,30,7,13,3,29,33,1,26,25,34,17,0,41,27,31,16,61,50,55,56,44,19,62,60,22,4,12,9,38,52,42,10,58,36,28,63,37,51,47,59,40,53,45,11,39,24,18,6,20,21,14,49,23,35,8,43,54,57,32,5}; FILE *fp,*op; int c,count; time_t t; int k; for(i=0;i<N;i++) aa[i]=0; for(i=0;i<N;i++){ inv_x[s[i]]=i; inv_y[tt[i]]=i; } for(i=0;i<N;i++){ b[i]^=salt[i]; // b[i+N/2]=111; } k=0; for(j=0;j<8;j++){ for(i=0;i<N;i++) z[i]=s[tt[inv_x[i]]]; for(i=0;i<N;i++) tt[i]=z[i]; for(i=0;i<N;i++){ m[i]^=gf[mlt(fg[4],mlt(fg[b[z[i]]],fg[255^b[z[i]]]))]|5*(b[z[i]]^b[z[(i+1)%N]]); // g[i]=5*b[z[i]]^b[z[(i+1)%N]]; //f[i]^=3*b[z[i]]; //b[i]^=g[i]*g[i]*f[i]^m[i]*m[i]*m[i]^4*m[i]^f[i]*f[i]*f[i]; } for(i=0;i<N;i++) b[i]^=m[i]; // //m[i]; // printf("m\n"); } //printf("relkg"); // exit(1); for(i=0;i<N;i++) n.ar[i]=b[i]; /* for(i=0;i<N;i++) printf("%u,",b[i]); printf("\n"); */ return n; }
int main(int argc,char **argv){ int i,j,k,l,c; unsigned long a,x,count=1; // unsigned char cc[K]={0}; unsigned char m[K],mm[T]={0}; time_t timer; FILE *fp,*fq; unsigned char g2[7]={1,0,9,0,0,6,4}; // unsigned char s[K]={0}; //{4,12,7,8,11,13}; unsigned char ee[10]={1,2,3,4,5,6,7,8,9,10}; unsigned char zz[T]={86,97,114,105,97,98,108,101,32,80,111,108,121,110,111,109}; // unsigned char zz[T]={10,97,114,105,97,98,108,101,32,80,111,108,121,110,111,109}; int y; OP f,h,r,w; vec v; unsigned char d=0; // unsigned char syn[K]={4,12,7,8,11,13}; // unsigned char g[K+1]={1,0,0,0,1,0,1}; // makegf(M); // makefg(M); // zz[0]=1; //zz[1]=2; //zz[2]=4; w=setpol(g,K+1); printpol(o2v(w)); // exit(1); /* fp=fopen(argv[1],"rb"); fq=fopen(argv[2],"wb"); while((c=fread(zz,1,T,fp))>0){ for(i=0;i<M;i++){ d=trace(w,(unsigned char)i); printf("%d,",d); if(d==0){ printf("%i bad trace 0\n",i); exit(1); } } printf("\n"); //exit(1); */ //エラーの生成 for(i=0;i<T;i++) zz[i]=i+1; det(g); for(i=0;i<K;i++){ for(j=0;j<M;j++) printf("%d,",mat[i][j]); printf("\n"); } //exit(1); // シンドローム多項式の生成 printf("zz="); for(i=0;i<K;i++){ syn[i]=0; for(j=0;j<T;j++){ printf("%u,",zz[j]); syn[i]^=gf[mlt(fg[zz[j]],fg[mat[i][j]])]; } // printf("%d,",syn[i]); } printf("\n"); // exit(1); f=setpol(syn,K); printpol(o2v(f)); // exit(1); r=decode(w,f); for(i=0;i<T;i++){ mm[i]=r.t[i].a; printf("e=%d %d\n",r.t[i].a,r.t[i].n); } /* fwrite(mm,1,T,fq); } */ // fclose(fp); // fclose(fq); // h2g(mat); // exit(1); return 0; }