Hi, Carl.

At 04:33 AM 11/6/2002 +0900, you wrote:
>Question:  Has anyone developed a Ruby encoder that would allow me to
>encrypt my Ruby code to avoid revealing database passwords or other such
>things to a potential hacker?

Not me.  I have something that "solves" the problem in a different way.

The way I tend to do this is to place the password into ini files
that the application reads.  I store them encrypted and then decrypt
them on the fly using my Crypto class.   Not very elegant nor secure,
however it seems to be enough to discourage casual abuse.

The obvious problem of someone taking the code and making a decryptor
is there.  The assumption on my side is that the user doesn't have
access to this library (via permissions, etc.).

Feel free to change DefSeed and RandSeed to suit.

Hope this helps,

-mark.

# -----
# Crypto -- a class to do some simple crypto stuff
#
class Crypto

     DefSeed = 
"1913241303102769784369176881852378684052287024444246184380987196"
     RandStr = "4]fdsfA94kk4t380t4"

     def encrypt(str)
         s = str.dup + RandStr
         n = 0
         s.length.times do
             s[n] = (s[n] + DefSeed[n] - 48).chr.to_s
             n += 1
         end
         return s
     end

     def decrypt(str)
         s = str.dup
         n = 0
         s.length.times do
             s[n] = (s[n] - DefSeed[n] + 48).chr.to_s
             n += 1
         end
         return s.slice!(0, s.length - RandStr.length)
     end
end