I've always been fascinated with obfuscation. To me, the fact that you can translate your code into an unintelligible mess but still be able to run it properly seems extraordinary.
After taking some inspiration from this absolute monstrosity, and after lots of head scratching, I was finally able to obfuscate my Python code for the first time ever. Of course, I had to do this manually, and that took a lot of time and effort. Out of boredom, I decided to make the dumbest thing ever and automate this.
I eventually managed to pull it off. Although not being fully polished, I feel contempt with this result.
Just to provide some insight, the name BFuscator came from combining the words "Bored" and "Obfuscator". Also, I have successfully obfuscated the obfuscator, however I had to manually minify the file for it to work.
The obfuscator won't work if you just press run, but will instead show the message below.
usage: python bfuscate.py -f <input file> -o (output file; defaults to <file>_BFUSCATE.py) outputted code must be run as a file
From here, you have two choices. The first choice if forking the project and working from there, and the second choice is working from the repl terminal, supposing you know how to use UNIX.
After you get your input file ready, you first need to minify it a bit. This step will be automated at a later date. First begin by removing all comments, and all extra newlines. This will help reduce the obfuscated file's size and also prevent a possible bug I've seen once or twice.
Once this is done, you can now run the command shown in the default message to obfuscate your code. If an output directory isn't specified, and supposing the file name is
sample, the output file will be named
sample_BFUSCATE.py. As it states, you cannot run the obfuscated code in a shell. This is because the program reads its own file to find the code after the
#. This cannot happen in a shell. You could change this by wrapping the code after the
# with an
exec(eval(...)), but I didn't include this in the final result because I felt that doing so would ruin the effect.