Created
September 24, 2012 02:48
-
-
Save atomaka/3773932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BASE52_CHARACTERS = Array('0'..'9') + Array('A'..'Z') + Array('a'..'z') - 'AEIOUaeiou'.split(//) | |
class String | |
def from_52 | |
i = 0 | |
decoded = 0 | |
self.split(//).reverse.each do |a| | |
place = 52 ** i | |
decoded += BASE52_CHARACTERS.index(a) * place | |
i += 1 | |
end | |
decoded | |
end | |
end | |
class Integer | |
def to_52 | |
input = self | |
encoded = '' | |
while input > 0 | |
encoded = BASE52_CHARACTERS[input % 52].to_s + encoded | |
input /= 52 | |
end | |
encoded | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment