How to obfuscate variable names in JavaScript? - Stack Overflow

I'm an artist that's written a simple game in Javascript. Yah! But go easy on me because I br

I'm an artist that's written a simple game in Javascript. Yah! But go easy on me because I bruise like a peach! I'm looking into difficult to cheat at the game. So code obfuscation will make it difficult to cheat, right? Difficult, not impossible. I realise that, and could accidentally open a can of worms here...

Essentially, I'm Looking for an online tool that renames variables; and don't say search and replace in textpad :). For example using / on one line of code

var loopCounter = 0;

we get the result:

eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('1 2=0;',3,3,'|var|loopCounter'.split('|'),0,{}))

The above looks like a mess, which is great; but it's quite easy to pick out English words like loopCounter. I would have expected it to make variable names obscure (single letter? words without nouns? look very similar?? Or should have that been my task anyway as part of writing the code. Or is this a waste of time trying to make variable names since a variable declaration is preceded by var and therefore there's no point to disguise it?

I'm an artist that's written a simple game in Javascript. Yah! But go easy on me because I bruise like a peach! I'm looking into difficult to cheat at the game. So code obfuscation will make it difficult to cheat, right? Difficult, not impossible. I realise that, and could accidentally open a can of worms here...

Essentially, I'm Looking for an online tool that renames variables; and don't say search and replace in textpad :). For example using http://packer.50x.eu/ on one line of code

var loopCounter = 0;

we get the result:

eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('1 2=0;',3,3,'|var|loopCounter'.split('|'),0,{}))

The above looks like a mess, which is great; but it's quite easy to pick out English words like loopCounter. I would have expected it to make variable names obscure (single letter? words without nouns? look very similar?? Or should have that been my task anyway as part of writing the code. Or is this a waste of time trying to make variable names since a variable declaration is preceded by var and therefore there's no point to disguise it?

Share Improve this question asked Jul 31, 2013 at 9:05 Ghoul FoolGhoul Fool 6,97713 gold badges76 silver badges140 bronze badges 2
  • 1 Maybe have a look at Closure Compiler. Does more than code obfuscation, but requires you code to follow some guidelines. – Sirko Commented Jul 31, 2013 at 9:08
  • Maybe a duplicate of this: stackoverflow./questions/522064/… – FidEliO Commented Jul 31, 2013 at 11:45
Add a ment  | 

3 Answers 3

Reset to default 2

After a lot of searching (and links to the above) I found this which allows obfuscated string variables. And that is what I was after.

there are a few online tools available for this: javascript pressor and then theres javascript minifier that you can use for large images also. otherwise you could just google some offline tools, pretty sure they're easy to find

You could use the Javascript Obfuscator... your code will be very difficult to decode!

Hope it helps! ^_^

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744353809a4570128.html

相关推荐

  • How to obfuscate variable names in JavaScript? - Stack Overflow

    I'm an artist that's written a simple game in Javascript. Yah! But go easy on me because I br

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信