rot: command-line substitution obfuscation
#!/bin/sh
#####################
#
# name: rot (rot.sh)
# vers: 0.1a
# date: 031506
# auth: "Keith Beckman" <kbeckm@alphahelical.com>
# site: http://alphahelical.com/code/scripts/rot
# desc: rot applies substitution cyphers to text in a case-sensitive.
# manner. It is essentially a front-end for tr(1), with its main
# features being that it allows input either from the command line
# or from stdin, that it keeps a set of predefined substitutions,
# and that it simplifies substitution with a user-definable
# default behaviour.
#
#####################
####configuration####
default_mode='anrot'
verstring='rot v0.1a 031506 Keith Beckman'
##end configuration##
# Define our various alphabets for use in translation, so we can define
# various rot13/atbash implementations (really, any simple substitution cypher)
alpha='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
alpharot='nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
alphanum='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
alphanumrot='nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM5678901234'
atbash='zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210'
rot_usage () {
echo 'Usage: rot -[a|n|b|h|v] [input text]'
echo ' rot applies substitution cyphers to stdin.'
echo ' Default behaviour is alphanumeric rot13.'
echo ' a: alpha-only rot13'
echo ' b: atbash (reversed alphabet)'
echo ' n: alphanumeric rot13'
}
# Check args to allow no flags but still input text.
if [ $2 ];
then
modearg=$1
inputarg=$2
elif [ $(echo $1 | grep
"^-") ];
then
modearg=$1
inputarg=$2
else
modearg=''
inputarg=$1
fi
# Choose mode, and default to alphanumeric-a
case $modearg in
# modes
'-a') #alpha-only rot13
mode='arot'
;;
'-b') #atbash
mode='atbash'
;;
'-n') #alphanumeric rot13
mode='anrot'
;;
# other options
'') #default mode
mode=$default_mode
;;
'-v') #version
echo $verstring
echo ' Apply substitution cyphers to stdin.'
exit
;;
'-h') #help
rot_usage
exit
;;
*) #bad option
echo 'Please specify a valid option.'
rot_usage
exit
;;
esac
# Set up substitutions based on mode
case $mode in
'arot') #alpha-only rot13
first=$alpha
second=$alpharot
;;
'anrot') #alphanumeric rot13
first=$alphanum
second=$alphanumrot
;;
'atbash') #atbash
first=$alphanum
second=$atbash
;;
esac
# Make allowance for command-line text input
if [ $inputarg ];
then
echo $inputarg |
tr
$first $second 2
> /dev/null
else
tr
$first $second 2
> /dev/null
fi
Generated by GNU enscript 1.6.1 and enscriptclean.
rot | Download Source | View Source