简体   繁体   English

这段代码究竟能做什么?

[英]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! 我不太了解javascript,但这看起来像某种加密,但是我认为注释之间存在某种联系,对不起,我对解密的了解很少,谢谢!

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 ). 它将“源”分割为7个字符长的子字符串( .{7} ),并用01替换某些空格字符,然后将这些01字符串解释为二进制数( parseInt(.., 2) )并将其转换为字符( 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"; 由于将源写回到DOM中,然后您就可以在其中读取它,因此对于实际的“保护”而言,它似乎毫无用处。 but all obfuscation is ultimately useless. 但是所有的混淆最终都没有用。 You cannot hide Javascript code, since then the browser couldn't execute it. 您无法隐藏Javascript代码,因为那样浏览器将无法执行它。 If the browser must execute it, it must be publicly visible somehow, somewhere. 如果浏览器必须执行它,则它必须以某种方式在某个地方公开可见。 But again, it's cute . 但是,它又很可爱

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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