I've seen several variations on "modular inverse" but I can't seem to identify the proper way of utilizing it for C++. I'm not sure how this python code translates into c++:
def inverse(x, p): """ Calculate the modular inverse of x ( mod p ) the modular inverse is a number such that: (inverse(x, p) * x) % p == 1 you could think of this as: 1/x """ inv1 = 1 inv2 = 0 while p != 1 and p!=0: inv1, inv2 = inv2, inv1 - inv2 * (x / p) x, p = p, x % p return inv2
My current coding is here: http://coliru.stacked-crooked.com/a/74648b16c2692525
But it only shows like the first public key properly, after that it messes up.