enhance(spiral):增加螺旋加密算法的兼容模式。

This commit is contained in:
徐涛 2023-07-18 16:10:46 +08:00
parent 85ebee0185
commit 0992fbe3b6
3 changed files with 23 additions and 4 deletions

View File

@ -7,6 +7,10 @@ import (
"github.com/spf13/cobra"
)
var (
spiralCompatible bool
)
var spiralCmd = &cobra.Command{
Use: "spiral",
Short: "螺旋随机密钥自解密算法工具",
@ -28,7 +32,13 @@ var spiralDecodeCmd = &cobra.Command{
}
func spiralEncodeExecute(cmd *cobra.Command, args []string) {
encodedResult, err := spiral.Encrypt(args[0])
var strength spiral.Strength
if spiralCompatible {
strength = spiral.Compatible
} else {
strength = spiral.Enhanced
}
encodedResult, err := spiral.Encrypt(args[0], strength)
if err != nil {
fmt.Printf("加密失败,%s\n", err)
return
@ -37,7 +47,13 @@ func spiralEncodeExecute(cmd *cobra.Command, args []string) {
}
func spiralDecodeExecute(cmd *cobra.Command, args []string) {
decodedResult, err := spiral.Decrypt(args[0])
var strength spiral.Strength
if spiralCompatible {
strength = spiral.Compatible
} else {
strength = spiral.Enhanced
}
decodedResult, err := spiral.Decrypt(args[0], strength)
if err != nil {
fmt.Printf("解密失败,%s\n", err)
return
@ -46,6 +62,7 @@ func spiralDecodeExecute(cmd *cobra.Command, args []string) {
}
func init() {
spiralCmd.PersistentFlags().BoolVarP(&spiralCompatible, "compatible", "c", false, "兼容模式,兼容旧版本的螺旋随机密钥自解密算法")
spiralCmd.AddCommand(spiralEncodeCmd, spiralDecodeCmd)
rootCmd.AddCommand(spiralCmd)
}

4
go.mod
View File

@ -17,9 +17,9 @@ require (
)
require (
archgrid.xyz/ag/toolsbox v0.1.1
archgrid.xyz/ag/toolsbox v0.1.2
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
replace archgrid.xyz/ag/toolsbox v0.1.1 => git.archgrid.xyz/xt/ag_toolsbox v0.1.1
replace archgrid.xyz/ag/toolsbox v0.1.2 => git.archgrid.xyz/xt/ag_toolsbox v0.1.2

2
go.sum
View File

@ -2,6 +2,8 @@ git.archgrid.xyz/xt/ag_toolsbox v0.1.0 h1:8/yp9wHf631K9IY7o4RZAJGGlLCBMYQOG/LHYl
git.archgrid.xyz/xt/ag_toolsbox v0.1.0/go.mod h1:iaTTuz0BZi3b3+9+J9lGujfY42sUIEBPxnEes8lr6iA=
git.archgrid.xyz/xt/ag_toolsbox v0.1.1 h1:QJX+fEEx1+yQIQEbAaLQXuOWnZb8HK6Y4ReBAIIWCQs=
git.archgrid.xyz/xt/ag_toolsbox v0.1.1/go.mod h1:iaTTuz0BZi3b3+9+J9lGujfY42sUIEBPxnEes8lr6iA=
git.archgrid.xyz/xt/ag_toolsbox v0.1.2 h1:hjpuzxMcdGjvCk7408Agg8IeR9vo/7f/BHfouxfWiYE=
git.archgrid.xyz/xt/ag_toolsbox v0.1.2/go.mod h1:iaTTuz0BZi3b3+9+J9lGujfY42sUIEBPxnEes8lr6iA=
github.com/azr/gift v1.1.2 h1:EbQ8/1QMtDfz5Beqg+RY5F21KbwGhE8aWSEbF1pp95A=
github.com/azr/gift v1.1.2/go.mod h1:bDKvjyxgachY3zdk831G99y+VANype25eu37uhm3khI=
github.com/azr/phash v0.2.0 h1:F6qkeYlwuMUMkUAJkQFElGrQzFnneJwV+L23VrEQ0cU=