This semester, I found myself making a lot of solutions to problem sets and exams, which I organize in public GitHub repos. I wanted a way to store the solutions to these assignments in the repos.

After a few months I found a solution that seemed to work well. The basic idea is to created a symlinked script on my local machine which encrypts solutions files so they can be committed.

Here is how it works

$ ls 
$ enc secret_solutions.ipynb # encrypt the file
$ ls 
secret_solutions.ipynb secret_solutions.ipynb.enc
$ head -1 secret_solutions.ipynb.enc
ք|�m@�!�3�����3+�~�V��j:����a a;}
$ git add secret_solutions.ipynb.enc && git commit -m solutions && git push origin main  # commit solution
$ rm secret_solutions.ipynb
$ dec secret_solutions.ipynb  # decrypt the file
$ ls 
secret_solutions.ipynb, secret_solutions.ipynb.enc

How is how to set it up

Here is how to set it up. I am assuming you have have installed openssl and set up a private key at ~/.ssh/id_rsa

First download the encrypt and decrypt scripts and give them execute permissions.

$ wget -O $HOME/

$ wget -O $HOME/

$ chmod +x $HOME/ && chmod +x $HOME/ # give run permission

Then symlink the encrypt and decrypt scripts so you can access them in your PATH

$ ln -s $HOME/ ~/bin/
$ ln -s $HOME/ ~/bin/

Finally, alias the scripts (I did this in a .zshrc file)

alias enc=""
alias dec=“”

After that you should be able to run

$ enc file.txt # encrypts file.txt into file.txt.enc
$ dec file.txt # decrypts file.txt.enc into file.txt

Important note: this system relies on a private key stored on your local machine. If you lose the key (e.g. maybe you get a new laptop), you will lose the encrypted answer forever. If you are teaching a class, losing your solutions is probably not such a big deal. But I did want to make a note of this.

If you are a student and you have read to here and also find a way to hack this system, I will give you an A.