Caesar()
{
rawdata="$1"
offset="$2"
action="$3"
text="$4"
length=$(echo "$rawdata"|awk '{print length()}')
for((i=1;i<=$length;i++))
do
[ $i -eq 1 ]&&y=""
x=$((i+offset));
[ $x -gt $length ]\
&&y="$y$(echo $rawdata|cut -b $((x-length)))"\
||y="$y$(echo -n $rawdata|cut -b $x)";
done
[ "$action" = "-e" ]&&echo "$text"|tr "$rawdata" "$y"
[ "$action" = "-d" ]&&echo "$text"|tr "$y" "$rawdata"
}
复制代码用法:Caesar "字符集" “偏移量” “加密/解密” “明文”
# All="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"
# Caesar "$All" 2 -e "Have a test"
Jcxg1c1vguv
# Caesar "$All" 2 -d "Jcxg1c1vguv"
Have a test