Need Help in converting php encryption decryption code to ruby on rails

Hi guys i found this encryption decryption in php and try to convert
it in rails but i am unable to successfully convert it. So plz help
me. I you write the whole conversion code then it will be great.

PHP code is like this

Even though i think you should use some known encryption algorythm,
here's translated source (not tested):

require 'digest/md5'
require 'base64'

class String
  def ^(value)
    rez = ""
    self.length.times { |i| rez << (self[i] ^ value[i %
value.length].to_i) }
    rez
  end
end

def get_rnd_iv(iv_len)
  chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
  iv = ""
  iv_len.times { iv << chars[rand(chars.size)] }
  return iv
end

def md5_encrypt(plain_text, password, iv_len = 16 )
  plain_text += "\x13"; # for some reason i believe that it should be
\n instead of \x13, a bug in a script?
  plain_text += "\0" * (16 - plain_text.length % 16)

  enc_text = get_rnd_iv(iv_len);
  iv = (password ^ enc_text)[0, 512];

  (plain_text.length % 16).times do |i|
    block = plain_text[i * 16, 16] ^ Digest::MD5.hexdigest(iv)
    enc_text += block
    iv = (block + iv)[0, 512] ^ password
  end

  return Base64.encode64(enc_text);
end

def md5_decrypt(enc_text, password, iv_len = 16)
  enc_text = Base64.decode64(enc_text);
  plain_text = '';
  iv = (password ^ enc_text[0, iv_len])[0, 512];

  i, n = iv.length, enc_text.length
  while i < n
    block = enc_text[i, 16]
    plain_text += block ^ Digest::MD5.hexdigest(iv)
    iv = (block + iv)[0, 512] ^ password
    i += 16
  end

  return plain_text.gsub(/\x13\x00*$/, '');
end

I will try it and let you know. Thanks for support.