-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.go
More file actions
41 lines (35 loc) · 809 Bytes
/
encode.go
File metadata and controls
41 lines (35 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"strings"
)
func main() {
// read input
input := os.Args[1:] // first element is path to the program
if len(input) != 1 {
panic("exactly one argument must be provided")
}
// split comma-separated values
prefixes := strings.Split(input[0], ",")
var targets [][]byte
// for each comma-separate prefix, decode hex to bytes
for _, prefix := range prefixes {
target, err := hex.DecodeString(prefix)
if err != nil {
panic(err)
}
// append result to target list
targets = append(targets, target)
}
// encode targets
encodedTargets, err := json.Marshal(targets)
if err != nil {
panic(err)
}
// return hex string of encoded targets
strEncoding := hex.EncodeToString(encodedTargets)
fmt.Println(strEncoding)
}