package experiment

import (
	"encoding/binary"
	"fmt"
	"testing"
)

func TestDotProd(t *testing.T) {
	fmt.Println(DotProd([]byte{0, 0, 1, 1}, []byte{1, 1, 1, 1}))
}

func TestTable(t *testing.T) {
	ml, mh := CreatTable(M1, C1.Byte())
	fmt.Printf("m1l = {0x%x, 0x%x};\n", binary.LittleEndian.Uint64(ml[:8]), binary.LittleEndian.Uint64(ml[8:]))
	fmt.Printf("m1h = {0x%x, 0x%x};\n", binary.LittleEndian.Uint64(mh[:8]), binary.LittleEndian.Uint64(mh[8:]))

	ml, mh = CreatTable(M2, C2.Byte())
	fmt.Printf("m2l = {0x%x, 0x%x};\n", binary.LittleEndian.Uint64(ml[:8]), binary.LittleEndian.Uint64(ml[8:]))
	fmt.Printf("m2h = {0x%x, 0x%x};\n", binary.LittleEndian.Uint64(mh[:8]), binary.LittleEndian.Uint64(mh[8:]))
}

func TestTransform(t *testing.T) {

	for i := 16; i < 256; i++ {
		b := byte(i)
		x := M1Transform(b)
		y := sm4Field.Add(Transform(M1, NewFFE(b)), C1).Byte()
		if x != y {
			t.Logf("%d: %x %x", i, x, y)
		}

	}
}

func TestMat(t *testing.T) {
	M2A := MatrixMul(M2, A)
	for i := range M2A {
		for j := range M2A[i] {
			fmt.Print(M2A[i][j], ", ")
		}
		fmt.Println()
	}
}

func TestVec(t *testing.T) {
	C3 := MatrixMulVector(M2, c)
	for i := 0; i < 8; i++ {
		C3[i] += c2[i]
		C3[i] %= 2
		fmt.Print(C3[i], ", ")
	}

}
