Skip to main content
Obfuscation

Variable & Function Renaming: Python Obfuscation's First Layer

By Mithun··5 min read
Quick Answer

Identifier renaming replaces every variable, function and argument name with a meaningless token (like lIlllIllllIIlllIlll), removing the semantic clues a reader depends on. The code runs identically — Python doesn't care what names are — but label and total become noise. It's the cheapest obfuscation layer and, crucially, irreversible: the original names are gone for good and no decompiler can bring them back.

When people picture "obfuscated code," they usually picture this: a wall of ls and Is where readable names used to be. Identifier renaming is the first and cheapest layer of Python obfuscation, and it's the one our Python Obfuscator applies with the Rename option. I ran it on a small function to show exactly what it does — and, more importantly, what it does *not* do.

Real output below, and yes, the renamed version still runs and returns the same result.

What renaming does

Your variable and function names are for humans — the interpreter throws them away when it runs. total, label, classify: those words carry all the meaning a reader uses to understand the code, but Python only needs *consistent* names, not *meaningful* ones. Renaming exploits that: it walks the AST and swaps every identifier you defined for a unique, meaningless token, keeping references consistent so the program still works.

def classify(n):
if n < 0:
label = "negative"
else:
label = "positive"
total = 0
for i in range(n):
total += i
return label, total
print(classify(5))
before

The real renamed output

With only the Rename layer on, the obfuscator produces this — classify becomes lIlllIllllIIlllIlll, label becomes IllllIIIIIllIlIlIIl, and so on, consistently everywhere they're used:

def lIlllIllllIIlllIlll(n):
if n < 0:
IllllIIIIIllIlIlIIl = 'negative'
else:
IllllIIIIIllIlIlIIl = 'positive'
lIIIIIllIIllIIIIIlIIllIl = 0
for lIllllIIllIlllIllllIIIII in range(n):
lIIIIIllIIllIIIIIlIIllIl += lIllllIIllIlllIllllIIIII
return (IllllIIIIIllIlIlIIl, lIIIIIllIIllIIIIIlIIllIl)
print(lIlllIllllIIlllIlll(5))
after — renamed (real output, runs identically)

It barely grew (194 → 362 characters) and still prints ('positive', 10). The names are visually confusable l/I tokens on purpose — even copying them by eye is painful.

Why renaming is irreversible — and why that matters

This is the key property most people miss: the original names are destroyed, not encoded. There's no key, no lookup table shipped with the code — total is simply *gone*. Decompilers like uncompyle6 or pycdc can rebuild structure and even re-indent, but they can only invent generic names (var_1, a, b); they can never recover total or classify, because that information doesn't exist in the compiled program anymore. String encryption can be run backwards; renaming can't.

For real code with descriptive names — validate_license, decrypt_payload, api_secret — that loss is significant. Half of reading unfamiliar code is reading the names; strip them and the reader is flying blind.

Why it's necessary but not sufficient

Renaming removes one clue — names — but leaves everything else in plain sight. Look again at the output: the strings 'positive'/'negative' are readable, the structure (if/for/return) is intact, and the logic is followable. An analyst can still see *what* the code does; they just can't lean on the names to do it faster.

Renaming does NOT hide secrets. A hard-coded key survives renaming as a plaintext string. To hide strings you need string encryption; to hide flow you need control-flow flattening; to bury the real logic you add junk code. Renaming is layer one of several — see how to obfuscate Python code.

Rename & obfuscate your Python — free

Run your code through our Python Obfuscator: it renames every identifier to meaningless tokens (and can encrypt strings, flatten flow and inject junk on top), keeping the exact behavior. In your browser.

Open the Python Obfuscator

Free tools mentioned here

Related guides

Frequently asked questions

What is variable and function renaming in obfuscation?

It replaces every identifier you defined — variables, functions, arguments — with a unique, meaningless token, kept consistent so the code still runs. It strips the semantic clues (like the names total or classify) that a reader relies on, without changing behavior.

Can renamed Python code be reversed to the original names?

No. Renaming destroys the original names rather than encoding them — there's no table to reverse. A decompiler can rebuild structure and assign generic placeholder names (var_1, a, b), but it can never recover the original meaningful names, because that information is gone from the compiled program.

Does renaming protect hard-coded secrets?

No. A hard-coded API key or password is a string literal, and renaming only changes identifiers, not string contents — the secret stays in plaintext. Use string encryption for literals, and keep real secrets off the client (environment variables or a server) entirely.

How do I rename/obfuscate Python variables online?

Paste your code into our free Python Obfuscator and enable the Rename option (it's on by default). It walks the AST and renames every identifier consistently, returning runnable Python — the exact transform in this article — with no install and nothing uploaded permanently for the client-side view.

Keep reading