Ghoul Fool
Ghoul Fool

Reputation: 6949

How to obfuscate variable names in JavaScript?

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?

Upvotes: 5

Views: 8885

Answers (3)

Ghoul Fool
Ghoul Fool

Reputation: 6949

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.

Upvotes: 2

Alesanco
Alesanco

Reputation: 1900

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

Hope it helps! ^_^

Upvotes: 0

pythonian29033
pythonian29033

Reputation: 5207

there are a few online tools available for this: javascript compressor 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

Upvotes: 0

Related Questions