aboutsummaryrefslogtreecommitdiff
path: root/templates/.bin/rot13
diff options
context:
space:
mode:
Diffstat (limited to 'templates/.bin/rot13')
-rwxr-xr-xtemplates/.bin/rot1318
1 files changed, 18 insertions, 0 deletions
diff --git a/templates/.bin/rot13 b/templates/.bin/rot13
new file mode 100755
index 0000000..c72f41e
--- /dev/null
+++ b/templates/.bin/rot13
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+offset=${1:-13}
+
+if [ "$offset" -lt 1 ]; then
+ echo "offset must be greater than zero" >&2
+ exit 1
+elif [ "$offset" -gt 25 ]; then
+ echo "offset must be less than 26" >&2
+ exit 1
+fi
+
+alphabet=aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ
+sub1=$(echo "$alphabet" | cut -c $((offset * 2 + 1))-)
+sub2=$(echo "$alphabet" | cut -c 1-$((offset * 2)))
+sub=$sub1$sub2
+
+tr "$alphabet" "$sub"