Encrypt your data using an ASP encryption Algorithm (II)

Source: Internet
Author: User
Tags chr decrypt
In the first section, we discussed how to generate the key, which describes how to use this key to encrypt and decrypt a string.
The following code is the function that can implement this function at the same time
crypt.asp file
<%
Dim G_key
Const G_cryptthis = "Now is"
All good men to come to the aid of their country.
Const g_keylocation = "C:key.txt"
G_key = Mid (Readkeyfromfile (g_keylocation), 1,len (G_cryptthis))
Response.Write "<p>original STRING:" & g_cryptthis & "<p>"
Response.Write "<p>key VALUE:" & G_key & "<p>"
Response.Write "<p>encrypted cyphertext:" & EnCrypt (g_cryptthis) & "<p>"
Response.Write "<p>decrypted cyphertext:" & DeCrypt (EnCrypt (g_cryptthis)) & "<p>"
Function EnCrypt (Strcryptthis)
Dim Strchar, Ikeychar, Istringchar, I
For I = 1 to Len (strcryptthis)
Ikeychar = ASC (Mid (g_key,i,1))
Istringchar = ASC (Mid (strcryptthis,i,1))
' * * * * Uncomment below to encrypt with addition,
' Icryptchar = Istringchar + Ikeychar
Icryptchar = Ikeychar Xor Istringchar
strencrypted = strencrypted & Chr (Icryptchar)
Next
EnCrypt = strencrypted
End Function
Function DeCrypt (strencrypted)
Dim Strchar, Ikeychar, Istringchar, I
For I = 1 to Len (strencrypted)
Ikeychar = (ASC (mid g_key,i,1))
Istringchar = ASC (Mid (strencrypted,i,1))
' * * * * Uncomment below to decrypt with subtraction
' Idecryptchar = Istringchar-ikeychar
Idecryptchar = Ikeychar Xor Istringchar
strdecrypted = strdecrypted & Chr (Idecryptchar)
Next
DeCrypt = strdecrypted
End Function
Function Readkeyfromfile (strFileName)
Dim KeyFile, FSO, F
Set fso = Server.CreateObject ("Scripting.FileSystemObject")
Set F = fso. GetFile (strFileName)
Set ts = F.openastextstream (1,-2)
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.