How zlib + Base64 Python Obfuscation Works

Inside the encode-and-execute pipeline  · 

The obfuscation technique used by pyobfuscator.com is based on three sequential transforms: zlib compression, Base64 encoding, and string reversal. Understanding each step explains both the strength and the limitations of the output.

Step 1: zlib Compression

The source code string is compressed using the zlib deflate algorithm. In Python this is zlib.compress(source.encode()). Compression serves two purposes: it reduces the size of the payload and produces binary output that is not human-readable.

Step 2: Base64 Encoding

The compressed binary is Base64-encoded with base64.b64encode(compressed). Base64 converts arbitrary bytes to a safe ASCII string using only the characters A-Z, a-z, 0-9, +, and /. This makes the payload safe to embed in a Python string literal.

Step 3: String Reversal

The Base64 string is reversed using Python's [::-1] slice syntax. This defeats naive scanners that look for Base64 patterns at the start of a string and adds an extra decoding step.

The Loader Lambda

The three-step transform is undone at runtime by a single Python lambda. At runtime: the payload is re-reversed, decoded from Base64, decompressed with zlib, and executed. All three built-in modules are called inline with __import__ so no imports appear at the file head.

Browser-Side Implementation

pyobfuscator.com performs all three steps in JavaScript using the browser native CompressionStream('deflate') API and btoa() for Base64 encoding. Your code never leaves your machine.

Multi-Layer Mode

In multi-layer mode, the entire output including the lambda is run through the same three-step pipeline a second time, producing a loader that decompresses and executes another loader.

Ready to protect your code? Try our free Python obfuscator - no sign-up needed, runs entirely in your browser.