本文介绍了Crockford的Base32编码的经典ASP/VBScript实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的第一部分开始,我现在正在尝试编写经典的ASP/VBScript Douglas Crockford的Base32编码的实现.

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).

推荐答案

第一次运行...这看起来正确吗?

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

到目前为止似乎还可以正常工作...除非有人发布更好的内容,否则我将继续使用它.

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

这篇关于Crockford的Base32编码的经典ASP/VBScript实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:26