class VagrantPlugins::Share::Helper::WordList

Constants

LIST

Word list content

Public Class Methods

decode(words) click to toggle source

Decode given words to number

@param [Array<String>] words @return [Integer]

# File lib/vagrant-share/helper/word_list.rb, line 539
def self.decode(words)
  result = ""
  words.each_with_index do |word, idx|
    key = idx % 2 == 1 ? "odd" : "even"
    result << LIST[key].key(word).to_s
  end
  result.to_i(16)
end
encode(number) click to toggle source

Encode given number to words

@param [Integer] number @return [Array<String>]

# File lib/vagrant-share/helper/word_list.rb, line 524
def self.encode(number)
  hex = number.to_s(16)
  hex = "0#{hex}" if hex.size % 2 == 1
  result = []
  hex.scan(/.{2}/).each_with_index do |value, idx|
    key = idx % 2 == 1 ? "odd" : "even"
    result << LIST[key][value.upcase]
  end
  result.compact
end