Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
340 views
'Let p and q be prime numbers and n be their product' p=233 q=151 is_prime(p) is_prime(q) n=p*q n (p-1)*(q-1) l=lcm(p-1,q-1) l
'Let p and q be prime numbers and n be their product' True True 35183 34800 17400
'Chose a number e that is relativiely prime to (p-1)(q-2)' e=17 e gcd(e,l) 'Bob Will Publish (n,e)' (n,e)
'Chose a number e that is relativiely prime to (p-1)(q-2)' 17 1 'Bob Will Publish (n,e)' (35183, 17)
'Find the inverse of e modulo n' h=xgcd(e,(p-1)*(q-1)) #Run the Extended Euclidean Algorithm to find s and t such that es + nt = 1. Then, the s becomes the inverse of e modulo n d=h[1] d #d is the inverse of e mod(e*d,(p-1)*(q-1)) #Test to ensure e and d are inverses modulo n
'Find the inverse of e modulo n' -2047 1
'To send a message x to Bob we compute y = x^e mod n and send that to Bob.' x = 24024; y=mod(x^e,n) y
'To send a message x to Bob we compute y = x^e mod n and send that to Bob.' 9307
'To decode the message Bob simply computes z = y^d mod n. (We have that (x^e)^d = x^(ed) = x mod n)' mod(y^d,n)
'To decode the message Bob simply computes z = y^d mod n. (We have that (x^e)^d = x^(ed) = x mod n)' 24024