I recently read several pages and found that many of them are processed.
However, there is a page with encryption crpit processing encryption.
The following describes the encryption and decryption processes.
I. Encryption
1. convert each character in the string to a number
The method is the string processing method charcodeat (INDEX)
The charcodeat () method returns the Unicode encoding of characters at the specified position, that is, the string is digitalized, And the return value is an integer between 0 and 65535 of the corresponding characters.
For example:
VaR STR = "Hello world! "Var r = Str. charcodeat (0); document. Write (r); // The output is: 104.
2. After modifying the number, use the fromcharcode () method to restore the character
The fromcharcode () method is a string static method that can be specified to convert a number Unicode code to a character.
For example
$ = String. fromcharcode (r); document. Write ($); // The output is: H
The key to encryption is string. fromchshortcode (R!
You can change the value of R to deviate the output characters, for example, r = R + 2.
$ = String. fromcharcode (R + 2); document. Write ($); // The output is: J
Therefore,
Hello world! Changed to jgnnq "yqtnf #
<HTML> changed to> jvon @
Ii. decryption
1. Change the character to an uncoide-encoded number first.
VaR STR = "> jvon @"; var r = Str. charcodeat (0); document. Write (r); // output: 62
2. Use the encrypted Inverse Algorithm
$ = String. fromcharcode (R-2); document. Write ($); // The output is: <
Iii. complete code
<SCRIPT type = "text/JavaScript"> // ============================ ========/// encryption method // ========================================== === function encode (content) {var $ = ""; for (VAR u = 0; U <content. length; U ++) {var r = content. charcodeat (U); $ + = string. fromcharcode (R + 2);} return $ ;}; // ================================================================/// decryption method/ /==================================== function decode (content) {var $ = ""; for (VAR u = 0; U <content. length; U ++) {var r = content. charcodeat (U); $ + = string. fromcharcode (R-2);} return $ ;}; // ==============================================================/// test // ====================================== var STR = "hello "; document. write (encode (STR) + "<br>"); document. write (decode (encode (STR); </SCRIPT>