Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class String
- def base60_decode
- n = 0
- self.each_byte do |c|
- case
- when c >= 48 && c <= 57
- c -= 48
- when c >= 65 && c <= 72
- c -= 55
- when c == 73 || c == 108
- c = 1
- when c >= 74 && c <= 78
- c -= 56
- when c == 79
- c = 0
- when c >= 80 && c <= 90
- c -= 57
- when c == 95
- c = 34
- when c >= 97 && c <= 107
- c -= 62
- when c >= 109 && c <= 122
- c -= 63
- else
- c = 0
- end
- n = (60 * n) + c
- end
- n
- end
- end
- class Integer
- BASE60_MAP = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"
- def base60_encode
- return self if self == 0
- s = ""
- n = self
- while n > 0 do
- d = n % 60;
- s = BASE60_MAP[d] + s;
- n = (n-d)/60;
- end
- s
- end
- end
Add Comment
Please, Sign In to add comment