Need help to understand this RSA common modulus attack Python code
Step by step of the code;

$gcd = \gcd(e_1,e_2)$

$a = e_1^{-1} \bmod e_2$

$b =gcd - (a\cdot e_1))/e_2 \implies gcd = b \cdot e_2 + a\cdot e_1$; The Bézout's identity

$i = c_2^{-1} \bmod n$

$mx = c_1^a \bmod n$

$my = i^{-b} \bmod n$

$\text{return } (mx \cdot my) \bmod n$


Now check
\begin{align}
 mx \cdot my &amp;=c_1^a \cdot i^{-b} \pmod n\\
  &amp; = c_1^a \cdot (c_2^{-1})^{-b} \pmod n\\ 
  &amp; =(m^{e_1})^a \cdot (m^{e_2})^{b} \pmod n\\
  &amp; =(m^{e_1 a+ e_2 b}) \pmod n\\
  &amp; = (m^{gcd})  &amp; &amp; \big[ = m \!\!\!\pmod n \,\textbf{ if } gcd=1\big]\\
\end{align}
The above calculation works for any $gcd$. This doesn't mean that we can resolve the message $m$ if $gcd&gt;1$. What if $gcd \neq 1$ then for case 2, it is so-called Rabin Cryptosystem, security is shown to be equal to factoring. if $gcd =3$ is the cube-root attack possible and if the textbook RSA is used and the message $m &lt; \sqrt[3]{n}$ recovery possible, and so on.
The conclusion is that they forget to write
  if gcd != 1:
      return -1

Writing good software is hard, writing good cryptographic software is much harder.
or someone is wrong on the internet

The common modulus attack is performed on Text-Book RSA when Alice and Bob use the same modulus $n$ with different public modulus. The first observation is that this is dangerous since Alice can learn Bob's private key, v.s. On the other hand, the eavesdropper ( passive attacker) knows the public keys $(n,e_1)$ and $(n,e_2)$ and when observed that the same message is sent to Alice and Bob (possibly broadcasting). Then the eavesdropper can resolve the broadcasted message $m$ if $\gcd(e_1,e_2)=1$. If they are using the same public exponent, this attack doesn't work.
When proper padding is used like PKCS#1 v1.5 and OAEP then this attack is not possible since they use randomization that prevents the equality of the same messages.