Ruby B64 encoding & decoding class

Results 1 to 9 of 9
  1. #1
    Alpha Member Caustik is offline
    MemberRank
    May 2011 Join Date
    LondonLocation
    1,837Posts

    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:


    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
    Last edited by Caustik; 11-10-16 at 06:59 PM.


  2. #2
    Account Upgraded | Title Enabled! George2000 is offline
    MemberRank
    Jul 2011 Join Date
    The NetherlandsLocation
    1,150Posts

    Re: Ruby B64 encoding & decoding class

    Why ruby?
    I think it's good, but I don't like ruby really much. Good job.

  3. #3
    Alpha Member Caustik is offline
    MemberRank
    May 2011 Join Date
    LondonLocation
    1,837Posts

    Re: Ruby B64 encoding & decoding class

    Quote Originally Posted by George2000 View Post
    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

  4. #4
    Zephyr Studios PRIZM is offline
    MemberRank
    Feb 2012 Join Date
    DenmarkLocation
    2,291Posts

    Re: Ruby B64 encoding & decoding class

    I don't know what it is, but that code makes my head explode;s

  5. #5
    Account Upgraded | Title Enabled! George2000 is offline
    MemberRank
    Jul 2011 Join Date
    The NetherlandsLocation
    1,150Posts

    Re: Ruby B64 encoding & decoding class

    Quote Originally Posted by SuckLake View Post
    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

  6. #6
    beep Bui is offline
    MemberRank
    Jan 2012 Join Date
    United KingdomLocation
    459Posts

    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.

  7. #7
    Account Upgraded | Title Enabled! George2000 is offline
    MemberRank
    Jul 2011 Join Date
    The NetherlandsLocation
    1,150Posts

    Re: Ruby B64 encoding & decoding class

    Quote Originally Posted by Funixeh View Post
    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'

  8. #8
    Alpha Member Caustik is offline
    MemberRank
    May 2011 Join Date
    LondonLocation
    1,837Posts
    Quote Originally Posted by Funixeh View Post
    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.
    There's a difference.. That's why I try refrain from calling it Base64

  9. #9
    beep Bui is offline
    MemberRank
    Jan 2012 Join Date
    United KingdomLocation
    459Posts

    Re: Ruby B64 encoding & decoding class

    Quote Originally Posted by Caustik View Post
    There's a difference.. That's why I try refrain from calling it Base64
    Oh, right. The file looks slightly confusing this way.



Advertisement