Method: Rex::Text.b32decode

Defined in:
lib/rex/text.rb

.b32decode(bytes_in) ⇒ Object

Base32 decoder



1101
1102
1103
1104
1105
1106
1107
# File 'lib/rex/text.rb', line 1101

def self.b32decode(bytes_in)
  bytes = bytes_in.take_while {|c| c != 61} # strip padding
  n = (bytes.length * 5.0 / 8.0).floor
  p = bytes.length < 8 ? 5 - (n * 8) % 5 : 0
  c = bytes.inject(0) {|m,o| (m << 5) + Base32.index(o.chr)} >> p
  (0..n-1).to_a.reverse.collect {|i| ((c >> i * 8) & 0xff).chr}
end