Last active
August 19, 2021 10:44
-
-
Save GordonOus/90f400866dfdc89a9e0437a839f648ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
========== First ========= | |
Lets compare both keys provided: | |
openssl rsa -pubin -inform PEM -text -noout < key1.pem | |
openssl rsa -pubin -inform PEM -text -noout < key2.pem | |
we can observe that both keys have SIMILAR modulus but DIFFERENT exponents: | |
after googling online on RSA attacks i found one for Common Modulus | |
Exploiting it according to me was not very trivial especially without solid background in crypto (google to the rescue) | |
had to follow this video: https://www.youtube.com/watch?v=uX2z4fZYYkQ to also manually understand the formulae before transferring to code | |
Overally, the equations that are helpful ini solving the challenge are: | |
a1c1 + a2c2 = 1 | |
where c1 and c2 are the cyphertexts and a1 is the multiplicative inverse of e1 and e2 (The exponents derived from both keys) | |
after getting a1, we can transform the write the above equation in terms of a2 to get the value of a2: | |
the equation i came up with is as below: | |
a2 = 1 - (modinverse(e1,e2) * e1) / e2 | |
Equation for decrypting the message : | |
m = c1<sup>a1</sup> * c2<sup>a2</sup> mod n | |
a2 will most probably be a negative number and that makes modular calculations much more difficult: hence the explanation | |
on the liked youtube video on how to work around that was very helpful. (inverse of c2 to the power a2) | |
also: | |
doing such big integer calculations would take forever to complete: to overcome this limitation: apply the modulus as you | |
go instead of waiting for the math operations to complete. (also explained in the linked video) | |
so overally it becomes: | |
[(c1<sup>a1</sup> mod n) * (inverse(c2) ** <sup>a2</sup>) mod n] mod n | |
Below are the steps above completed in python3.8 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment