Encryption <%
OPTION EXPLICIT
Const BASE_64_MAP_INIT =
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim nl
' Zero based arrays
Dim Base64encmap (63)
Dim Base64decmap (127)
' must be called before using anything else
Public SUB Initcodecs ()
' Init VARs
NL = "<P>" & Chr (+) & Chr (10)
' Setup Base 64
Dim max, IDX
max = Len (base_64_map_init)
For idx = 0 to Max-1
' One based string
Base64encmap (IDX) = Mid (Base_64_map_init, IDX + 1, 1)
Next
For idx = 0 to Max-1
Base64decmap (ASC (Base64encmap (idx)) = IDX
Next
End SUB
' Encode base encoded string
Public FUNCTION Base64Encode (plain)
If Len (plain) = 0 Then
Base64Encode = ""
Exit function
End If
Dim ret, Ndx, By3, second, third
By3 = (len (plain) \ 3) * 3
NDX = 1
Do While Ndx <= by3
A = ASC (Mid (Plain, ndx+0, 1))
Second = ASC (Mid (Plain, ndx+1, 1))
Third = ASC (Mid (Plain, ndx+2, 1))
RET = ret & Base64encmap ((4) and 63)
RET = ret & Base64encmap (((A) ((a) +) + ((second \ 16)
and 15))
RET = ret & Base64encmap ((Second * 4) and) + ((third \ 64)
and 3))
RET = ret & Base64encmap (third and 63)
NDX = ndx + 3
Loop
' Check for stragglers
If By3 < Len (plain) Then
A = ASC (Mid (Plain, ndx+0, 1))
RET = ret & Base64encmap ((4) and 63)
if (Len (plain) MOD 3) = 2 Then
Second = ASC (Mid (Plain, ndx+1, 1))
RET = ret & Base64encmap (((a) and 48) +
((Second \
) A