User:Thienithcm

sage: p = random_prime(10000); p 1601 sage: q = random_prime(10000); q 4073 sage: N = p*q sage: R = IntegerModRing(N) sage: phi_N = (p-1)*(q-1) sage: e = 47 sage: gcd(e, phi_N) 1 sage: d = xgcd(e,phi_N)[1] % phi_N sage: # Now by exponentiating with the private key sage: # we are effectively signing the data sage: # a few examples of this sage: to_sign = randint(2,2^10); to_sign 650 sage: # the signature is checked by exponentiating sage: # and checking vs the to_sign value sage: signed = R(to_sign)^d; signed 2910116 sage: to_sign == signed^e True sage: to_sign = randint(2,2^10); to_sign 362 sage: signed = R(to_sign)^d; signed 546132 sage: to_sign == signed^e True sage: # we can also see what happens if we try to verify a bad signature sage: to_sign = randint(2,2^10); to_sign 605 sage: signed = R(to_sign)^d; signed 1967793 sage: bad_signature = signed - randint(2,100) sage: to_sign == bad_signature^e False