JavaScript code hiding

Source: Internet
Author: User

Of course, the author left us a small exercise because he only uses two characters, resulting in 8 times the converted data. He provides us with four zero-width characters, and we can reduce it to 4 times. Okay. Let's take a look at the code. Text (function (window) {var rep = {// Replace the data with four zero-width characters, reducing the data size by half. '00': '\ u200b', '01':' \ u200c ', '10':' \ u200d ', '11':' \ ufeff '}; function hide (str) {str = str. replace (/[^ \ x00-\ xff]/g, function (a) {// transcode a character other than Latin-1 encoding. Return escape (). replace ('%', '\') ;}); str = str. replace (/[\ s \ S]/g, function (a) {// process binary data and replace a =. charCodeAt (). toString (2); a =. length <8? Array (9-. length ). join ('0') + a: a; return. replace (/.. /g, function (a) {return rep [a];}) ;}); return str ;}var tpl = '("@ code ". replace (/. {4}/g, function (a) {var rep = {"\ u200b": "00", "\ u200c": "01", "\ u200d ": "10", "\ uFEFF": "11"}; return String. fromCharCode (parseInt (. replace (/. /g, function (a) {return rep [a]}), 2)}) '; window. hider = function (code, type) {var str = hide (code); // generates a string with Zero Width str = tpl. r Eplace ('@ Code', str); // generate the template if (type = 'eval') {str = 'eval' + str ;} else {str = 'function' + str + '()';} return str ;}}) (window); To test the effect. (Click Run in the upper-right corner of the code box.) Run var code = hider ('alert (") to test the text .. ") '); Console. log (code); then try the generated data. (If the previous step is not executed, an error is returned when you execute it directly .) Run eval (code) in text );

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.