Module: Ronin::Support::Encoding::Base32

Defined in:
lib/ronin/support/encoding/base32.rb

Overview

Base32 encoding.

Core-Ext Methods

Since:

  • 1.0.0

Defined Under Namespace

Classes: Chunk

Constant Summary collapse

TABLE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Base32 alphabet

Since:

  • 1.0.0

'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'

Class Method Summary collapse

Class Method Details

.decode(data) ⇒ String

Base32 decodes the given String.

Parameters:

  • data (String)

    The String to decode.

Returns:

  • (String)

    The Base32 decoded String.

Since:

  • 1.0.0



65
66
67
68
69
70
71
72
73
# 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| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerates over the consecutive chunks within the given data.

Parameters:

Yields:

  • (chunk)

Yield Parameters:

Since:

  • 1.0.0



170
171
172
173
174
# 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) ⇒ String

Base32 encodes the given String.

Parameters:

  • data (String)

    The String to encode.

Returns:

  • (String)

    The Base32 encoded String.

Since:

  • 1.0.0



46
47
48
49
50
51
52
53
54
# 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