Implement function to find a generator g for a prime p

* Fix a critical bug in Exp which would modify the inputs