codice:
<%
Class cStringBuilder
Private Count
Private arLength
Private arStrings()
Public Increment
Private Sub Class_Initialize()
Clear()
End Sub
Public Function Clear()
Count = 0
Increment = 1000
Redim arStrings(0)
arLength = 1
End Function
Public Sub Write(value)
if Count=arLength then
arLength=Count+Increment
Redim Preserve arStrings(arLength)
end if
arStrings(Count)=value
Count=Count+1
End Sub
Public Property Let Value(strValue)
Clear()
Write strValue
End Property
Public default Property Get Value()
Value = Join(arStrings,"")
End Property
Private Sub Class_Terminate()
Erase arStrings
End Sub
End Class
Class cBase64
Private Base64Chars
Private arBase64Chars
Private Length
Private Sub Class_Initialize()
Base64Chars = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn
opqrstuvwxyz0123456789+/"
arBase64Chars = Array(" ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/")
End Sub
Public Function Decode(strIn)
Dim w1, w2, w3, w4, n, strOut
Set strOut = new cStringBuilder
Length = Len(strIn)
For n = 1 To Length Step 4
w1 = mimedecode(Mid(strIn,n,1))
w2 = mimedecode(Mid(strIn,n+1,1))
w3 = mimedecode(Mid(strIn,n+2,1))
w4 = mimedecode(Mid(strIn,n+3,1))
If w2 >= 0 Then strOut.Write Chr(((w1 * 4 + (w2 \ 16)) And 255))
If w3 >= 0 Then strOut.Write Chr(((w2 * 16 + (w3 \ 4)) And 255))
If w4 >= 0 Then strOut.Write Chr(((w3 * 64 + w4) And 255))
Next
Decode = strOut.Value
Set strOut = Nothing
End Function
Public Function Encode(strIn)
Dim c1, c2, c3, w3, w4, n , strOut , chr0 ,ar
Set strOut = new cStringBuilder
chr0 = Chr(0)
Length = Len(strIn)
For n = 1 To Length Step 3
c1 = Asc(Mid(strIn, n, 1))
c2 = Asc(Mid(strIn, n + 1, 1) + chr0)
c3 = Asc(Mid(strIn, n + 2, 1) + chr0)
If Length >= n + 1 Then
w3 = (c2 And 15) * 4 + (c3 \ 64)
Else
w3 = -1
End If
If Length >= n + 2 Then
w4 = c3 And 63
Else
w4 = -1
End If
strOut.Write mimeencode(c1 \ 4) + mimeencode((c1 And 3) * 16 + (c2 \ 16)) + mimeencode(w3) + mimeencode(w4)
Next
on error goto 0
Encode = strOut.Value
Set strOut = Nothing
End Function
Private Function mimeencode(intIn)
if intIn>=0 then
mimeencode = arBase64Chars(intIn)
else
mimeencode = ""
End if
End Function
Private Function mimedecode(strIn)
If strIn = "" Then
mimedecode = -1
Else
mimedecode = InStr(Base64Chars, strIn) - 1
End If
End Function
End Class
%>