// DecomposeAffineEncoding is an efficient way to factor an unknown affine encoding into its component linear and // affine parts. func DecomposeAffineEncoding(e encoding.Byte) (matrix.Matrix, byte) { m, c := matrix.Matrix(make([]matrix.Row, 8)), e.Encode(0) for i := uint(0); i < 8; i++ { m[i] = matrix.Row{e.Encode(1<<i) ^ c} } return m.Transpose(), c }
func (bl ByteLinear) Decode(i byte) byte { inv, ok := matrix.Matrix(bl).Invert() if !ok { panic("Matrix wasn't invertible!") } return inv.Mul(matrix.Row{i})[0] }
func parseMatrix(in []byte) (out matrix.Matrix, rest []byte) { if in == nil || len(in) < matrixSize { return } out = matrix.Matrix(make([]matrix.Row, 128)) for row, _ := range out { out[row] = in[16*row : 16*(row+1)] } return out, in[matrixSize:] }
func (bl BlockLinear) Decode(i [16]byte) (out [16]byte) { inv, ok := matrix.Matrix(bl).Invert() if !ok { panic("Matrix wasn't invertible!") } res := inv.Mul(matrix.Row(i[:])) copy(out[:], res) return }
func (wl WordLinear) Decode(i [4]byte) (out [4]byte) { inv, ok := matrix.Matrix(wl).Invert() // Performance bottleneck. if !ok { panic("Matrix wasn't invertible!") } res := inv.Mul(matrix.Row(i[:])) copy(out[:], res) return }
// FindAtilde calculates a non-trivial matrix Atilde s.t. L <- Atilde = Atilde <- D(beta), where // L = A_i <- D(beta) <- A_i^(-1) func FindAtilde(constr *chow.Construction, L matrix.Matrix) matrix.Matrix { beta := CharToBeta[FindCharacteristic(L)] D, _ := DecomposeAffineEncoding(encoding.ByteMultiplication(beta)) x := L.RightStretch().Add(D.LeftStretch()).NullSpace() m := matrix.Matrix(make([]matrix.Row, len(x))) for i, e := range x { m[i] = matrix.Row{e} } return m }
func (bl ByteLinear) Encode(i byte) byte { return matrix.Matrix(bl).Mul(matrix.Row{i})[0] }
func (bl BlockLinear) Encode(i [16]byte) (out [16]byte) { res := matrix.Matrix(bl).Mul(matrix.Row(i[:])) copy(out[:], res) return }
func (wl WordLinear) Encode(i [4]byte) (out [4]byte) { res := matrix.Matrix(wl).Mul(matrix.Row(i[:])) copy(out[:], res) return }