More elegant solution to public key problem from earlier