question archive Select two distinct primes
Subject:Computer SciencePrice: Bought3
Select two distinct primes. Call them p q.
Let n = p*q
print n, p and q
Select an integer e in the range 1 < e < n such that gcd (e, (p-1)(q-1) ) = 1.
This means that e and (p-1)*(q-1) do not share a common factor. Recall that 35(==7*5) and 6(==2*3) are relatively prime even though neither is prime
The public key is the pair (e,n) Compute d in the range 1 < d < n such that d*e = 1 mod ( ( p-1)*(q-1) )
This statement can be computed as follows:
Find a d such that
e*d -1 == k(p-1)*(q-1) è d = [k(p-1)*(q-1) +1] /e for k = 1, 2 3 4 5 etc.
(use a while loop for k = 1, 2, 3, 4 until [k(p-1)*(q-1) +1] /e does NOT result in a decimal value for d this is your d )
The private key is the pair (d,n) This should be kept secret!
print d
Ask the user for an integer in the dictionary below
See the message values below but the user input should be an integer in the range 70 - 82
print m
Encode the message m by using the public key as follows:
c = me mod n See Khan video for assistance
print c as follows: print("the encoded text is ",c)
Decode: We decrypt message c to obtain the orginal message m using the private key d
m = cd mod n
print (key, m) (should be the key and the original message )
for example if the user enters the integer 77 in step 5 then you should print out 77 and the text 'Enjoy your morning beverage'
Use the messages dictionary available
# dictionary
d = { 70:'What is up?',
71:'You are fast!',
72:'All your trinkets belong to us.',
73:'Someone on our team thinks someone on your team are in the same class.',
74:'You are the weakest link.',
75:'Encryption is fun;',
76:'Spring is my favorite season',
77:'Enjoy your morning beverage',
78:'I am an early riser',
79:'I am not an early riser',
80:'Wake Tech is my school',
81:'CSC 120 Computing Fundamentals',
82:'Best wishes to you'
} # end of dictionary
print('Here is your original dictionary', d)