classBase64Class
remConst
dimsBASE_64_CHARACTERS'转化码
dimlenString'计算字符串的长度
dimiCount'计数器
dimreturnValue'返回值
dimtempChar'缓存字符
dimtempString'缓存字符串
dimparamString'参数字符串
dimtemHex'缓存缓存十六进制
dimtempLow'缓存低位
dimtempHigh'缓存高位
dimmod3String'
dimmod4String'
dimtempBinary'
dimtempByteOne'
dimtempByteTwo'
dimtempByteThree'
dimtempByteFour'
dimtempSaveBitsOne'
dimtempSaveBitsTwo'
'********************************************
'begin初始化类
'********************************************
privatesubClass_Initialize()
sBASE_64_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"endsub
'********************************************
'end初始化类'
********************************************
'********************************************
'begin销毁类
'********************************************
PrivateSubClass_Terminate()
sBASE_64_CHARACTERS=""endsub
'********************************************
'end销毁类
'********************************************
'********************************************
'begin将Ansi编码的字符串进行Base64编码
'********************************************
publicfunctionEncode(paramString)
tempString=""
returnValue=""
lenString=len(paramString)
iflenString<1then
Encode=returnValue
else
mod3String=lenStringmod3
'补足位数是为了便于计算
ifmod3String>0then
lenString=lenString+3-mod3String
lenString=lenString-3
endif
'*************************begin
foriCount=1tolenStringstep3
tempBinary=Mid(paramString,iCount,3)
'response.writetempBinary
tempByteOne=Asc(Mid(tempBinary,1,1)):tempSaveBitsOne=tempByteOneAnd3
tempByteTwo=Asc(Mid(tempBinary,2,1)):tempSaveBitsTwo=tempByteTwoAnd15
tempChar=Asc(Mid(tempBinary,3,1))
tempByteOne=Mid(sBASE_64_CHARACTERS,((tempByteOneAnd252)4)+1,1)
tempByteTwo=Mid(sBASE_64_CHARACTERS,(((tempByteTwoAnd240)16)Or(tempSaveBitsOne*16)And&HFF)+1,1)
tempByteThree=Mid(sBASE_64_CHARACTERS,(((tempCharAnd192)64)Or(tempSaveBitsTwo*4)And&HFF)+1,1)
tempByteFour=Mid(sBASE_64_CHARACTERS,(tempCharAnd63)+1,1)
tempString=tempByteOne&tempByteTwo&tempByteThree&tempByteFourreturnValue=returnValue&tempStringnext
'*************************end
'*************************begin处理最后剩余的几个字符
ifmod3String>0then
tempBinary=Mid(paramString,iCount,mod3String)
ifmod3String=1then
tempString=tempBinary&Chr(64)&Chr(64)&Chr(64)'用@号补足位数
elsetempString=tempBinary&Chr(64)&Chr(64)'用@号补足位数
endif
returnValue=returnValue&tempString
endif
'*************************end处理最后剩余的几个字符
Encode=returnValueendifendfunction
'********************************************
'end将Ansi编码的字符串进行Base64编码
'********************************************
'********************************************
'end将Base64编码字符串转换成Ansi编码的字符串
'********************************************
publicfunctionDecode(paramString)
tempString=""
returnValue=""
lenString=len(paramString)
iflenString<1then
Decode=returnValue
else
mod4String=lenStringmod4
ifmod4String>0then'字符串长度应当是4的倍数
Decode=returnValue
else'begin判断是不是@号
ifMid(paramString,lenString-1,1)="@"then
mod4String=2
endif
ifMid(paramString,lenString-2,1)="@"then
mod4String=1
endif
'end判断是不是@号
ifmod4String>0then
lenString=lenString-4
endif
'******************************begin
foriCount=1tolenStringstep4
tempString=Mid(paramString,iCount,4)
tempByteOne=InStr(sBASE_64_CHARACTERS,Mid(tempString,1,1))-1
tempByteTwo=InStr(sBASE_64_CHARACTERS,Mid(tempString,2,1))-1
tempByteThree=InStr(sBASE_64_CHARACTERS,Mid(tempString,3,1))-1
tempByteFour=InStr(sBASE_64_CHARACTERS,Mid(tempString,4,1))-1
tempByteOne=Chr(((tempByteTwoAnd48)16)Or(tempByteOne*4)And&HFF)tempByteTwo=""&Chr(((tempByteThreeAnd60)4)Or(tempByteTwo*16)And&HFF)
tempByteThree=Chr((((tempByteThreeAnd3)*64)And&HFF)Or(tempByteFourAnd63))
tempString=tempByteOne&tempByteTwo&tempByteThree
returnValue=returnValue&tempString
next
'******************************end
'处理最后剩余的几个字符
ifmod4String>0then
tempString=left(right(paramString,4),mod4String)
returnValue=returnValue&tempString
endif
Decode=returnValue
endif
endif
endfunction
'********************************************
'end将Base64编码字符串转换成Ansi编码的字符串
'********************************************
endclass
|