0

Moving on from the first part of my problem, I'm now working on trying to write a Classic ASP/VBScript implementation of Douglas Crockford's Base32 Encoding.

Time is tight on this particular project, so while I am working this out on my own, I'm hoping someone has something readily at hand (or can at least whip one up faster than I can).

Community
  • 1
  • 1
AnonJr
  • 2,759
  • 1
  • 26
  • 39

2 Answers2

1

the chosen answer may work, but note

TOTP Base32 vs Base64

One important and simple reason and why Base32 even exists is that it uses A-Z uppercase only (no lowercase) and the numbers 2-7. No 0189. 26 + 6 chars = 32.

Hence, I would change the constant:

Const kBase32Digits = "234567ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Alex
  • 11
  • 2
  • For various TOTP implementations, sure. The article in the original question cited _We chose a symbol set of 10 digits and 22 letters. We exclude 4 of the 26 letters: I L O U_. Since it was intended to be an implementation of the article, I used that constant. – AnonJr Mar 19 '22 at 02:45
0

First run... does this look about right?

'Base32 encoding functions for shorter, less confusing verification numbers'
Const kBase32Digits = "0123456789abcdefghjkmnpqrstvwxyz"
'To Base32'
Function ToBase32(ByVal lInput)
    Dim lModulo, sTemp
    Do Until lInput = 0
        lModulo = lInput Mod 32
        sTemp = Mid(kBase32Digits, lModulo + 1, 1) & sTemp
        lInput = lInput \ 32
    Loop
    ToBase32 = sTemp
End Function
'From Base32'
Function FromBase32(ByVal sInput)
    Dim sTemp, sR, i,iY,lLen, zMultiplier
    sTemp = LCase(sInput)
    sTemp = Replace(sTemp,"o","0")
    sTemp = Replace(sTemp,"i","1")
    sTemp = Replace(sTemp,"l","1")
    sTemp = Replace(sTemp,"u","v")
    zMultiplier = 1
    lLen = Len(sTemp)
    For i = lLen To 1 Step -1
        sR = Mid(sTemp, i, 1)
        iY = InStr(1, kBase32Digits, sR, vbTextCompare) - 1
        FromBase32 = FromBase32 + iY * zMultiplier
        zMultiplier = zMultiplier * 32
    Next
End Function

Edit: Seems to work fine so far... I'll go with this unless someone posts something better.

AnonJr
  • 2,759
  • 1
  • 26
  • 39