Cryptographic decryption-ASP instance

Source: Internet
Author: User
Tags base64 exit chr end
Encryption | decryption | encryption | encryption | Before decrypting: 1234567890

After encryption: Mtizndu2nzg5ma

After decryption: 1234567890

Source:

<%
OPTION EXPLICIT
Const BASE_64_MAP_INIT = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim newline
Dim Base64encmap (63)
Dim Base64decmap (127)
' Initialization function
Public SUB Initcodecs ()
' Initialize variable
NewLine = "<P>" & Chr (km) & Chr (10)
Dim max, IDX
max = Len (base_64_map_init)
For idx = 0 to Max-1
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
' Base64 encryption function
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) + ((second) and 15))
RET = ret & Base64encmap ((Second * 4) and + ((third) and 3))
RET = ret & Base64encmap (third and 63)
NDX = ndx + 3
Loop
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) + ((second) and 15))
RET = ret & Base64encmap ((Second * 4) and 60))
Else
RET = ret & Base64encmap ((a) and 48)
ret = Ret ' & ' = '
End If
ret = Ret ' & ' = '
End If
Base64Encode = RET
End FUNCTION
' Base64 decryption function
Public FUNCTION Base64decode (scrambled)
If Len (scrambled) = 0 Then
Base64decode = ""
Exit function
End If
Dim Reallen
Reallen = Len (scrambled)
Do while mid (scrambled, Reallen, 1) = "="
Reallen = realLen-1
Loop
Dim ret, Ndx, By4, A, second, third, fourth
ret = ""
By4 = (reallen \ 4) * 4
NDX = 1
Do While Ndx <= by4
i = BASE64DECMAP (ASC (Scrambled, ndx+0, 1))
Second = BASE64DECMAP (ASC (Scrambled, ndx+1, 1))
Third = Base64decmap (ASC (Scrambled, ndx+2, 1))
Fourth = BASE64DECMAP (ASC (Scrambled, ndx+3, 1))
RET = ret & Chr (((4) and 255) + ((second) and 3))
RET = ret & Chr ((second *) and 255) + ((third \ 4) and 15))
RET = ret & Chr ((third *) and 255) + (fourth and 63))
NDX = ndx + 4
Loop
If Ndx < Reallen Then
i = BASE64DECMAP (ASC (Scrambled, ndx+0, 1))
Second = BASE64DECMAP (ASC (Scrambled, ndx+1, 1))
RET = ret & Chr (((4) and 255) + ((second) and 3))
If Reallen MOD 4 = 3 Then
Third = Base64decmap (ASC (mid scrambled,ndx+2,1))
RET = ret & Chr ((second *) and 255) + ((third \ 4) and 15))
End If
End If
Base64decode = RET
End FUNCTION
' Initialization
Call Initcodecs
' Test code
Dim InP, Encode
INP = "1234567890"
encode = Base64Encode (INP)
Response.Write "Before encryption:" & INP & NewLine
Response.Write "After encryption:" & Encode & NewLine
Response.Write "After decryption:" & Base64decode (encode) & newline
%>



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.