ASP:BASE64 encoding and decoding functions

Source: Internet
Author: User
Tags base64 character set chr
ASP:BASE64 encoding and decoding functions
www.xufei.net [2003-3-6]
--------------------------------------------------------------------------------
Base64 encoding and decoding functions
This is I read a few Base64 encoding, decoding the function of their own rewrite.
Because, in the Chinese operating system of VBScript, using the Unicode character set, so
Many base64 encoding and decoding functions are theoretically correct, but they do not actually work!
File name base64test.asp
<%
Sbase_64_characters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
Sbase_64_characters = Strunicode2ansi (sbase_64_characters)
Function Strunicodelen (ascontents)
' Calculates the length of the ANSI encoding of a Unicode string
Ascontents1= "a" &ascontents
Len1=len (ASCONTENTS1)
K=0
For I=1 to Len1
ASC1=ASC (Mid (ascontents1,i,1))
If Asc1<0 then ASC1=65536+ASC1
If asc1>255 Then
K=k+2
Else
K=k+1
End If
Next
Strunicodelen=k-1
End Function
Function Strunicode2ansi (ascontents)
' Converts a Unicode-encoded string into an ANSI-encoded string
Strunicode2ansi= ""
Len1=len (ascontents)
For I=1 to Len1
Varchar=mid (ascontents,i,1)
VARASC=ASC (varchar)
If Varasc<0 then varasc=varasc+65536
If varasc>255 Then
Varhex=hex (VARASC)
Varlow=left (varhex,2)
Varhigh=right (varhex,2)
Strunicode2ansi=strunicode2ansi & ChrB ("&h" & Varlow) & ChrB ("&h" & Varhigh)
Else
Strunicode2ansi=strunicode2ansi & ChrB (VARASC)
End If
Next
End Function
Function Stransi2unicode (ascontents)
' Converts an ANSI-encoded string into a Unicode-encoded string
Stransi2unicode = ""
Len1=lenb (ascontents)
If Len1=0 then Exit function
For I=1 to Len1
VARCHAR=MIDB (ascontents,i,1)
VARASC=ASCB (varchar)
If VARASC > 127 Then
Stransi2unicode = Stransi2unicode & Chr (AscW (MidB (ascontents,i+1,1) & varchar))
I=i+1
Else
Stransi2unicode = Stransi2unicode & Chr (VARASC)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.