Class: ROTP::Base32

Inherits:
Object
  • Object
show all
Defined in:
lib/rotp/base32.rb

Constant Summary collapse

CHARS =
"abcdefghijklmnopqrstuvwxyz234567".each_char.to_a

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rotp/base32.rb', line 6

def decode(str)
  output = []
  str.scan(/.{8}/).each do |block|
    char_array = decode_block(block).map{|c| c.chr}
    output << char_array
  end
  output.join
end

.random_base32(length = 16) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rotp/base32.rb', line 15

def random_base32(length=16)
  b32 = ''
  OpenSSL::Random.random_bytes(length).each_byte do |b|
    b32 << CHARS[b % 32]
  end
  b32
end