Method: Rex::Text.b32encode

Defined in:
lib/rex/text/base32.rb

.b32encode(bytes_in) ⇒ Object

Base32 encoder



39
40
41
42
43
44
45
# File 'lib/rex/text/base32.rb', line 39

def self.b32encode(bytes_in)
  n = (bytes_in.length * 8.0 / 5.0).ceil
  p = n < 8 ? 5 - (bytes_in.length * 8) % 5 : 0
  c = bytes_in.inject(0) {|m,o| (m << 8) + o} << p
  [(0..n-1).to_a.reverse.collect {|i| Base32[(c >> i * 5) & 0x1f].chr},
   ("=" * (8-n))]
end