简体   繁体   中英

What exactly Does this code do?

/*
No source for you!
*//
/.source.replace(/.{7}/g,function(w){
document.write(String.fromCharCode(parseInt(w.replace(/ /g,'0').replace(/   /g,'1'),2)))});

I don't know javascript this well but this looks like an encryption of some sort, but I believe that the comment is somehow related, Sorry for my little knowledge on decryption, thankyou!

This is quite cute. It splits the "source" into 7 character long substrings ( .{7} ) and replaces certain whitespace characters with 0 or 1 , then interprets these 0 and 1 strings as binary number ( parseInt(.., 2) ) and turns them into a character ( String.fromCharCode ). The whitespace source itself is written as a regex literal ( / / ).

Essentially, all source code is encoded as "invisible" whitespace and this piece of code turns it back into the actual source code.

Since the source is written back into the DOM where you can then read it, it's somewhat useless for actual "protection"; but all obfuscation is ultimately useless. You cannot hide Javascript code, since then the browser couldn't execute it. If the browser must execute it, it must be publicly visible somehow, somewhere. But again, it's cute .

上面的代码将0或1替换为空格,因为它将这些0和1字符串解释为二进制数并将其转换为字符

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM