Ask A Question


You’re not receiving notifications from this thread.

Base62 Decoding Short Codes Discussion

Intresting, I had the same requirement so I created this gem , 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



Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,160+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.