[SLL] Curious

Paul Franz paul at eucleides.com
Sat Mar 7 09:21:32 PST 2009



On Sat, March 7, 2009 6:21 am, Jeremy C. Reed wrote:
> On Sat, 7 Mar 2009, Paul Franz wrote:
>
>> > echo 'EhZ[h ^jjf0%%h[[Zc[Z_W$d[j%Xeeai%ZW[ced#]dk#f[d]k_d%' | \
>> >   tr            '#-~'            '\-.-{'
>>
>> echo '@kij medZ[h_d] ^em "R#$#q" mehai5' | tr '#-~' '\-.-{'
>>
>> You've got me puzzled. I'd appreciate a little verbosity. It would seem to me that
ROT13 equivalence could be achieved too.
>
> The \- means literal - so not a range. Then the real range is period through left
brace.

What puzzled me is that the length of the second tr argument is 13 characters shorter
and the . is just another character in the range, the next one after a - in ascii
sequence. So:

tr '#-~' '\-.-{'
and
tr '#-~' '\--{'  are both the same. And tr fills the second string to and equal count
by repeating the last character so this is also the same:
tr '#-~' '\--{{{{{'

That's what I through me at first.

> echo V znqr n fpevcg gb perngr guvf sbe EBG13 gbb | \
>  tr "VBEGnpqrsuvzbcefg" "IORTacdefhimoprst"

I did too:

 echo V znqr n fpevcg gb perngr guvf sbe EBG13 gbb | rot13
I made a script to create this for ROT13 too

It is this;

#!/bin/bash
# /usr/share/sbin/rot13 script by Paul A. Franz
# Rotates alphabetic characters 13 positions from stdin or a file
# It's symmetric so the following two lines are equivalent
# cat file
# rot13 file | rot13

# USAGE EXAMPLES
#
# echo "Lbh'ir tbg gb cvgl Arj Zrkvpb... fb sne sebz urnira naq fb pybfr gb Grknf." |
rot13
#
# cat file | rot13
#
# rot13 file

cat $1 | tr 'A-Za-z' 'N-ZA-Mn-za-m'

BTW, my motivation for this is playing with fortune. If the fortune files are rot13
then the -m switch doesn't work unless you rot13 the argument too. When the file is
rot13, the .dat file was made with "strfile -x" and fortune works fine but the Linux
version doesn't compensate with the -m switch for searching rot13 data.

-- 
Paul Franz
425.440.9505 (O)
425.241.1618 (C)


More information about the linux-list mailing list