func TestFindCharacteristic(t *testing.T) { M := matrix.GenerateRandom(rand.Reader, 8) A := matrix.GenerateRandom(rand.Reader, 8) AInv, _ := A.Invert() N, _ := DecomposeAffineEncoding(encoding.ComposedBytes{ encoding.ByteLinear(A), encoding.ByteLinear(M), encoding.ByteLinear(AInv), }) if FindCharacteristic(M) != FindCharacteristic(N) { t.Fatalf("FindCharacteristic was not invariant!\nM = %2.2x\nA = %2.2x\nN = %2.2x, ", M, A, N) } }
func BenchmarkFindCharacteristic(b *testing.B) { M := matrix.GenerateRandom(rand.Reader, 8) b.ResetTimer() for i := 0; i < b.N; i++ { FindCharacteristic(M) } }
func TestByteLinear(t *testing.T) { m := ByteLinear(matrix.GenerateRandom(rand.Reader, 8)) for i := byte(0); i < 250; i++ { for j := byte(0); j < 250; j++ { if m.Decode(m.Encode(i)^m.Encode(j)) != i^j { t.Fatalf("Linear encoding didn't Encode/Decode correctly.") } } } }
func BenchmarkDecomposeAffineEncoding(b *testing.B) { aff := encoding.ByteAffine{ encoding.ByteLinear(matrix.GenerateRandom(rand.Reader, 8)), 0x60, } b.ResetTimer() for i := 0; i < b.N; i++ { DecomposeAffineEncoding(aff) } }
// Matrix takes a (private) seed and a (possibly public) label and produces a random non-singular 128x128 matrix. func (rs *RandomSource) Matrix(label []byte, size int) matrix.Matrix { key := [16]byte{} copy(key[:], label) cached, ok := rs.matrixCache[key] if ok { return cached } else { rs.matrixCache[key] = matrix.GenerateRandom(rs.Stream(label), size) return rs.matrixCache[key] } }