Finding Mersenne primes
The page you linked to has pseudocode, and it does s = ((s × s) − 2) mod M. And right below the pseudocode it says:

Performing the mod M at each iteration ensures that all intermediate results are at most p bits (otherwise the number of bits would double each iteration).

Do that and it'll be much faster.
And better use the same variable names as in the page you referenced, don't make up new ones, that just obfuscates the connection.