Skip to content

loyaltypollution/lambda-obfuscator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda Obfuscator

A Python code obfuscator that transforms Python statements into lambda calculus expressions, making the code harder to understand while maintaining functionality.

Overview

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

Installation

# Clone the repository
git clone <repository-url>
cd lambda-obfuscator

# Install dependencies
pip install astor

Usage

Command Line Interface

# 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 --execute

Programmatic Usage

from 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)

Examples

Input (examples/basic.py)

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

result = factorial(5)
print(result)

Output (Simplified View)

The code is transformed into nested lambda expressions using Church encoding and continuation-passing style.

python cli.py examples/basic.py

How It Works

  1. Statement Transformation: Each Python statement (assignment, expression, return) is converted to a lambda expression
  2. Control Flow: If-statements become lambda conditionals using Church booleans
  3. Function Definitions: Functions are converted to lambdas with continuation-passing style
  4. Sequencing: Statement sequences are chained using function composition

Limitations

  • 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

Technical Details

The obfuscator uses:

  • AST (Abstract Syntax Tree) manipulation via Python's ast module
  • Continuation-Passing Style (CPS) for control flow
  • Church Encoding for booleans and numbers
  • Y-Combinator (fixed-point combinator) for recursion

License

MIT

Disclaimer

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages