I made this a while back and just converted it into an executable library, so I'd thought I'd post it here. The code is probably horribly inefficient, but it works.
#! /usr/bin/ruby
# This is an executable Ruby library that adds rot13 functinality to the String class,
# and can encrypt/decrypt STDIN.
class String
def rot13!
size.times do |i|
if self[i].between? 65, 90
self[i] += 13
self[i] = 64 + self[i] - 90 if self[i] > 90
elsif self[i].between? 97, 122
self[i] += 13
self[i] = 96 + self[i] - 122 if self[i] > 122
end
end
return self
end
def rot13
return self.dup.rot13!
end
end
begin
if $0 == __FILE__
input = ''
while ( b = STDIN.gets ) != nil
input << b
end
STDOUT.print input.rot13
end
rescue
nil
end
Enjoy.
EDIT:
rot13