Ruby B64 encoding & decoding class
Hi. This is a simple class written in Ruby, which is to encode and decode integers into their b64 equivalent.
Code:
#B64 encoding in Ruby
#You must retain this notice if you wish to use it
class B64
def self.encodeInt32(value,length)
stack = ""
1.step(length) { |x|
offset = 6 * (length - x)
val = (64 + ( value >> offset & 0x3f))
stack << val
}
return stack
end
def self.decodeInt(strVal)
val = strVal
intTot = 0
y = 0
x = (val.length - 1)
while x >= 0
intTmp = ((val[x] - 64))
if y > 0 then
intTmp = intTmp * ((64 ^ y))
end
intTot += intTmp
y += 1
x -= 1
end
return intTot
end
end
This class serves two static methods; encode and decode. You can use this as so:
Code:
#require 'b64.rb' if you have it elsewhere
puts B64.encodeInt32(12,2)
puts B64.decodeInt("@L")
Screenshot:
http://i.imgur.com/3Plzj.png
Enjoy!
(VL64 should be coming soon - having a bit of difficulty atm. If you want me to release encoding and decoding for the new protocol, I will.)
This is based off JoeH's class
Re: Ruby B64 encoding & decoding class
Why ruby?
I think it's good, but I don't like ruby really much. Good job.
Re: Ruby B64 encoding & decoding class
Quote:
Originally Posted by
George2000
Why ruby?
I think it's good, but I don't like ruby really much. Good job.
Ruby's a nice language, good for simple, on the fly stuff :P
Re: Ruby B64 encoding & decoding class
I don't know what it is, but that code makes my head explode;s
Re: Ruby B64 encoding & decoding class
Quote:
Originally Posted by
SuckLake
I don't know what it is, but that code makes my head explode;s
It's the Base64 encoding to convert for example @A into 1 written in Ruby.
It's the encoding for Habbo V5 - R63a
Re: Ruby B64 encoding & decoding class
I'm no Ruby user, but from what I can see there is already a Base64 module for Ruby. Why reinvent the wheel?
But good effort either way.
Re: Ruby B64 encoding & decoding class
Quote:
Originally Posted by
Funixeh
I'm no Ruby user, but from what I can see there is already a Base64 module for Ruby. Why reinvent the wheel?
But good effort either way.
In C# there's also something with B64, but it isn't the same as 'Habbo's B64'
Re: Ruby B64 encoding & decoding class
Quote:
Originally Posted by
Caustik
There's a difference.. That's why I try refrain from calling it Base64
Oh, right. The file looks slightly confusing this way.