Compare commits

...

2 Commits

Author SHA1 Message Date
Nick Chambers 228484de6f Fix incorrect case of kill builtin 2021-11-15 02:32:28 -06:00
Nick Chambers bdd8fb3601 Implement a base64 encoder 2021-11-15 02:31:53 -06:00
1 changed files with 29 additions and 1 deletions

30
rowbot
View File

@ -181,6 +181,34 @@ url() {
fi
}
b64_encode() {
local idx=0 numerics table_idxs table_idx encoded
local table=( {A..Z} {a..z} {0..9} + / )
for (( ; idx < ${#1}; idx+=3 )); do
read -ra numerics < <(
printf '%d %d %d\n' "'${1:idx:1}" "'${1:idx+1:1}" "'${1:idx+2:1}"
)
(( table_idxs[0] = numerics[0] >> 2 ))
(( table_idxs[1] = (((numerics[0] & 0x03) << 6) | (numerics[1] & 0xF0) >> 2) >> 2 ))
(( table_idxs[2] = (((numerics[1] & 0x0F) << 4) | (numerics[2] & 0xC0) >> 4) >> 2 ))
(( table_idxs[3] = numerics[2] & 0x3F ))
for table_idx in "${table_idxs[@]}"; do
encoded+=${table[$table_idx]}
done
done
if (( ${#1} % 3 == 1 )); then
encoded=${encoded::-2}==
elif (( ${#1} % 3 == 2 )); then
encoded=${encoded::-1}=
fi
printf %s "$encoded"
if [[ -t 1 ]]; then
printf \\n
fi
}
###
# configure rowbot's environment
###
@ -481,7 +509,7 @@ on_sys_after_999_annoyatron900() {
on_sys_register_999_annoyatron900() {
while true; do
read -rt 10 </dev/zero
KILL -USR1 "$$"
kill -USR1 "$$"
done &
alarm_pid=$!