rot13 and rot47 shell functions

blarbaltest - 2 years ago (last modified 2 years ago)

function rot13()
{
 if [ -r $1 ]; then cat $1 | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; else echo $* | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; fi
}

function rot47()
{
 if [ -r $1 ]; then cat $1 | tr '\!-~' 'P-~\!-O' ; else echo $* | tr '\!-~' 'P-~\!-O'; fi
}

# usages:
# rot13 test
# echo test | rot13

blarbaltest - 2 years ago | thread

Any chance there could be a link somewhere with a "Formatting Help" or FAQ that covers formatting?

reply
demindiro - 2 years ago | thread parent

You can format with monospace by prepending two spaces, e.g.

' test'

becomes

test

reply
blarbaltest - 2 years ago | thread parent

Thankyou!

reply
demindiro - 2 years ago (last modified 2 years ago) | thread parent

I've edited it for you, I hope you don't mind.

EDIT: And I've found I strip a bit too much whitespace. Whoops

reply