DEV Community

WangLiwen
WangLiwen

Posted on

How many variations can be produced by obfuscating a single line of JavaScript code: 'var a=1'?

Confusing code is a technique used to make it difficult to understand and reverse engineer, often employed to protect the confidentiality of source code. For a simple variable assignment like var a = 1;, here are some possible methods:

Using Uncommon Variable Names:

var _0x1234 = 1;
Enter fullscreen mode Exit fullscreen mode

Using Computational Expressions:

var a = 0 + 1;
Enter fullscreen mode Exit fullscreen mode

Or a more complex one:

var a = Math.floor(1.0);
Enter fullscreen mode Exit fullscreen mode

Using String Parsing:

var a = parseInt("1", 10);
Enter fullscreen mode Exit fullscreen mode

Using Array or Object Access:

var _0xarray = [1];
var a = _0xarray[0];
Enter fullscreen mode Exit fullscreen mode

Or:

var _0xobj = {key: 1};
var a = _0xobj.key;
Enter fullscreen mode Exit fullscreen mode

Using Bitwise Operations:

var a = ~(~0 + 1);
Enter fullscreen mode Exit fullscreen mode

Multiple Assignments:

var b, a;
b = 1;
a = b;
Enter fullscreen mode Exit fullscreen mode

Using Functions:

function getOne() {
    return 1;
}
var a = getOne();
Enter fullscreen mode Exit fullscreen mode

Using JShaman JavaScript Obfuscator:

var a = function (s, h) {
  return eval(String.fromCharCode(115, 32, 94, 32, 104));
}(287630, 287631);
Enter fullscreen mode Exit fullscreen mode

Please note that obfuscating code can make it harder to read and maintain, so it should be used cautiously.

Top comments (0)