lib/base64.rb


DEFINITIONS

This source file includes following functions.


   1  require "kconv"
   2  
   3  def decode64(str)
   4    str.unpack("m")[0]
   5  end
   6  
   7  def decode_b(str)
   8    str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
   9      decode64($1)
  10    }
  11    str = Kconv::toeuc(str)
  12    str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
  13      decode64($1)
  14    }
  15    str = Kconv::toeuc(str)
  16    str.gsub!(/\n/, ' ') 
  17    str.gsub!(/\0/, '')
  18    str
  19  end
  20  
  21  def encode64(bin)
  22    [bin].pack("m")
  23  end
  24  
  25  def b64encode(bin, len = 60)
  26    encode64(bin).scan(/.{1,#{len}}/o) do
  27      print $&, "\n"
  28    end
  29  end