1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-28 14:50:26 +08:00
This commit is contained in:
源文雨
2023-08-04 16:07:35 +08:00
parent c90cee8c1b
commit 8163c38884
5 changed files with 62 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package link
import (
"bytes"
"crypto/rand"
"io"
"testing"
)
@@ -10,15 +11,20 @@ func TestXOR(t *testing.T) {
m := Me{
mask: 0x12345678_90abcdef,
}
buf := make([]byte, 65535)
for i := 1; i < 65536; i++ {
buf := make([]byte, 4096)
buf2 := make([]byte, 4096)
for i := 1; i < 4096; i++ {
data := buf[:i]
_, err := rand.Read(data)
orgdata := buf2[:i]
r1 := bytes.NewBuffer(data[:0])
r2 := bytes.NewBuffer(orgdata[:0])
w := io.MultiWriter(r1, r2)
_, err := io.CopyN(w, rand.Reader, int64(i))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(m.xor(m.xor(data)), data) {
t.Fatal("unexpected xor at ", i)
if !bytes.Equal(m.xordec(m.xorenc(r1.Bytes())), r2.Bytes()) {
t.Fatal("unexpected xor at", i)
}
}
}