github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/common/util_test.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  	"testing"
     7  )
     8  
     9  func TestRandomCSPRNG(t *testing.T) {
    10  	for i := 2; i < 9; i++ {
    11  		f64 := math.Pow(2, float64(i))
    12  		buf := RandomCSPRNG(int(f64))
    13  
    14  		fmt.Printf("len=%d,buf=%x\n", int(f64), buf)
    15  
    16  	}
    17  
    18  }
    19  
    20  func TestUint16(t *testing.T) {
    21  	pkbf := "04a21186f94eb8b037c2e304a86a333952c898ee7eca0de0184b4728e78d5cf7a998b032034ec5074a23ab8c86c1aa071fab3d9c55eb2ad79a8377b24774981356"
    22  
    23  	buf, _ := Hex2Bytes(pkbf)
    24  
    25  	u16 := BytesToUint16(buf)
    26  
    27  	fmt.Printf("u16=%v\n", u16)
    28  
    29  	newbuf := Uint16ToBytes(u16)
    30  
    31  	fmt.Printf("qqq-->%x\n", newbuf)
    32  
    33  }