DEV Community

WangLiwen
WangLiwen

Posted on

2

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.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay