implemented sub subcommand
implemented the sub subcommand and did some clean up for the function
This commit is contained in:
parent
60d320088d
commit
ca2c861387
23
main.go
23
main.go
@ -16,10 +16,7 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
//psyfer.ReadConfig()
|
||||
//psyfer.Substitution("hello")
|
||||
var input string
|
||||
//var key string
|
||||
var key string
|
||||
var decrypt bool
|
||||
|
||||
var trans = &cobra.Command{
|
||||
@ -32,11 +29,18 @@ func main() {
|
||||
}
|
||||
|
||||
var sub = &cobra.Command{
|
||||
Use: "sub mode -c [cipher] -k [key] -i [input]",
|
||||
Use: "sub",
|
||||
Short: "substitution cipher",
|
||||
Long: `perform substitution cipher`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if key == "" || len(args) < 1 {
|
||||
fmt.Println("missing input, see -h (--help) for more info")
|
||||
os.Exit(1)
|
||||
}
|
||||
psyfer.ReadConfig(key)
|
||||
for _, arg := range args {
|
||||
fmt.Println(psyfer.Substitution(arg))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@ -135,16 +139,15 @@ func main() {
|
||||
)
|
||||
|
||||
sub.Flags().StringVarP(
|
||||
&input,
|
||||
"input",
|
||||
"i",
|
||||
&key,
|
||||
"key",
|
||||
"k",
|
||||
"",
|
||||
"string to be encrypted",
|
||||
"file containing key",
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{Use: "app"}
|
||||
rootCmd.AddCommand(sub, aes, trans, vig)
|
||||
sub.AddCommand(crack)
|
||||
aes.AddCommand(crack)
|
||||
trans.AddCommand(random, railfence, split)
|
||||
vig.AddCommand(crack)
|
||||
|
@ -2,7 +2,6 @@ package psyfer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
@ -13,13 +12,13 @@ type KeyJSON struct {
|
||||
|
||||
var k = KeyJSON{}
|
||||
|
||||
func ReadConfig() {
|
||||
dat, err := ioutil.ReadFile("key.json")
|
||||
func ReadConfig(file string) {
|
||||
dat, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
json.Unmarshal([]byte(dat), &k)
|
||||
fmt.Println(k.Key["a"])
|
||||
k.Key[" "] = " " // keep spaces alive
|
||||
}
|
||||
|
||||
func Substitution(input string) string {
|
||||
@ -31,6 +30,5 @@ func Substitution(input string) string {
|
||||
for i := range inputSlice {
|
||||
output += k.Key[inputSlice[i]]
|
||||
}
|
||||
fmt.Println(output)
|
||||
return output
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user