A Python code obfuscator that transforms Python statements into lambda calculus expressions, making the code harder to understand while maintaining functionality.
This tool converts Python code using lambda calculus primitives:
- Church Booleans:
TRUE = λx.λy.x,FALSE = λx.λy.y - Church Numerals:
ZERO = λf.λx.x,SUCC = λn.λf.λx.f(n f x) - Control Flow: Converts if-statements, assignments, and returns into lambda expressions
- Fixed-Point Combinator: For recursive functions
# Clone the repository
git clone <repository-url>
cd lambda-obfuscator
# Install dependencies
pip install astor# Basic usage
python cli.py input.py
# Specify output file
python cli.py input.py -o output.py
# Execute obfuscated code after generation
python cli.py input.py --executefrom obfuscate import obfuscate_code
# Obfuscate a Python file
tree = obfuscate_code('example.py')
# Compile and execute
code = compile(tree, filename="<ast>", mode="exec")
exec(code)def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
result = factorial(5)
print(result)The code is transformed into nested lambda expressions using Church encoding and continuation-passing style.
python cli.py examples/basic.py- Statement Transformation: Each Python statement (assignment, expression, return) is converted to a lambda expression
- Control Flow: If-statements become lambda conditionals using Church booleans
- Function Definitions: Functions are converted to lambdas with continuation-passing style
- Sequencing: Statement sequences are chained using function composition
- Only supports basic Python constructs (assignments, if-statements, returns, function calls)
- Limited error handling for complex Python features
- Generated code is significantly slower than original
- Not suitable for production use - purely educational/research purposes
The obfuscator uses:
- AST (Abstract Syntax Tree) manipulation via Python's
astmodule - Continuation-Passing Style (CPS) for control flow
- Church Encoding for booleans and numbers
- Y-Combinator (fixed-point combinator) for recursion
MIT
This tool is for educational and research purposes only. The obfuscated code is not intended for security purposes and should not be used to hide malicious code.