比网上搜索来的短一些
Public Function Base64Encode(ByVal srcCode As String,Optional ByVal Base64table As String = "") Dim I As Integer,Result As String,Arr() As Byte If Len(Base64table) <> 64 Then Base64table = "ABCDEFGHIJKLMnopQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" End If Arr = StrConv(srcCode,vbFromUnicode) For I = 0 To UBound(Arr) Select Case I Mod 3 Case 0 Result = Result & MID(Base64table,Arr(I) \ 4 + 1,1) If I = UBound(Arr) Then Result = Result & MID(Base64table,(Arr(I) And 3) * 16 + 1,1) End If Case 1 Result = Result & MID(Base64table,(Arr(I - 1) And 3) * 16 + Arr(I) \ 16 + 1,(Arr(I) And 15) * 4 + 1,1) End If Case 2 Result = Result & MID(Base64table,(Arr(I - 1) And 15) * 4 + Arr(I) \ 64 + 1,1) Result = Result & MID(Base64table,(Arr(I) And 63) + 1,1) End Select Next Base64Encode = ResultEnd FunctionPublic Function Base64Decode(ByVal srcCode As String,Optional ByVal Base64table As String = "") As String Dim I As Integer,C As Integer,Result() As Byte,Arr() As Byte srcCode = Replace(srcCode,"=","") If Len(Base64table) <> 64 Then Base64table = "ABCDEFGHIJKLMnopQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" End If For I = 1 To Len(srcCode) If InStr(Base64table,MID(srcCode,I,1)) = 0 Then Exit Function Next ReDim Result(Len(srcCode) * 3 \ 4 - 1) For I = 0 To UBound(Result) C = I * 4 \ 3 + 1 Result(I) = InStr(Base64table,C,1)) - 1 Select Case I Mod 3 Case 0 Result(I) = Result(I) * 4 If C + 1 <= Len(srcCode) Then Result(I) = Result(I) + (InStr(Base64table,C + 1,1)) - 1) \ 16 End If Case 1 Result(I) = (Result(I) And 15) * 16 If C + 1 <= Len(srcCode) Then Result(I) = Result(I) + (InStr(Base64table,1)) - 1) \ 4 End If Case 2 Result(I) = (Result(I) And 3) * 64 + InStr(Base64table,1)) - 1 End Select Next Base64Decode = StrConv(Result,vbUnicode)End Function总结
以上是内存溢出为你收集整理的Base64算法函数VB6全部内容,希望文章能够帮你解决Base64算法函数VB6所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)