|
|
|
|
package base85
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
"b612.me/starcrypto"
|
|
|
|
|
"b612.me/starlog"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var Cmd = &cobra.Command{
|
|
|
|
|
Use: "base85",
|
|
|
|
|
Short: "使用base85处理文件或字符串",
|
|
|
|
|
Long: "使用base85处理文件或字符串",
|
|
|
|
|
Run: func(this *cobra.Command, args []string) {
|
|
|
|
|
var err error
|
|
|
|
|
ok, _ := this.Flags().GetBool("file")
|
|
|
|
|
de, _ := this.Flags().GetBool("decode")
|
|
|
|
|
if len(args) != 1 {
|
|
|
|
|
starlog.Criticalln("参数不足,请输入文件地址或字符串")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
shell := func(pec float64) {
|
|
|
|
|
if pec == 100 {
|
|
|
|
|
fmt.Println("已处理:100.000000%")
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf("已处理:%f%%\r", pec)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
path, _ := this.Flags().GetString("out")
|
|
|
|
|
if path == "" {
|
|
|
|
|
ext := filepath.Ext(args[0])
|
|
|
|
|
if ext != "" {
|
|
|
|
|
path = args[0][:len(args[0])-len(ext)] + ".b85" + ext
|
|
|
|
|
} else {
|
|
|
|
|
path = args[0] + ".b85"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !de {
|
|
|
|
|
err = starcrypto.Base85EncodeFile(args[0], path, shell)
|
|
|
|
|
} else {
|
|
|
|
|
err = starcrypto.Base85DecodeFile(args[0], path, shell)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if !de {
|
|
|
|
|
data := starcrypto.Base85Encode([]byte(args[0]))
|
|
|
|
|
fmt.Println(data)
|
|
|
|
|
} else {
|
|
|
|
|
var data []byte
|
|
|
|
|
data, err = starcrypto.Base85Decode(args[0])
|
|
|
|
|
fmt.Println(string(data))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Criticalln(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
Cmd.Flags().BoolP("file", "f", false, "base85处理文件")
|
|
|
|
|
Cmd.Flags().StringP("out", "o", "", "指定加解码输出地址")
|
|
|
|
|
Cmd.Flags().BoolP("decode", "d", false, "base85解码")
|
|
|
|
|
}
|