Reverse-engineered optimal encryption