Yesterday, someone asked how to use ASP for base64 encryption, this is

Source: Internet
Author: User
Tags base64 chr
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



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.