Sha256: 8dad8262227d0288350afb7af85b7fb1c9de5d023a69bd6a7cfd5aae3f067cd7
Contents?: true
Size: 528 Bytes
Versions: 2
Compression:
Stored size: 528 Bytes
Contents
module Firefly class Base62 CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split('') BASE = 62 def self.encode(value) s = [] while value >= BASE value, rem = value.divmod(BASE) s << CHARS[rem] end s << CHARS[value] s.reverse.to_s end def self.decode(str) str = str.split('').reverse total = 0 str.each_with_index do |v,k| total += (CHARS.index(v) * (BASE ** k)) end total end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
firefly-0.2.0 | lib/firefly/base62.rb |
firefly-0.1.0 | lib/firefly/base62.rb |