#!/bin/bash LANG=C B64=({A..Z} {a..z} {0..9} + /) printf -v ascii \\%o {32..126} printf -v ascii "$ascii" printf -v cntrl %-20sE abtnvfr pkt=() lne= while IFS= read -r -d '' -n 1 car ;do if [ "$car" ] ;then printf -v car "%q" "$car" case ${#car} in 1|2 ) car=${ascii%$car*};pkt+=($((${#car}+32)));; 7 ) car=${car#*\'\\};pkt+=($((8#${car%\'})));; 5 ) car=${car#*\'\\};car=${cntrl%${car%\'}*};pkt+=($((${#car}+7)));; * ) echo >&2 ERROR: $car;; esac else pkt+=(0) fi if [ ${#pkt[@]} -gt 2 ] ;then car=$((pkt<<16|${pkt[1]}<<8|${pkt[2]})) lne+=${B64[car>>18]}${B64[car>>12&63]}${B64[car>>6&63]}${B64[car&63]} if [ "${#lne}" -gt 72 ] ;then echo $lne lne= fi pkt=() fi done if [ "$pkt" ] ;then f=0 while [ ${#pkt[@]} -lt 3 ] ;do pkt+=(0) ((f++)) done car=$((pkt<<16|${pkt[1]}<<8|${pkt[2]})) lne+=${B64[car>>18]}${B64[car>>12&63]}${B64[car>>6&63]}${B64[car&63]} lne=${lne:0:${#lne}-f} printf -v f %${f}s lne+=${f// /=} fi [ "$lne" ] && echo $lne