module Ronin::Support::Encoding::Base32

Base32

encoding.

[Base32]: datatracker.ietf.org/doc/html/rfc3548#page-6

## Core-Ext Methods

@api public

@since 1.0.0

Constants

TABLE

Base32 alphabet

@api private

Public Class Methods

decode(data) click to toggle source

Base32 decodes the given String.

@param [String] data

The String to decode.

@return [String]

The Base32 decoded String.
# File lib/ronin/support/encoding/base32.rb, line 65
def self.decode(data)
  decoded = String.new(encoding: Encoding::UTF_8)

  each_chunk(data,8) do |chunk|
    chunk.decode(decoded)
  end

  return decoded
end
each_chunk(data,size) { |chunk| ... } click to toggle source

Enumerates over the consecutive chunks within the given data.

@param [String] data

@param [Integer] size

@yield [chunk]

@yieldparam [Chunk] chunk

@api private

# File lib/ronin/support/encoding/base32.rb, line 170
def self.each_chunk(data,size)
  data.bytes.each_slice(size) do |byte_slice|
    yield Chunk.new(byte_slice)
  end
end
encode(data) click to toggle source

Base32 encodes the given String.

@param [String] data

The String to encode.

@return [String]

The Base32 encoded String.
# File lib/ronin/support/encoding/base32.rb, line 46
def self.encode(data)
  encoded = String.new

  each_chunk(data,5) do |chunk|
    chunk.encode(encoded)
  end

  return encoded
end