< / DIV> td> tr> table> form> <%
SBASE_64_CHARACTERS = "AbcdefghijklmnopqrStuvwxyzabcdefghijklmnopqrStuvwxyz0123456789 /" SBASE_64_Characters = Strunicode2ansi (SBASE_64_Characlet)
Function strunicodelen (ascontents) 'Calculate the length of ANSI encoding of Unicode strings ascontents1 = "a" & ascontentslen1 = len (ascontents1) k = 0for i = 1 to len1ASC1 = ASC (MID (AsconTents1, i, 1)) IF ASC1 <0 THEN ASC1 = 65536 ASC1IF ASC1> 255 THENK = K 2ELSEK = K 1END IFNEXTSTRUNICODELEN = K-1END FUNCTION
Function strunicode2ansi (ascontents) 'converts Unicode encoded strings to ANSI encoded strings strunicode2ansi = "" len1 = len (ascontents) for i = 1 to len1varchar = MID (AsconTents, I, 1) Varasc = ASC (varchar) ) if varasc <0 then varasc = varasc 65536if varasc> 255 thenvarHex = Hex (varasc) varlow = left (varHex, 2) varhigh = right (varHex, 2) strUnicode2Ansi = strUnicode2Ansi & chrb ( "& H" & varlow) & chrb ( "& H" & varhigh) elsestrUnicode2Ansi = strUnicode2Ansi & chrb (varasc) end ifnextEnd functionFunction strAnsi2Unicode (asContents) 'the Ansi encoded string, is converted into a Unicode string strAnsi2Unicode = "" len1 = lenb (asContents) if len1 = 0 THEN EXIT FUNCTIONFOR I = 1 to Len1varchar = MIDB (Ascontents, I, 1) Varasc = ASCB (varchar) IF Varasc> 127 Then Stransi2Unicode = Stransi2Unicode & Chr (ASCW (MIDB (AsconTents, i 1, 1) & varchar) i = i 1ELSESTRANSI2UNICODE = STRANSI2UNICODE & CHR (VARASC) End ifnextend Function
Function Base64encode (asContents) 'the Ansi Base64 encoded encoded string' asContents ANSI should be encoded string (binary string may be) Dim lnPosition Dim lsResult Dim Char1 Dim Char2 Dim Char3 Dim Char4 Dim Byte1 Dim Byte2 Dim Byte3 DIM Savebits1 Dim SaveBits2 Dim Lsgroupbinary Dim Lsgroup64 Dim M4, Len1, Len2
Len1 = lenb (ascontents) if len1 <1 dama64encode = "" EXIT FUNCTIONEND IF
M3 = len1 mod 3 if m3> 0 Then Ascontents = Ascontents & String (3-m3, chrb (0)) 'Supplement bits are for easy calculations
IF m3> 0 THEN LEN1 = LEN1 (3-M3) len2 = len1-3elselen2 = len1nd if
LsResult = ""
For lnposition = 1 to len2 step 3 lsgroup64 = "" lsgroupbinary = MIDB (Ascontents, LnPosition, 3)
BYTE1 = ASCB (MIDB (Lsgroupbinary, 1, 1): SaveBits1 = BYTE1 AND 3 BYTE2 = ASCB (MIDB (LsGroupBinary, 2, 1)): SaveBits2 = Byte2 and 15 Byte3 = ASCB (MIDB (Lsgroupbinary, 3, 1) CHAR1 = MIDB (SBASE_64_Characters, ((Byte1 and 252) / 4) 1, 1) Char2 = MIDB (SBase_64_Characters, ((Byte2 and 240) / 16) or (SaveBits1 * 16) And & HFF) 1, 1 CHAR3 = MIDB (SBASE_64_Characters ((Byte3 and 192) / 64) or (SaveBits2 * 4) and & HFF) 1, 1) Char4 = MIDB (SBase_64_Characters, (Byte3 and 63) 1, 1) lsgroup64 = char1 & Char2 & char3 & char4
LsResult = lsResult & lsgroup64 Next
'Handling the last remaining characters IF M3> 0 Thenlsgroup64 = "" "" LsGroupBinary = MIDB (Ascontents, Len2 1, 3)
BYTE1 = ASCB (MIDB (Lsgroupbinary, 1, 1): SaveBits1 = BYTE1 AND 3 BYTE2 = ASCB (MIDB (LsGroupBinary, 2, 1)): SaveBits2 = Byte2 and 15 Byte3 = ASCB (MIDB (Lsgroupbinary, 3, 1) )
Char1 = MIDB (SBASE_64_Characters, (Byte1 and 252) / 4) 1, 1) Char2 = MIDB (SBase_64_Characters, (((Byte2 and 240) / 16) or (SaveBits1 * 16) And & HFF) 1, 1) Char3 = MIDB (SBASE_64_Characters, ((Byte3 and 192) / 64) or (SaveBits2 * 4) And & HFF) 1, 1)
IF m3 = 1 kil2 & chrb (61) & chrb (61) 'Use = 号 补 位 位 ELSELSGROUP64 = char1 & char2 & char3 & chrb (61)' Use = 号 补 补 号 END IF
LsResult = lsResult & lsgroup64 endiff
Base64encode = lsresult
END FUNCTION
Function base64decode (ascontents) 'Convert Base64 encoded strings to ANSI encoded strings' ascontents should also be ANSI encoded strings (binary strings can also be) DIM LSRESULT DIM LNPSITION DIM LSGROUP64, LSGROUPBINARY DIM CHAR1, CHAR2, CHAR3, Char4 Dim Byte1, Byte2, Byte3 Dim M4, LEN1, LEN2LEN1 = LeNB (Ascontents) M4 = LEN1 MOD 4
If Len1 <1 or M4> 0 THEN 'string length should be 4 multiples64decode = "" EXIT FUNCTION END IF
'Judgment the last bit is = 号' Judgment the second bit is = 号 'Here M4 indicates the last remaining character number IF MIDB (ascontents, len1, 1) = chrb (61) THEN M4 = 3 IF MIDB (Ascontents, Len1-1, 1) = chrb (61) THEN M4 = 2
IF m4 = 0 Thenlen2 = len1elselen2 = len1-4nd IF
For lnPosition = 1 To Len2 Step 4 lsGroupBinary = "" lsGroup64 = Midb (asContents, lnPosition, 4) Char1 = InStrb (sBASE_64_CHARACTERS, Midb (lsGroup64, 1, 1)) - 1 Char2 = InStrb (sBASE_64_CHARACTERS, Midb (lsGroup64, 2 , 1) - 1 CHAR3 = INSTRB (SBase_64_Characters, MIDB (Lsgroup64, 3, 1)) - 1 Char4 = INSTRB (SBase_64_Characters, MIDB (Lsgroup64, 4, 1)) - 1 Byte1 = ChRB (((Char2 and 48) / 16) OR (char1 * 4) and & hff) BYTE2 = LSGroupBinary & ChRB ((Char3 and 60) / 4) OR (char2 * 16) And & HFF) Byte3 = chrb ((((Char3 and 3) * 64) And & HFF) OR (Char4 and 63)) lsgroupbinary = Byte1 & Byte2 & Byte3
LsResult = lsResult & lsgroupbinary Next
'Handling the last remaining characters IF M4> 0 Then LsgroupBinary = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" THEN 'complements 4 bits, is to make it easy to calculate lrsgroup64 = lsgroup64 & chrb (65) end ifchar1 = INSTRB (SBASE_64_Characters, MIDB (LsGroup64, 1, 1)) - 1 Char2 = INSTRB (SBase_64_Characters, MIDB (LsGroup64, 2, 1) ) - 1 Char3 = INSTRB (SBase_64_Characters, MIDB (Lsgroup64, 3, 1)) - 1 Char4 = INSTRB (SBase_64_Characters, MIDB (LsGroup64, 4, 1)) - 1 Byte1 = ChRB (((Char2 and 48) / 16) OR (Char1 * 4) and & hff) BYTE2 = LSGroupBinary & ChRB ((Char3 and 60) / 4) OR (Char2 * 16) And & HFF) BYTE3 = ChRB (((Char3 and 3) * 64) And & HFF) OR (Char4 and 63)) IF M4 = 2 ThenlsgroupBinary = BYTE11ELSEIF M4 = 3 ThenlsGroupBinary = BYTE1 & BYTE2END IF
LsResult = lsResult & lsgroupbinary endiff
Base64decode = lsresult
END FUNCTION
'------------------------------------- --------------------------------
IF Request.form ("JM") <> "" "" "" "" "" "" "" "" "" ""
Response.write replace (STRANSI2UNICODE (Strunicode2NICode (Strunicode2ance (SDECode)), CHR (13) & chr (10), "
") & "
"
Response.endend IF
%>