How to calculate M when the attacker know e and w Alice has a pair of RSA keys, the public key is $(n,e)$, the clear 
text message $M$ and the ciphertext $C=M^e \pmod n$.

We suppose that Bob wants to encrypt two successive messages and send them to Alice, the messages are of the form, $M$, and $M+w$, the corresponding ciphers are $C$ and $C’$.

We suppose that an attacker intercepted $C$ and $C’$ and that he 
knows $w$.

Find out how can the attacker calculate the message $M$, in the case of $e=2$.
You have $\{(n,e=2), M, w, C, \text{ and }, C'\}$ where;
\begin{align}
C &amp;= M^2 \pmod n \\
C'&amp;= (M+w)^2 \pmod n = M^2+2Mw+w^2 \pmod n
\end{align}


Now calculate $C'-C = M^2+2Mw+w^2 - M^2 \pmod n = 2Mw+w^2 \pmod n$
Substruct $w^2 \pmod n$ get $2Mw \pmod n$
Divide by 2 and get $Mw \pmod n$.
Find the inverse of $w$ to mod $n$ and multiply it to get the $M$.


in total $$M = (C' - C - w^2) (2w)^{-1} \pmod n$$ 
Note : when $e=2$ it is not RSA. The below quote form this answer;


  In fact, the Rabin Cryptosystem does exactly that.