vbscript – base32/base36 (base62) encoding

Base32/Base36 (or even Base62)encoding/decoding.

<%
Const kBase62Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Function ToBase62(ByVal lInput)
    Dim lModulo
    Dim sTemp

    Do Until lInput = 0                                
        lModulo = lInput Mod 62                        
        sTemp = Mid(kBase62Digits, lModulo + 1, 1) & sTemp
        lInput = lInput \ 62                           
    Loop
    ToBase62 = sTemp                                   
End Function

Function FromBase62(ByVal sInput)
    Dim sR
    Dim i,iY,lLen
    Dim zMultiplier

    zMultiplier = 1                                    
    lLen = Len(sInput)                                 
    For i = lLen To 1 Step -1                          
        sR = Mid(sInput, i, 1)                         
        iY = InStr(1, kBase62Digits, sR, vbBinaryCompare) - 1
        FromBase62 = FromBase62 + iY * zMultiplier   
        zMultiplier = zMultiplier * 62                 
    Next
End Function
%>
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s