Skip to main content

sutdobfs

Build Status PyPI version PyPI - Downloads license Coverage Status

a gift from a senior to the final batch of students taking the last round of Digital World in 2020

Singapore University of Technical Difficulties Obfuscator

Is normal Python code too boring? Do you want to make your code more d a n k? Don't want your friend to copy your Python homework? Want to make your Digital World Prof's life hard when grading your 1D/2D assignments (and get zero in the process)?

Introducing sutdobfs, the SUTD Obfuscator for Python. With this tool, easily turn your variable and (inner) function names into something established in collaboration with MIT.

Before (99 bottles of beer):

def main():
    def sing(b, end):
        print(b or 'No more', 'bottle' + ('s' if b - 1 else ''), end)

    for i in range(99, 0, -1):
        sing(i, 'of beer on the wall,')
        sing(i, 'of beer,')
        print('Take one down, pass it around,')
        sing(i - 1, 'of beer on the wall.\n')

After (99 bottles of DANK MEMES):

def main():
    def professional_practice_programme(established_in_collaboration_with_MIT, professional_practice_programme_copy):
        print(established_in_collaboration_with_MIT or 'No more', 'bottle' + ('s' if established_in_collaboration_with_MIT - 1 else ''), professional_practice_programme_copy)

    for eleven_to_one_student_to_faculty_ratio in range(99, 0, -1):
        professional_practice_programme(eleven_to_one_student_to_faculty_ratio, 'of beer on the wall,')
        professional_practice_programme(eleven_to_one_student_to_faculty_ratio, 'of beer,')
        print('Take one down, pass it around,')
        professional_practice_programme(eleven_to_one_student_to_faculty_ratio - 1, 'of beer on the wall.\n')

The best part? This tool actually produces real functioning code you can submit on Vocareum! Now you don't have to worry about getting hit with plagiarism warnings anymore.

This tool works on all sorts of programs, large and small. For reference, here is the meme'd version of the A* algorithm from Rosetta Code.

Installation and Usage

Using on Vocareum

For maximum dank, why not use it directly on Vocareum itself?

In the Terminal window of your Vocareum workspace, enter the following:

pip install --user sutdobfs

If you have trouble pasting into the terminal, Right Click > Paste instead.

vocareum-install

Now you can meme your homework files in the Vocareum workspace:

sutdobfs your_homework_file.py

vocareum-workspace

vocareum-obfs

This produces a new file in your workspace called your_homework_file.sutd.py, filled with glorious dank memes. Click on the workspace window on the left to let it refresh and open the file:

vocareum-result

Yeah, try plagarising this.

Because Vocareum workspaces are ephemeral (i.e. they may be destroyed when you leave the workspace), you may need to rerun the installation command if you leave Vocareum and come back later.

Local Installs

Open your terminal (or anaconda prompt if you installed anaconda – find it in your start menu) and type the following

pip install sutdobfs

Usage is the same:

sutdobfs your_file.py

This outputs the obfuscated file in your the same directory called your_file.sutd.py. The output file name and location can be changed in Advanced Usage.

If you get a "command not found" error, Python executables are likely not in your PATH. Either fix your PATH or use python3 -m sutdobfs instead.

Upgrading (Local Installs)

To get the dankest of memes, you will need to update whenever the meme list is updated:

pip install --upgrade sutdobfs

If it says "requirement already satisfied", but you can clearly see that the latest version on PyPI is greater than what you have, simply nuke and start over:

pip uninstall sutdobfs
pip install sutdobfs

How this works

sutdobfs uses the tokenizer module in the Python standard library to parse through source files. sutdobfs will scan through your code and identify variable and function names that are safe to rename: only names in the local and enclosed scopes will be renamed (if you're interested in the algorithm that determines scope, check the Gatekeeper source code). Candidate replacements are pulled from a "dictionary" (actually a .txt file) of memes to replace these variable names. In case of a name collision (too few memes), _copy will be appended to the end of the variable name. Finally, a new Python file (same filename ending with .sutd.py in the same directory by default) containing the memed names is be created.

The default list of memes can be found in the memes.txt file. Feel free to add more memes to the list using GitHub! If you're new to GitHub, this is a great way to learn how to use GitHub to collaborate – read the contributing guide for more information.

Advanced Usage

Custom output path

Simply add another argument to the command line to customize the path of the output file:

sutdobfs input_file.py output_file.py

Random Names for Memes

By default, names are chosen using hashing: that means the same variable name will always result in the same meme (for the same meme dictionary). If you would like a random meme to be chosen every time you run the obfsucator, add the --random option:

sutdobfs input_file.py --random

Sequential Names for Memes

To guarantee that all memes in the dictionary are used before memes are recycled, pass the --sequential (or --seq) argument:

sutdobfs input_file.py --seq

This will assign memes based on the order sutdobfs encounters names in your source code. This can be combined with the --random option:

sutdobfs input_file.py --seq --random

Custom Meme Dictionaries

You can specify your own text file containing memes to be used in the replacement process:

sutdobfs input_file.py --memes your_meme.txt

Python 3 supports unicode characters in other languages (but not emoji). Get creative!

Here's an example using the built-in jojo.txt meme dictionary:

def main():
    def even_speedwagon_is_afraid(ORA_ORA_ORA_ORA, オラオラオラオラオラオラ):
        print(ORA_ORA_ORA_ORA or 'No more', 'bottle' + ('s' if ORA_ORA_ORA_ORA - 1 else ''), オラオラオラオラオラオラ)

    for ムダムダムダムダムダムダ in range(99, 0, -1):
        even_speedwagon_is_afraid(ムダムダムダムダムダムダ, 'of beer on the wall,')
        even_speedwagon_is_afraid(ムダムダムダムダムダムダ, 'of beer,')
        print('Take one down, pass it around,')
        even_speedwagon_is_afraid(ムダムダムダムダムダムダ - 1, 'of beer on the wall.\n')

Note that your custom filename cannot be the same as the built-in ones found in the meme folder, otherwise the built-in files will be used instead.

Limitations

At the moment, this tool cannot meme f-strings, because the tokenzier module reads f-strings as a single giant string. I am working hard on a f-string lexer, in the meantime, please use the older str.format method instead.

This tool will break if your code attempts to perform imports in a local scope. I will not fix this, because you're not supposed to use the import keyword like that anyway.

This tool is offered on a best effort basis with absolutely no warranty. If you find a bug or have a suggestion, please open an issue on this GitHub repository and include the sample file that you tried to meme.

Metadata

Release files for sutdobfs 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sutdobfs 1.0.4
File Size Uploaded Provenance Actions
sutdobfs-1.0.4.tar.gz 11.4 kB Without provenance Details for sutdobfs-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sutdobfs 1.0.4
File Interpreter ABI Platform Actions
sutdobfs-1.0.4-py3-none-any.whl Python 3 none any Details for sutdobfs-1.0.4-py3-none-any.whl

Total release size: 21.7 kB

Release files / sutdobfs-1.0.4.tar.gz

Download URL sutdobfs-1.0.4.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
34c6c0de5a243cf26fdc3503f3613651a4384652ad6d8564b10cdd7b59b4bd7e
BLAKE2b-256 checksum
How to use checksums
d1869b9877522c0b84809355b4e4e6fc85549b9183d0a42cc08b0516431286ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6

Release files / sutdobfs-1.0.4-py3-none-any.whl

Download URL sutdobfs-1.0.4-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6500ae1acf1557e0db02f75a3c32cf922c4084a24046fb8df1a53ce8ae019edc
BLAKE2b-256 checksum
How to use checksums
875a2220c10dd835972115facf8e543ae9a5d7b7f5f521a988e3e37435ca9a80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6

Security for sutdobfs 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page