module PrettyNumber
Constants
- DefaultEncryptArray
- VERSION
Public Class Methods
decrypt(encryption_code)
click to toggle source
# File lib/pretty_number.rb, line 31 def self.decrypt encryption_code begin radix = encrypt_array.count secret_hash = Hash[encrypt_array.map.with_index.to_a] convert_array = encryption_code.each_char.map{|i| secret_hash[i]} number = 0 convert_array.reverse.each_with_index do |i, index| number += i*radix**index end return number rescue => e return nil end end
encrypt(number)
click to toggle source
# File lib/pretty_number.rb, line 15 def self.encrypt number begin radix = encrypt_array.count convert_array =[] while number != 0 do merchant, arithmetical_compliment = number.divmod radix convert_array << arithmetical_compliment number = merchant end convert_array = [0] if convert_array.empty? secret_str = convert_array.reverse.map{|i| encrypt_array.at(i)}.join rescue => e return nil end end
encrypt_array()
click to toggle source
# File lib/pretty_number.rb, line 11 def self.encrypt_array encrypt_array = @encrypt_array || DefaultEncryptArray end
init(encrypt_array)
click to toggle source
# File lib/pretty_number.rb, line 6 def self.init encrypt_array @encrypt_array = encrypt_array.is_a?(Array) ? encrypt_array : nil return self end