def invmod(e, et)
      g, x = extended_gcd(e, et)
      fail ArgumentError, 'Teh maths are broken!' if g != 1
      x % et
    end
def invmod(e, et)
      g, x = extended_gcd(e, et)
      fail ArgumentError, 'Teh maths are broken!' if g != 1
      x % et
    end
Calculate the Modular Inverse.
 See : http://rosettacode.org/wiki/Modular_inverse#Ruby
 Based on pseudo code from http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Iterative_method_2