数据上报
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

52 lines
1.5 KiB

package main
import (
"bytes"
"crypto/rc4"
"encoding/hex"
"goUpload/utils"
"log"
"testing"
"text/template"
"time"
)
func TestCRC16CCITT(t *testing.T) {
hexs := "0a16080718a8ea8fab06620c0a0471bd54c11204e01d8641"
hexs = "0a2f080210f8b6d5d01218b395bffec3313a1e0a08a75fed41a75fed41120892c5d64292c5d6421a08f6c8a74379c9a743"
Hexdata, _ := hex.DecodeString(hexs)
crc := utils.NewCRC16CCITT().GetWCRCin(Hexdata)
log.Println(hex.EncodeToString(crc))
log.Println("===1==")
needRC4 := append(Hexdata, crc...)
rc4Key := []byte("t/500101")
dest1 := make([]byte, len(needRC4))
cipher1, _ := rc4.NewCipher(rc4Key)
cipher1.XORKeyStream(dest1, needRC4)
log.Printf("最终报文 dest1=%s", hex.EncodeToString(dest1))
}
func TestRC4(t *testing.T) {
rc4Key := []byte("t/500101")
log.Println("===2 test RC4==")
cipher2, _ := rc4.NewCipher(rc4Key)
raw := "0a2f080210f8b6d5d01218b395bffec3313a1e0a08a75fed41a75fed41120892c5d64292c5d6421a08f6c8a74379c9a743864c"
needRC4New, _ := hex.DecodeString(raw)
dest2 := make([]byte, len(needRC4New))
cipher2.XORKeyStream(dest2, needRC4New)
log.Printf("最终报文 dest1=%s", hex.EncodeToString(dest2))
}
func TestTemplate(t *testing.T) {
Create := func(name, t string) *template.Template {
return template.Must(template.New(name).Parse(t))
}
t2 := Create("t2", "什么是快乐星球-Name: {{.Name}}\n")
b := &bytes.Buffer{}
t2.Execute(b, struct {
Name string
}{"Jane Doe"})
time.Sleep(time.Second * 1)
bs := b.String()
log.Println(bs)
}