package main import ( "bytes" "crypto/rc4" "encoding/hex" "fmt" "goInOut/utils" "log" "sync" "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) } func TestRangeMap(t *testing.T) { m := sync.Map{} //存数据 m.Store(1, 1) m.Store(2, 2) m.Store(3, 3) m.Store(4, 4) m.Store(5, 5) //遍历map m.Range(func(key, value interface{}) bool { log.Printf("开始遍历 %v", key) if key.(int) == 2 { return false } fmt.Println(key, value) return true }) }