class BaseConvert::Entropia

Attributes

bits[R]
entropy[R]
length[R]

Public Class Methods

bits_length_entropy(bits_request, base) click to toggle source
# File lib/base_convert/entropia.rb, line 3
def Entropia.bits_length_entropy(bits_request, base)
  n,e,entropy = 0,1,2**bits_request
  while e < entropy
    n += 1
    e *= base
  end
  b=Math.log(e,2)
  # Actual bits, length, and entropy
  return b,n,e
end
new(counter=nil, base: 95, digits: :P95, validate: true, bits: 256, rng: Random) click to toggle source
Calls superclass method
# File lib/base_convert/entropia.rb, line 15
def initialize(counter=nil, base: 95, digits: :P95, validate: true,
               bits: 256, rng: Random)
  @bits,@length,@entropy = Entropia.bits_length_entropy(bits,base)
  counter = rng.random_number(@entropy) unless counter
  super(counter, base:base, digits:digits, validate:validate)
end

Public Instance Methods

to_s() click to toggle source
# File lib/base_convert/entropia.rb, line 22
def to_s
  (@length - (string=tos).length).times{string.prepend self.digits[0]}
  return string
end