Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168742
Image: ubuntu2004
import binascii bits=256 # Generate two large prime numbers p = next_prime( ZZ.random_element(1, 2^(bits//2 +1)) ) q = next_prime( ZZ.random_element(1, 2^(bits//2 +1)) ) n = p*q phi_n = (p - 1)*(q - 1) while True: e = ZZ.random_element(1, phi_n) if gcd(e, phi_n) == 1: break d = power_mod(e, -1, phi_n) #computes e^(-1) mod phi_n e,d,n
(18504618844489859274977983157852324676921577873264505513536994768681728090807, 4244270334285079821131998092697524738650529643354327055069383089061088156623, 22224140447341099545733723057734793861666674509228661146298555277781225356847)
m=int(binascii.hexlify('Test Message'),16) c=power_mod(m,e,n) c
9329205991968375512579524637518670290434882710412944984360355943848456393735
b=power_mod(c,d,n) b
26119387547069534007986317157
binascii.unhexlify("%X" % b)
'Test Message'