Exercise 3: Python
Mark: 20%
Alice and Bob need to individually and separately generate the same encryption (secret) key to allow them
to securely exchange a message (read about Diffie-Hellman key exchange). To do this, in this case, they both
need two public numbers (π = 353 and πΌ = 3). Alice calculates an individual public key (ππ΄ = 40) and sends it
to Bob. Bob calculates an individual public key (πB = 248) and sends it to Alice. To generate the secret key
(K), Alice and Bob would need their individual private keys (ππ΄ and XB respectively) and the individual public
keys they received.
The relevant equations are:
ππ΄ = β
ππ΄ πππ π
ππ΅ = β
ππ΅ πππ π
πΎπ΄ = ππ΅
ππ΄ πππ π OR πΎπ΅ = ππ΄
ππ΅ πππ π
Write a python script that will crack (brute force) the values of ππ΄ and ππ΅ and use them to generate the
secret key (πΎ). You must comment your code and explain the steps. Deliverables include commented code
and screenshots showing the values (ππ΄, ππ΅ and πΎ) generated by the code.
Hint: You already know the values of (π = 353, πΌ = 3, ππ΄ = 40, and πB = 248). πππ π means βmodulus πβ
(check the mathematical notation for modulus). Your range is 1 to π β 1, which means 1 β 352. You are
looking for the values of ππ΄ and ππ΅ such that πΎπ΄ = πΎπ΅.
____________________________________________________