-
Notifications
You must be signed in to change notification settings - Fork 29
/
encode.go
89 lines (68 loc) · 1.89 KB
/
encode.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
89
package transform
import (
"encoding/base64"
"encoding/binary"
"strconv"
"strings"
"github.com/vulncheck-oss/go-exploit/output"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func EncodeBase64(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
func DecodeBase64(s string) string {
decoded, err := base64.StdEncoding.DecodeString(s)
if err != nil {
output.PrintFrameworkError(err.Error())
return ""
}
return string(decoded)
}
func Title(s string) string {
return cases.Title(language.Und, cases.NoLower).String(s)
}
// URL encode every character in the provided string.
func URLEncodeString(inputString string) string {
encodedChars := ""
for _, char := range inputString {
encodedChars += "%" + strconv.FormatInt(int64(char), 16)
}
return encodedChars
}
// PackLittleInt32 packs a little-endian 32-bit integer as a string.
func PackLittleInt32(n int) string {
var packed strings.Builder
err := binary.Write(&packed, binary.LittleEndian, int32(n))
if err != nil {
output.PrintFrameworkError(err.Error())
}
return packed.String()
}
// PackLittleInt64 packs a little-endian 64-bit integer as a string.
func PackLittleInt64(n int) string {
var packed strings.Builder
err := binary.Write(&packed, binary.LittleEndian, int64(n))
if err != nil {
output.PrintFrameworkError(err.Error())
}
return packed.String()
}
// PackBigInt16 packs a big-endian 16-bit integer as a string.
func PackBigInt16(n int) string {
var packed strings.Builder
err := binary.Write(&packed, binary.BigEndian, int16(n))
if err != nil {
output.PrintFrameworkError(err.Error())
}
return packed.String()
}
// PackBigInt32 packs a big-endian 32-bit integer as a string.
func PackBigInt32(n int) string {
var packed strings.Builder
err := binary.Write(&packed, binary.BigEndian, int32(n))
if err != nil {
output.PrintFrameworkError(err.Error())
}
return packed.String()
}