-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrot135
executable file
·51 lines (46 loc) · 1.39 KB
/
rot135
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
#######################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : BSD/Linux
# Requires : bash, POSIX, file, tr
# Location : ~/bin, /usr/local/bin
# Name : rot135
# Version : 1.0.2
# Date : 2018-08-14
# Purpose : Encode or decode any (US-ASCII) text using ROT13 and
# numbers using ROT5. You will never break this cypher!!1
# Parameters : Text to be encoded, or a text file name.
# Input : Original text via a pipe, or as parameter(s).
# Output : Translated text on stdout. Error message on stderr.
# Settings : none
# Exit 0 : No error
# 1 : No input detected
#######################################################################
function tr_rot135() {
tr a-zA-Z0-9 n-za-mN-ZA-M5-90-4
}
if [ ! -t 0 ]; then
# Piped input, probably
tr_rot135
exit 0
fi
if [ -z "$1" ]; then
# No input detected
self=$(basename "$0")
echo "Usage 1: $self <text>" 1>&2
echo "Usage 2: $self <filename.txt>" 1>&2
echo "Usage 3: echo <text> | $self" 1>&2
exit 1
fi
if [ "$#" -eq 1 -a -f "$1" -a -r "$1" ]; then
# Single argument is a file that can be read
mime=$(file -b -i -eencoding "$1" | cut -d';' -f1)
if [ "$mime" = "text/plain" ]; then
# It is a text file (encoding not checked)
cat "$1" | tr_rot135
exit 0
fi
fi
# Use argument(s) as text
echo "$*" | tr_rot135