<%
'程序设计,环球万维:http://www.netinter.cn
'专业提供域名注册,虚拟主机服务
''以上信息与文章正文是不可分割的一部分,所以如果您要转载本文章,您必须保留以上信息.

function bin2dec(binstr)
towpow=1
numlen=len(binstr)
bin2dec=0
decpos=numlen
do while decpos>0
cchar=mid(binstr,decpos,1)
nchar=cint(cchar)
bin2dec=bin2dec+nchar*towpow
towpow=towpow*2
decpos=decpos-1
loop
end function

function dec2bin(octnumber)
vara=octnumber
do
dec2bin=cstr(vara mod 2) & dec2bin
vara=vara 2
loop until vara=0
end function

bstr_base64="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="
function encode_base64(strbin)
bins=""
for i=1 to lenb(strbin)
vartm=ascb(midb(strbin,i,1))
bins=bins & right("00000000" & dec2bin(vartm),8)
if i mod 3=0 then
for w=0 to 3
sixbin=mid(bins,w*6+1,6)
nchar=bin2dec(sixbin)+1
encode_base64=encode_base64 & mid(bstr_base64,nchar,1)
next
bins=""
end if
next

if bins<>"" then
pads=3-len(bins) 8
exitloop=false
do while not exitloop
nchar=left(bins,6)
if len(nchar)<6 then
nchar=left(nchar & "000000",6)
exitloop=true
end if
nnum=bin2dec(nchar)+1
encode_base64=encode_base64 & mid(bstr_base64,nnum,1)
bins=mid(bins,7)
loop
encode_base64=encode_base64 & string(pads,"=")
end if
end function

function decode_base64(basestr)
if len(basestr) mod 4 <>0 then
exit function
end if
bins=""
for i=1 to len(basestr)
nchar=mid(basestr,i,1)
if nchar="=" then
exit for
end if
oldvalue=instr(bstr_base64,nchar)-1
binvalue=right("000000" & dec2bin(oldvalue),6)
bins=bins & binvalue

if len(bins)>=8 then
dechar=left(bins,8)
bins=mid(bins,9)
decode_base64=decode_base64 & chrb(bin2dec(dechar))
end if
next
end function


%>