def encode_password(password)
    i = 0
    chars = password.split(//)
    count = chars.size

    chars.collect! do |char|
      i += 1
      char     = char.ord << i
      low_15   = char & 0x7fff
      high_15  = char & 0x7fff << 15
      high_15  = high_15 >> 15
      char     = low_15 | high_15
    end

    encoded_password  = 0x0000
    chars.each { |c| encoded_password ^= c }
    encoded_password ^= count
    encoded_password ^= 0xCE4B
  end
def encode_password(password)
    i = 0
    chars = password.split(//)
    count = chars.size

    chars.collect! do |char|
      i += 1
      char     = char.ord << i
      low_15   = char & 0x7fff
      high_15  = char & 0x7fff << 15
      high_15  = high_15 >> 15
      char     = low_15 | high_15
    end

    encoded_password  = 0x0000
    chars.each { |c| encoded_password ^= c }
    encoded_password ^= count
    encoded_password ^= 0xCE4B
  end
Based on the algorithm provided by Daniel Rentz of OpenOffice.