Refactored fd1094's decryption code in order to make the function more amenable to inversion. [Andreas Naive]