From fe60ffdfde90b4bbbd0ba570cd8a9b4282f4b7ac Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 16 Jul 2020 15:53:41 -0400 Subject: initial implementation --- caesar.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 caesar.sh diff --git a/caesar.sh b/caesar.sh new file mode 100644 index 0000000..186891d --- /dev/null +++ b/caesar.sh @@ -0,0 +1,25 @@ +number=13 + +while getopts n: opt; do + case $opt in + n) number=${OPTARG};; + ?) exit 1;; + esac +done + +shift $((OPTIND - 1)) + +if [ $# -ne 0 ]; then + printf 'usage: %s [-n number]\n' "$0" + printf '\t-n the number of characters to rotate (default 13)\n' + exit 1 +fi + +number=$((number % 26)) +A=$(printf '%d' 0$(printf '%o' \"A\")) +FROM=$(printf '%o' $((A + number))) +THRU=$(printf '%o' $((A + number - 1))) +TRUPPER=$(printf '%b-ZA-%b\n' "\0${FROM}" "\0${THRU}") +trlower=$(echo $TRUPPER | tr [[:upper:]] [[:lower:]]) + +exec tr "A-Za-z" "${TRUPPER}${trlower}" -- cgit v1.2.1