func (g *RSA) Exp(base, exponent *big.Int) *big.Int {
	expAbs := new(big.Int).Abs(exponent)
	if expAbs.Cmp(exponent) == 0 {
		return new(big.Int).Exp(base, exponent, g.N)
	} else {
		t := new(big.Int).Exp(base, expAbs, g.N)
		return g.Inv(t)
	}
}
Exp computes base^exponent in QR_N. This means base^exponent mod rsa.N.
package qr
import (
	"math/big"
	"fmt"
)
type RSA struct {
	N     *big.Int  
	P     *big.Int
	Q     *big.Int
	Order *big.Int  
}
func NewRSA(P, Q *big.Int) (*RSA, error) {
	if !P.ProbablyPrime(20) || !Q.ProbablyPrime(20) {
		return nil, fmt.Errorf("P and Q must be primes")
	}
	pMin := new(big.Int).Sub(P, big.NewInt(1))
	pMinHalf := new(big.Int).Div(pMin, big.NewInt(2))
	qMin := new(big.Int).Sub(Q, big.NewInt(1))
	qMinHalf := new(big.Int).Div(qMin, big.NewInt(2))
	order := new(big.Int).Mul(pMinHalf, qMinHalf)
	return &RSA{
		N:     new(big.Int).Mul(P, Q),
		P:     P,
		Q:     Q,
		Order: order,
	}, nil
}
func NewRSAPublic(N *big.Int) *RSA {
	return &RSA{
		N: N,
	}
}
func (g *RSA) Add(x, y *big.Int) *big.Int {
	r := new(big.Int)
	r.Add(x, y)
	return r.Mod(r, g.N)
}
func (g *RSA) Mul(x, y *big.Int) *big.Int {
	r := new(big.Int)
	r.Mul(x, y)
	return r.Mod(r, g.N)
}
func (g *RSA) Inv(x *big.Int) *big.Int {
	return new(big.Int).ModInverse(x, g.N)
}