# Simple encryption Method: XOR

Source: Internet
Author: User
Tags chr decrypt
The easiest way to use data encryption in school is to vary or see someone want to encrypt the algorithm, the previous information turned over, sorted out a series of cryptographic functions, of course, simple encryption is easy to crack, but better than nothing (remember to put the secret to the key), It's better than having someone open the database and see the code. :-)

<%
' Simplest encryption method: XOR
'----------------------

G_cryptthis = "China-china"
Strfullkeylen = Len (g_cryptthis)

Strfullkey = KeyGen (Strfullkeylen)

Response.Write "<p> Original string:" & G_cryptthis & "<p>"
Response.Write "<p> key:" & Strfullkey & "<p>"
Response.Write "<p> after Encryption:" & Server.URLEncode (EnCrypt (g_cryptthis)) & "<p>"
Response.Write "<p> after decryption:" & DeCrypt (EnCrypt (g_cryptthis)) & "<p>"

' XOR ' or ' encryption '
Function EnCrypt (Strcryptthis)
Dim Strchar, Ikeychar, Istringchar, I
For i = 1 to Len (strcryptthis)
Ikeychar = ASC (Mid (strfullkey,i,1))
Istringchar = ASC (Mid (strcryptthis,i,1))
Icryptchar = Ikeychar Xor Istringchar
strencrypted = strencrypted & Chr (Icryptchar)
Next
EnCrypt = strencrypted
End Function

' Xor or decryption
Function DeCrypt (strencrypted)
Dim Strchar, Ikeychar, Istringchar, I
For i = 1 to Len (strencrypted)
Ikeychar = (ASC (mid strfullkey,i,1))
Istringchar = ASC (Mid (strencrypted,i,1))
Idecryptchar = Ikeychar Xor Istringchar
strdecrypted = strdecrypted & Chr (Idecryptchar)
Next
DeCrypt = strdecrypted
End Function

' Generates a random key of the specified length
Function KeyGen (strlength)
Dim I,ub
Dim Temp
Dim Poss
Poss = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Temp = ""

UB = Len (Poss)
For i = 1 to Strlength
Randomize
Temp = temp & Mid (Poss,int (UB-0 + 1) * Rnd + 1), 1)
Next
KeyGen = Temp
End Function
%>

Related Keywords:

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.