substitution cipher implementation
Reads in a json file that has a map of letters to letters
This commit is contained in:
parent
f357a75682
commit
7dd108f4ba
6
main.go
6
main.go
@ -15,13 +15,15 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
psyfer.ReadConfig()
|
||||
psyfer.Substitution("hello")
|
||||
var input string
|
||||
var cipher string
|
||||
var cipType string
|
||||
var key string
|
||||
|
||||
var encrypt = &cobra.Command{
|
||||
Use: "encrypt [cipher] [key] [input]",
|
||||
Use: "encrypt -c [cipher] -k [key] -i [input]",
|
||||
Short: "encrypt string",
|
||||
Long: `encrypt given string`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
@ -52,7 +54,7 @@ func main() {
|
||||
}
|
||||
|
||||
var decrypt = &cobra.Command{
|
||||
Use: "decrypt [cipher] [key] [input]",
|
||||
Use: "decrypt -c [cipher] -k [key] -i [input]",
|
||||
Short: "decrypt string",
|
||||
Long: `decrypt given string`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -1,4 +1,36 @@
|
||||
package psyfer
|
||||
|
||||
func ReadConfig() {
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
type KeyJSON struct {
|
||||
Key map[string]string `json:"key"`
|
||||
}
|
||||
|
||||
var k = KeyJSON{}
|
||||
|
||||
func ReadConfig() {
|
||||
dat, err := ioutil.ReadFile("key.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
json.Unmarshal([]byte(dat), &k)
|
||||
fmt.Println(k.Key["a"])
|
||||
}
|
||||
|
||||
func Substitution(input string) string {
|
||||
inputSlice := []string{}
|
||||
output := ""
|
||||
for _, char := range input {
|
||||
inputSlice = append(inputSlice, string(char))
|
||||
}
|
||||
for i := range inputSlice {
|
||||
output += k.Key[inputSlice[i]]
|
||||
}
|
||||
fmt.Println(output)
|
||||
return output
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user