-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathook.sh
More file actions
executable file
·124 lines (115 loc) · 2.26 KB
/
Copy pathook.sh
File metadata and controls
executable file
·124 lines (115 loc) · 2.26 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
declare -a ooks
declare -a chars
ooks=("oO" "Oooo" "OoOo" "Ooo" "o" "ooOo" "OOo" "oooo" "oo" "oOOO" "OoO" "oOoo" "OO" "Oo" "OOO" "oOOo" "OOoO" "oOo" "ooo" "O" "ooO" "oooO" "oOO" "OooO" "OoOO" "OOoo" "OOOOO" "oOOOO" "ooOOO" "oooOO" "ooooO" "ooooo" "Ooooo" "OOooo" "OOOoo" "OOOOo" "k ")
chars=("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" " ")
nflag=""
eflag=""
space="k "
sep="0"
encode=""
usage() {
echo "Usage: $0 ...strings [-n] [-e]" 1>&2;
echo "By defaul strings that looks encoded will be decoded." 1>&2;
exit 1;
}
find() {
local i=0
if [[ "$1" = "ooks" ]];
then
for i in "${!ooks[@]}";
do
if [[ ${ooks[$i]} = $2 ]];
then
return $i
fi
done
else
for i in "${!chars[@]}";
do
if [[ ${chars[$i]} = $2 ]];
then
return $i
fi
done
fi
return -1
}
while getopts "ne" opt; do
case $opt in
n) nflag="true";;
e) eflag="true";;
*)
usage
exit 1
esac
done
shift $((OPTIND-1))
if [[ $# -eq 0 ]];
then
usage
exit 1
fi
s=""
if [[ $1 =~ ^([Oo0k\s])+$ ]] && [[ ! $eflag = "true" ]];
then
encode="false"
numWords=$#
for (( i=1; i<=$numWords; i++ ));
do
str=${!i}
str=$(echo -e $str | sed "s/0/ /g")
IFS=" " read -a codes <<< "$str"
numCodes=${#codes[*]}
for (( j=0; j<$numCodes; j++ ));
do
code=${codes[$j]}
if [[ $code = "k" ]]; then
code="k "
fi
find "ooks" "$code"
res=$?
s="$s${chars[$res]}"
done
done
else
# encode
# every word
encode="true"
numWords=$#
for (( i=1; i<=$numWords; i++ ));
do
var=${!i}
varLen=${#var}
# prepend 0 if we need
if [[ $i -gt 1 ]];
then
s="$s$sep"
fi
# everychar
for (( j=0; j<$varLen; j++ ));
do
find "chars" "${var:$j:1}"
res=$?
s="$s${ooks[$res]}"
s="$s$sep"
done
s="$s$space"
done
fi
# mode message
mode="decode"
if [[ $encode = "true" ]]; then
mode="encode"
fi
if [[ $s = "" ]]; then
mode="$mode (ambiguous input)"
fi
echo "Mode: $mode"
if [[ ! $nflag = "true" ]]; then
# copy to clip
echo "Copied to clipboard."
echo -e $s | pbcopy
else
echo $s
fi