Skip to content

JavaScript Obfuscator (eval)

Updated:

Paste JavaScript into the code field to generate an eval-based packed version. Copy the resulting code from the Obfuscated Code field.

Eval-Based JavaScript Obfuscation Tool

Input Fields
If enabled, the result will update automatically when you change any value.

JavaScript Obfuscator (eval) Formula

Formula
\[O=\operatorname{Packer.pack}(S,\mathrm{true},\mathrm{true})\]

Where:

  • \(S\) — the JavaScript entered in the input field.
  • \(O\) — the packed JavaScript shown as the result.
  • The first \(\mathrm{true}\) enables base-62 token encoding; the second enables variable shrinking.

The packer also minifies the input before producing an eval-based wrapper. Base-62 token encoding is not Base64 or hexadecimal encoding.

JavaScript Obfuscator (eval) – Calculation Example

Example: Leave the default alert('Hello, world!'); in the JavaScript Code to Obfuscate field.

\[S=\texttt{alert('Hello, world!');},\qquad O=\operatorname{Packer.pack}(S,\mathrm{true},\mathrm{true})\]

Result: Obfuscated Code contains a packed, eval-based JavaScript snippet. Running it in an environment that permits eval() executes the original alert, displaying “Hello, world!”. The result field contains code, not the alert message itself.

How to use the calculator

  1. Enter or paste your script into JavaScript Code to Obfuscate. The field initially contains alert('Hello, world!');, which you can use for a quick test.
  2. Run the calculator to process the code. If the field is empty, you will see an “Enter code” message instead of a result.
  3. Copy the generated script from Obfuscated Code and test it where you intend to use it.

Paste JavaScript code rather than HTML <script> tags. There are no encoding, compression, or security-level settings to select: the tool calls the packer with both available options enabled.

What eval-based obfuscation does

This tool transforms JavaScript source into a packed script that reconstructs code and executes it through eval(). Its purpose is to make the source less immediately readable during casual inspection. Unlike a conventional calculation, it does not produce a numerical answer: Obfuscated Code is another JavaScript program intended to perform the work of the input.

The packer minifies the script, shrinks variables where its transformation supports doing so, and replaces tokens with shorter base-62 representations. The resulting wrapper restores the packed code when it runs. Base-62 describes the token alphabet used by this packing approach; it does not mean the entire script is converted to a Base64 string. The tool does not offer a choice of encodings.

Obfuscation is not encryption. Anyone who can run or inspect the result can work toward recovering the underlying code, including by studying the unpacking step. Use this approach to discourage casual reading, not to protect passwords, API secrets, license checks, or other information that must remain private. For a more readable version of packed code, try the JavaScript Eval Decode tool.

Also distinguish packing from file-size optimization. Although minification removes unnecessary source text, the unpacking wrapper adds code of its own, so a short script may become larger. If download size is your main concern, compare the result with the JavaScript Compress tool instead.

Assumptions and practical limitations

  • Execution policy matters. A Content Security Policy that disallows eval() can prevent the packed script from running. A site may need to use an unpacked script rather than weaken its policy.
  • Test the actual result. Variable shrinking and packing can affect code that depends on source text, variable names, or particular scope behavior. Check the generated script with your intended JavaScript engine and test suite before replacing working code.
  • Do not treat the output as safe because it looks unreadable. Packed JavaScript can still perform any actions its original code performs. Review untrusted input before executing it.
  • Keep the original source. The packed output is harder to edit and debug. Maintain your readable version for changes, error investigation, and future builds.

The best check is a side-by-side test: run the original and packed scripts under the same conditions, compare their observable behavior, and confirm that your deployment environment permits dynamic evaluation.

Frequently Asked Questions

How can I make an eval-based JavaScript packer by hand?

First, minify a small script, then build a dictionary of repeated tokens and replace them with short identifiers. Finally, write a wrapper that restores those tokens before passing the reconstructed script to eval(). Escaping quotes, backslashes, and replacement tokens correctly is difficult, so hand-built packers are best treated as experiments rather than production tools.

Will packed code work with JavaScript modules?

Not necessarily. Static import and export declarations require module syntax and cannot simply be placed inside an eval() call. If your source uses them, pack the code only after a suitable build step has bundled or transformed the modules. Test the result in the same browser or runtime configuration you will use for deployment.

Does this obfuscator support modern JavaScript syntax?

Support depends on the packer’s parser and transformation rules, not just on whether your browser understands the source. Features such as template literals, optional chaining, or newer class syntax may cause an older packer to fail or change behavior. Try a representative sample and compare its results with the original before processing a larger project.

Does eval-based packing make JavaScript slower?

It can add startup work because the wrapper must reconstruct the script before eval() executes it. The effect depends on script size, how often it runs, and the JavaScript engine; code that executes repeatedly after unpacking may show little difference. Measure load and execution times in your target environment rather than assuming a smaller-looking script is faster.

Why do special characters look different in the packed output?

The wrapper may escape quotes, backslashes, line breaks, or non-ASCII characters so they can be represented safely inside generated JavaScript. A different-looking source is not necessarily a different string value. Check the value produced at runtime, especially for emoji, accented characters, regular expressions, and strings containing backslashes.

How can I tell whether the obfuscation is good?

There is no standard score or ideal output length for this kind of packing. A useful result still behaves like the original script and makes casual source inspection less straightforward. It should not be judged by appearance alone: a determined reader can reconstruct code that must be unpacked to run, so keep sensitive data out of client-side JavaScript.

How do I debug an error in packed JavaScript?

Reproduce the error with the original source first, where line numbers and variable names are more useful. If it appears only after packing, reduce the input to the smallest script that still fails and compare both versions in the same environment. Errors reported inside the eval() wrapper may not point to the corresponding line in your original file.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 thoughts on “JavaScript Obfuscator (eval)”