-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexescaper.sh
83 lines (78 loc) · 2.24 KB
/
hexescaper.sh
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
#!/bin/bash
green="\e[92m"
red="\e[91m"
blue="\e[34m"
none="\e[0m"
function usage {
echo -e "Please use the hex value in ${red}"double quotes"!${none} :D
${blue}USAGE:${none}
$0 Option Hex
${blue}EXAMPLE:${none}
$0 -e \"735f796172612d72756c65736574\"
${blue}OPTIONS:${none}
-e Escape_hex
-r Reverse_hex_escape
-d Double_escape - (escape the escape)
-dr Reversed_double_escape
-we White_escape
-wre White_reverse_escape
-w Just_white space b/w hex
-E Encode_hex - (Convert)
-D Reverse_hex - (Decode)"
}
if [ ${#} -ne 2 ]; then
echo -e ${none}"Need two arguments to run the script."${none}
echo
usage
exit
fi
case "$1" in
-e)
echo -e ${green}"Hex value escaped!"${none}
echo -n "$2" | fold -w 2 | tr "\n" " " | sed 's/\s/\\x/g' | sed 's/\\x$/ /' | sed 's/^/\\x/'
echo
;;
-r)
echo -e ${green}"Hex value reversed the escape!"${none}
echo -n "$2" | sed 's/\\x//g'
echo
;;
-d)
echo -e ${green}"Hex value escape the escaped!"${none}
echo -n "$2" | sed 's/\x/\\\x/g'
echo
;;
-dr|-rd)
echo -e ${green}"Hex value reversed the double escape!"${none}
echo -n "$2"
echo
;;
-we | -ew)
echo -e ${green}"Hex value with whitespace is escaped!"${none}
echo -n "$2" | sed 's/\s//g' | fold -w 2 | tr "\n" " " | sed 's/\s/\\x/g' | sed 's/\\x$/ /' | sed 's/\b/\\x/'
echo
;;
-wre | -erw | -rwe | -ewr | -wer | -rew)
echo -e ${green}"Hex value reversed with whitespace!"${none}
echo -n "$2" | sed 's/\\x/ /g' | sed 's/^\s//'
echo
;;
-w)
echo -e ${green}"Hex value White Spaced!"${none}
echo -n "$2" | fold -w 2 | tr "\n" " "
echo
;;
-E)
echo -e ${green}"Converted the text to hex!"${none}
echo -n "$2" | xxd -ps
;;
-D)
echo -e ${green}"Reversed the hex to text!"${none}
echo -n "$2" | sed 's/\\x//g' | xxd -ps -r
echo
;;
*)
usage
exit 2
;;
esac