summaryrefslogtreecommitdiff
path: root/caesar.sh
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-07-16 15:53:41 -0400
committerJakob Kaivo <jkk@ung.org>2020-07-16 15:53:41 -0400
commitfe60ffdfde90b4bbbd0ba570cd8a9b4282f4b7ac (patch)
tree18e31ff579a94fadc7361460404a51d5604e7116 /caesar.sh
parent4581c73b6b037fd86304703373e3d87420928be2 (diff)
initial implementationHEADmaster
Diffstat (limited to 'caesar.sh')
-rw-r--r--caesar.sh25
1 files changed, 25 insertions, 0 deletions
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}"