Javascript Encription - is it possible ??

Hi All,

Is it possible to encript javascript but still it works in Internet Explorer and Netscape?
Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
Hello meet_zorrer,

the initial question is: why do you want to encrypt your JavaScript?
If you want to prevent modification or prevent removing of some license enforcement, then it can not be absolutely done, but to some degree you can encode your script by algorithm which are difficult to follow and backtrack.
If you want only to make it difficult to be read by humans, then a regular scrambler and space remover will do it too.

But at the end I can prove you that any encoded script can be decoded, when the effort is worth of doing it.
Also for the Microsoft IE script compiler are decompiler out there (for demo purposes :)

if you find something, do not forget to test it ;)
look in my profile a tester :)
meet_zorrerAuthor Commented:
if you are tester then you should test your mind first :D
NushiConnect With a Mentor Commented:
hi there.

you can only encrypt the js from IE.
you can find a small took called srcenc which will encode the script and you will not be able to see it.

BUT you can use the same tool for decone and encode so someone whi knows what to do will be able to "see" the code.
under NS you will not be able to run it.
jaysolomonConnect With a Mentor Commented:
Here are a number of very effective methods of keeping unscrupulous surfers from stealing your HTML source:

Use the <INVISIBLE> </INVISIBLE> tags around the entire document.
Use the DONTSTEAL attribute in the <BODY> tag.
Ftp to your server, select all files and directories, hit "Delete".
Put every existing copy of every file on floppies, place them in a shoebox and bury them in the backyard. There is another version of this method which involves placing the floppies in a plastic bag and hiding them in a different sort of hole. Both are equally effective.
Password protect your entire site and make sure no one has the password, not even you.
Employ a small but fanatically loyal and well-armed band of mercenaries to guard your site.
Start>Run>format C:\
Attack dogs, preferably rabid.
Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.)
Don't put your pages on the web.
See also the alt.html micro-faq: #1, #2, #6, #19, #20, #22 & #36.

Ok, that was a bit of fun. Here's the real lowdown on hiding your source code:

It can't be done.
The only truly effective method in the list above is #10.

While it is possible to make it difficult for people to view your source code, you cannot stop someone who really wants it. It has been suggested that using javascript to disable right-click or encrypting the HTML may be effective. It is far more likely that employing these easily circumvented techniques will only encourage people to "steal" your code. In all probability, they don't want it until you tell them they can't have it.

For example: Here is page- -where the author is laboring under the misapprehension that employing all manner of legitimate-user-infuriating scripting tricks will prevent their page from being copied/edited/distributed. They have attempted to encrypt the source, intercept right-clicks, left-clicks and various keyboard commands and have, of course, most conspicuously failed. The only thing this author has succeeded in doing is to create a page that presents serious obstacles to legitimate users and one that will crash many commonly used browsers. A simple snippet of javascript defeats all of this foolishness in under two seconds:

javascript:(function(){ function htmlEscape(s){s=s.replace(/&/g,'&');s=s.replace(/>/g,'></g,'<');return s;}; x.document.write('>');s=s.replace(/pre>' + htmlEscape('\n' + document.documentElement.innerHTML + '\n')); x.document.close(); })();

To use this javascript simply right-click the following link and select "add to favorites": Reveal Generated Source (Use IE5.0 or greater)

Now point your browser at and once the page is displayed, go to the bookmark you just made. All of the encryption is stripped out leaving a clean copy of the HTML source to do with as you see fit. Images from the page may be saved by dragging them from the page into a local folder, or by going directly to their individual URLs.

The point of this little demonstration is that there are a number of ways to protect your works from unauthorized distribution. Creating crippled pages with easily defeated script-kiddie hacks is not one of them.

Beware, there are individuals and companies that sell HTML "protection" to the naive. These are nothing more than scams; don't get taken for a ride.
All Courses

From novice to tech pro — start learning today.