Base62 Decoding Short Codes Discussion
Discussion for
Base62 Decoding Short Codes
Intresting, I had the same requirement so I created this gem https://github.com/xiaohui-zhangxh/xencoder , it can encode/decode interger to BaseX and prevent it to be decoded without seed
How nice to discover ".reverse.each_char.with_index"... much cleaner than the implementation that I was working on!
Thank you very much for all of your work! You are my teacher!
Also, I think I have a better implementation of the decoding algorithm (since ** is a costly operation):
def self.decode(string)
number = 0
string.each_char.with_index do |char, index|
number = ALPHABET.index(char) + number * BASE
end
number
end