52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"archgrid.xyz/ag/toolsbox/encryption/spiral"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var spiralCmd = &cobra.Command{
|
|
Use: "spiral",
|
|
Short: "螺旋随机密钥自解密算法工具",
|
|
Long: `使用螺旋随机密钥自解密算法加密或解密数据,在使用的时候注意明文和密文中如果包含空格或特殊字符,需要使用双引号包裹起来。`,
|
|
}
|
|
|
|
var spiralEncodeCmd = &cobra.Command{
|
|
Use: "encode",
|
|
Short: "使用螺旋随机密钥自解密算法加密",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: spiralEncodeExecute,
|
|
}
|
|
|
|
var spiralDecodeCmd = &cobra.Command{
|
|
Use: "decode",
|
|
Short: "使用螺旋随机密钥自解密算法解密",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: spiralDecodeExecute,
|
|
}
|
|
|
|
func spiralEncodeExecute(cmd *cobra.Command, args []string) {
|
|
encodedResult, err := spiral.Encrypt(args[0])
|
|
if err != nil {
|
|
fmt.Printf("加密失败,%s\n", err)
|
|
return
|
|
}
|
|
fmt.Printf("加密结果:%s\n", encodedResult)
|
|
}
|
|
|
|
func spiralDecodeExecute(cmd *cobra.Command, args []string) {
|
|
decodedResult, err := spiral.Decrypt(args[0])
|
|
if err != nil {
|
|
fmt.Printf("解密失败,%s\n", err)
|
|
return
|
|
}
|
|
fmt.Printf("解密结果:%s\n", decodedResult)
|
|
}
|
|
|
|
func init() {
|
|
spiralCmd.AddCommand(spiralEncodeCmd, spiralDecodeCmd)
|
|
rootCmd.AddCommand(spiralCmd)
|
|
}
|