-1

I am building a small JavaScript game where the user has to guess a word. The user will be given letters and he will have to combine them into a word. Every time when the user adds/removes a letter, the system checks if the word combined is the answer.

As the game will be mostly presented to users with no programming skills and because my server is not too powerful, I decided to implement word checking on the client side. (otherwise, I would have to run an ajax request for php script which possibly checks the answer from mysql db. that would introduce extra latency and load on the server)

Now, just to make sure, I would like to make it a bit more difficult for users with low programming skills to find out the answer variable or see the comparing function.

Is it somehow possible to make a function in JavaScript non-human readable? Or at least making it hard-readable?


Just to remind you again, I am not too concerned if the final code will be not secure enough and some people actually crack the compare function and get the answer - I would be happy for their effort.

Arturs Vancans
  • 4,531
  • 14
  • 47
  • 76

2 Answers2

1

Did your looking for js obfuscation? May be this links helps:

http://badassjs.com/post/2929065287/obfuscation

and

http://adamcecc.blogspot.ru/2011/01/javascript.html

S Panfilov
  • 16,641
  • 17
  • 74
  • 96
0

You can use something like this:

var encodedData = window.btoa("the word"); // encode a string
var decodedData = window.atob(encodedData); // decode the string

I'd just encode all the words prior and then encode their guess and check it against the already encoded string you originally created.

https://developer.mozilla.org/en-US/docs/DOM/window.btoa https://developer.mozilla.org/en-US/docs/DOM/window.atob

This would work for Firefox, Chrome, Safari... although you could use a Base-64 function also like shown on this stackoverflow question: Base64 encoding and decoding in client-side Javascript

Community
  • 1
  • 1
blamonet
  • 592
  • 1
  • 4
  • 13