Skip to content

SSL-ACTX/pyfuckv2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation


PyfuckV2 Logo

PyfuckV2

An esoteric Python transformer that transforms your code into a cryptic dialect using only [(+travels)].

Why? · How It Works · Installation · Usage

License: MIT Python 3.7+ Build Status


PyfuckV2 is a mind-bending exploration of Python's dynamic nature. It takes any valid Python script and transmutes it into a highly unreadable but perfectly functional format, using an extremely limited set of characters: (, ), [, ], +, t, r, a, v, e, l, s.

This project serves as an educational deep dive into Python's introspection capabilities and a tribute to the esoteric programming concepts pioneered by JSFuck and the original PyFuck.

🔮 What's the Point?

Disclaimer: This tool is for educational and recreational purposes only. It is a proof of concept, not a tool for serious security or obfuscation. The generated code is extremely slow, inefficient, and easily reversible. Do not use this in production environments.

The goal of PyfuckV2 is to answer the question: "What is the absolute minimum set of characters needed to represent any program in a Turing-complete language like Python?" It's a fun way to:

  • Explore Metaprogramming: Understand how Python can build and execute code on the fly.
  • Learn About Introspection: See how we can access the "guts" of Python's built-in types and functions to construct new functionality from scratch.
  • Create a Programming Puzzle: The output is a fascinating, if horrifying, piece of code that challenges our understanding of syntax.

✨ Demonstration

Take a simple Python script...

# hello.py
print("Hello, World!")

...run it through PyfuckV2...

pyfuck -i hello.py

...and witness the transformation.

# obfuscated.py (output is heavily truncated for readability)
eval(str(eval)[eval(str(+all([]))+str(all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])))]+eval(str(str)[+all([])]+str(eval(str(str)[all([])+all([])+all([])+all([])]+str(str)[all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])]+str(str)[eval(str(+all([]))+str(+all([[]])))]+str(eval(str(eval)[eval(str(+all([]))+str(+all([[]])))]+str(str)[all([])+all([])]+str(eval)[eval(str(+all([]))+str(all([])+all([])+all([])+all([])+all([])+all([])))]+str(str)[all([])+all([])+all([])]+str(str)[all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])]+str(())[+all([[]])]+str(+all([]))+str(())[+all([])]))[+all([])]+str(str)[+all([])]+str(eval)[eval(str(+all([]))+str(all([])+all([])+all([])+all([])+all([])+all([])))]+str(eval)[all([])+all([])]+str(eval)[eval(str(+all([]))+str(all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])+all([])...

Despite its appearance, this is valid Python code that executes perfectly and prints "Hello, World!".

🚀 Features

  • Minimal Character Set: Uses only [(+travels)] to represent any Python script.
  • Zero Imports: The generated code is completely self-contained.
  • Powerful CLI: A simple and intuitive command-line interface for all your obfuscation needs.
  • Multiple Modes:
    • exec: (Default) Generates code that executes the input script.
    • eval: Generates an expression that evaluates to the input script's result.
    • string: Generates an expression that evaluates to the input script as a string.

🧠 How It Works

The magic behind PyfuckV2 is a "bootstrapping" process that constructs a usable character set from almost nothing. It's a chain of logical steps, each building upon the last.

  1. Boolean Arithmetic (Getting 0 and 1): The process starts by generating integers. Python's boolean logic is the key:

    • all([]) evaluates to True.
    • +all([]) coerces True to the integer 1.
    • all([[]]) evaluates to False.
    • +all([[]]) coerces False to the integer 0. Larger numbers are then created by summing 1s.
  2. Initial Characters (Scavenging from str()): With numbers, we can index strings. By calling str() on built-in objects like eval and str, we can "scrape" our first characters. For example:

    • str(str) gives "<class 'str'>"
    • str(eval) gives "<built-in function eval>"
    • Indexing these strings (e.g., str(str)[1]) gives us 'c', 'l', 'a', 's', etc.
  3. Unlocking chr() (The Rosetta Stone): The crucial breakthrough is to construct the string 'chr' using the scavenged characters and then call eval('chr'). Once the chr function is accessible, PyfuckV2 can generate any character from its ASCII/Unicode ordinal value. This is the "Rosetta Stone" that unlocks the entire character set.

  4. Unlocking exec() (Executing Scripts): Similarly, once the character 'x' is available (via chr()), the script constructs and evaluates the string 'exec'. This allows the execution of multi-line scripts and statements that don't return a value (like import or print).

  5. Final Assembly: With the power of chr() and exec(), the original Python script is assembled character by character into a very long string. This string is then wrapped in a final exec() or eval() call to be executed by the Python interpreter.

📦 Installation

You can install PyfuckV2 directly from this GitHub repository using pip.

pip install git+https://github.com/SSL-ACTX/pyfuckv2.git

🛠️ Usage

PyfuckV2 is designed to be used as a command-line tool.

usage: pyfuck [-h] [-i FILE] [-o FILE] [-m {string,eval,exec}] [-v] [source]

A Python obfuscator using only **[(+travels)]** characters.

positional arguments:
  source                The Python code string to encode. If not provided, reads from stdin.

I/O Options:
  -i FILE, --input FILE
                        File to read Python code from. Overrides the positional source argument.
  -o FILE, --output FILE
                        File to write the encoded output to. Prints to stdout by default.

Encoding Options:
  -m {string,eval,exec}, --mode {string,eval,exec}
                        Encoding mode:
                          string: creates an expression evaluating to the source string.
                          eval: creates an expression that evaluates the source code.
                          exec: creates an expression that executes the source code (default).
  -v, --verbose         Show verbose output during the character bootstrapping phase.

Command-Line Examples

Description Command
Encode a string directly pyfuck 'print("Hello from the CLI!")'
Encode a file and save the output pyfuck -i my_script.py -o obfuscated.py
Encode from stdin using a pipe echo "import sys; print(sys.version)" | pyfuck
Generate a string expression pyfuck -m string "42"
Use verbose mode to see the magic pyfuck -v "1+1"

Verbose Mode

Using the --verbose or -v flag provides a fascinating look into the bootstrapping process, showing how each character and function is "learned" before the final code is assembled.

$ pyfuck -v '42'
[Verbose] Learned '<' -> str(str)[+all([[]])]...
⠋ Encoding...
[Verbose] Learned 'c' -> str(str)[+all([])]...
[Verbose] Learned 'l' -> str(str)[all([])+all([])]...
[Verbose] Learned 'a' -> str(str)[all([])+all([])+all([])]...
[Verbose] Learned 's' -> str(str)[all([])+all([])+all([])+all([])]...
[Verbose] Learned ' ' -> str(str)[all([])+all([])+all([])+all([])+all([])+all([])]...

🙏 Credits and Inspiration

This project was developed by SSL-ACTX and stands on the shoulders of giants in the esoteric programming world.

  • JSFuck: The original and most famous implementation of this concept in JavaScript, which demonstrated that any JS code could be written with only six characters: []()!+.
  • PyFuck: An earlier Python implementation that served as a direct inspiration for this more feature-rich and robust version.

PyfuckV2 aims to modernize the concept with a clean codebase, a powerful CLI, and a more detailed explanation of its inner workings.

📄 License

This project is licensed under the MIT License. See the LICENSE file for the full text.

About

A Python code transformer using a limited esoteric character set.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages