예제 #1
0
// 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
}
예제 #2
0
파일: chow_test.go 프로젝트: gaurav1981/AES
func verifyIsAffine(t *testing.T, aff encoding.Byte, err string) {
	m, c := DecomposeAffineEncoding(aff)
	test := encoding.ByteAffine{encoding.ByteLinear(m), c}

	for i := 0; i < 256; i++ {
		a, b := aff.Encode(byte(i)), test.Encode(byte(i))
		if a != b {
			t.Fatalf(err, i, a, b)
		}
	}
}
예제 #3
0
// isAffine returns true if the given encoding is affine and false if not.
func isAffine(aff encoding.Byte) bool {
	m, c := DecomposeAffineEncoding(aff)
	test := encoding.ByteAffine{encoding.ByteLinear(m), c}

	for i := 0; i < 256; i++ {
		a, b := aff.Encode(byte(i)), test.Encode(byte(i))
		if a != b {
			return false
		}
	}

	return true
}