Program 3.9: Matrix inversion of 32 X 32 Boolean matrices
Algorithmic cryptanalysis codes by Antoine Joux are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
/* Warning: mat is transformed during MatInv */ int MatInv(WORD mat[DIM], WORD inv[DIM]) { int piv,l,c,k; WORD val,vali,mask; for(piv=0,mask=1;piv<DIM;piv++,mask<<=1) inv[piv]=mask; for(piv=0,mask=1;piv<DIM;piv++,mask<<=1) { for (c=piv;c<DIM;c++) if (mask&mat[c]) break; if (c>=DIM) return(FALSE); val=mat[c];mat[c]=mat[piv];mat[piv]=val; vali=inv[c];inv[c]=inv[piv];inv[piv]=vali; for(c=0;c<DIM;c++) if ((c!=piv)&&(mask&mat[c])) { mat[c]^=val;inv[c]^=vali; }} return(TRUE); }
Credits for page styles: Dynamic Drive CSS Library