Created
June 27, 2019 11:00
-
-
Save husio/0508ad24aa52a8f95684a1a86f33e1cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/hex" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"os" | |
"strings" | |
) | |
func main() { | |
decodeFl := flag.Bool("d", false, "Decode Hex encoded value") | |
flag.Parse() | |
data := strings.Join(flag.Args(), " ") | |
if data == "" { | |
raw, _ := ioutil.ReadAll(os.Stdin) | |
data = string(raw) | |
} | |
if *decodeFl { | |
raw, err := hex.DecodeString(data) | |
if err != nil { | |
fail(err) | |
} | |
os.Stdout.Write(raw) | |
} else { | |
io.WriteString(os.Stdout, hex.EncodeToString([]byte(data))) | |
} | |
} | |
func fail(err error) { | |
fmt.Fprint(os.Stderr, err) | |
os.Exit(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment