diff --git a/README.md b/README.md index a1432878..a8ff2825 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,7 @@ Here are the Go packages that can be imported correctly: * [reflect](https://pkg.go.dev/reflect) (partially) * [time](https://pkg.go.dev/time) (partially) * [encoding/binary](https://pkg.go.dev/encoding/binary) +* [encoding/base32](https://pkg.go.dev/encoding/base32) * [encoding/base64](https://pkg.go.dev/encoding/base64) * [regexp](https://pkg.go.dev/regexp) * [regexp/syntax](https://pkg.go.dev/regexp/syntax) diff --git a/_cmptest/base64demo/base64.go b/_cmptest/base64demo/base64.go index 22728ba9..e80a6f42 100644 --- a/_cmptest/base64demo/base64.go +++ b/_cmptest/base64demo/base64.go @@ -1,11 +1,12 @@ package main import ( + "encoding/base32" "encoding/base64" "fmt" ) -func main() { +func base64Demo() { msg := "Hello, 世界" encoded := base64.StdEncoding.EncodeToString([]byte(msg)) fmt.Println(encoded) @@ -16,3 +17,20 @@ func main() { } fmt.Println(string(decoded)) } + +func base32Demo() { + str := "JBSWY3DPFQQHO33SNRSCC===" + dst := make([]byte, base32.StdEncoding.DecodedLen(len(str))) + n, err := base32.StdEncoding.Decode(dst, []byte(str)) + if err != nil { + fmt.Println("decode error:", err) + return + } + dst = dst[:n] + fmt.Printf("%q\n", dst) +} + +func main() { + base64Demo() + base32Demo() +}