-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
88 lines (75 loc) 路 1.82 KB
/
args.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cli
import (
"bufio"
"flag"
"fmt"
"os"
decode "github.com/zerodayrat/den/decoding"
encode "github.com/zerodayrat/den/encodings"
)
func Init() {
base64 := flag.Bool("base64", false, "Encode in Base64")
hex := flag.Bool("hex", false, "Encode in Hexadecimal")
url := flag.Bool("url", false, "Encode in URL")
html := flag.Bool("html", false, "Encode in HTML")
bin := flag.Bool("bin", false, "Encode in Binary")
dec := flag.Bool("dec", false, "Encode in Decimal")
all := flag.Bool("all", false, "Encode in all Available Format")
dbase64 := flag.Bool("dbase64", false, "Decode from Base64")
dhex := flag.Bool("dhex", false, "Decode from Hex")
durl := flag.Bool("durl", false, "Decode from URL")
dhtml := flag.Bool("dhtml", false, "Decode from HTML")
dbin := flag.Bool("dbin", false, "Decode from Binary")
ddec := flag.Bool("ddec", false, "Decode from Decimal")
dall := flag.Bool("dall", false, "Decode in all Available Formats")
flag.Parse()
it := bufio.NewScanner(os.Stdin)
// check if any flag has passed or not
// if no flag is passed it'll print the tool usage
if flag.NFlag() == 0 {
flag.Usage()
os.Exit(0)
} else if flag.NFlag() > 1 {
fmt.Println("Error : Pass only one flag at a time.")
fmt.Println()
flag.Usage()
os.Exit(0)
} else {
for it.Scan() {
e := encode.E{S: it.Text()}
de := decode.DE{S: it.Text()}
switch {
// encoding
case *url:
e.ToURL()
case *html:
e.ToHTML()
case *base64:
e.ToBase64()
case *hex:
e.ToHex()
case *bin:
e.ToBin()
case *dec:
e.ToDec()
case *all:
e.ToAll()
// decoding
case *durl:
de.FromURL()
case *dhtml:
de.FromHTML()
case *dbase64:
de.FromBase64()
case *dhex:
de.FromHex()
case *dbin:
de.FromBin()
case *ddec:
de.FromDec()
case *dall:
de.ForAll()
}
}
}
}