JavaScript Obfuscation
What is an obfuscated code? – source Wikipedia
Obfuscated code is source code in a computer programming language that has been made difficult to understand. Programmers may deliberately obfuscate code to conceal its purpose (a form of security through obscurity), to deter reverse engineering, or as a puzzle or recreational challenge for readers. Programs known as obfuscators transform human-readable code into obfuscated code using various techniques.
JavaScript obfuscation: Why & why not
An obfuscated JavaScript code can help us in many ways – reduce the download time, more optimization and a fair amount of encryption. At the same time it got some serious disadvantages too – understandability is a distant dream where there is no readability.
JavaScript obfuscation: How
Try this piece code:
// Get the value of all the form fields as a string
function getFormParametersAsAString(aWebForm)
{
var inputs = aWebForm.getElementsByTagName('input');
var formParameters = '';
var anInput;
if (inputs)
{
for (i = 0; i < inputs.length; i++)
{
anInput = inputs[i];
if (anInput.name && (anInput.name.length > 0) &&
("submit" != anInput.type) && ("reset" != anInput.type))
formParameters += anInput.name + '=' + encodeURIComponent(anInput.value) + '&';
}
}
return (formParameters);
}
And the obfuscated version:
var _0xf8b7=["input","getElementsByTagName","","length","name","submit","type","reset","=","value","\x26"];
function getFormParametersAsAString(aWebForm){var inputs=aWebForm[_0xf8b7[1]](_0xf8b7[0]);
var formParameters=_0xf8b7[2];var anInput;if(inputs){for(i=0;i<inputs [_0xf8b7[3]];i++){anInput=inputs[i];
if(anInput[_0xf8b7[4]]&&(anInput[_0xf8b7[4]][_0xf8b7[3]]>0)&&(_0xf8b7[5]!=anInput[_0xf8b7[6]])&&(_0xf8b7[7]!=anInput[_0xf8b7[6]]))
{formParameters+=anInput[_0xf8b7[4]]+_0xf8b7[8]+encodeURIComponent(anInput[_0xf8b7[9]])+_0xf8b7[10];} ;} ;} ;
return (formParameters);} ;
Made using http://www.javascriptobfuscator.com/
You can try these obfuscators
http://www.javascriptobfuscator.com/Default.aspx
http://www.jasob.com/
http://ajaxian.com/archives/utility-javascript-obfuscator – It’s Java based. Download the obfuscator Jar file
References:
http://en.wikipedia.org/wiki/Obfuscated_code



JavaScript obfuscation can really help us if we have huge chunks of code to be loaded and the time need to be minimized. It can really help in reducing the code size where we use lot of string constants and can make the code more optimized. Again, everything depends on the obfuscator.
Subinkrishna G
June 16, 2009 at 2:16 pm