A piece of cryptographic function (base64)

Source: Internet
Author: User
Tags base64
function | encryption Const sbase_64_characters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"


Function Base64Encode (ByVal ascontents)
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

If Len (ascontents) mod 3 > 0 Then ascontents = ascontents & String (3-(Len (ascontents) mod 3), ""
Lsresult = ""

For lnposition = 1 to Len (ascontents) Step 3
LSGROUP64 = ""
Lsgroupbinary = Mid (ascontents, lnposition, 3)

Byte1 = ASC (Mid (lsgroupbinary, 1, 1)): SaveBits1 = Byte1 and 3
Byte2 = ASC (Mid (Lsgroupbinary, 2, 1)): SaveBits2 = Byte2 and 15
Byte3 = ASC (Mid (Lsgroupbinary, 3, 1))

Char1 = Mid (Sbase_64_characters, (Byte1 and 252) \ 4) + 1, 1)
CHAR2 = Mid (Sbase_64_characters, (Byte2 and R) and &HFF) + 1, 1)
CHAR3 = Mid (Sbase_64_characters, (Byte3 and) Or (SAVEBITS2 * 4) and &HFF) + 1, 1)
CHAR4 = Mid (Sbase_64_characters, (Byte3 and 63) + 1, 1)
LSGROUP64 = Char1 & Char2 & Char3 & CHAR4

Lsresult = Lsresult + lsGroup64
Next

Base64Encode = Lsresult
End Function



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.