As part of cryptography, if I wish to test whether a given number is probably prime I use the formula:
$$ a^{p-1} \equiv 1 \bmod p $$
where $p$ is (potentially) a prime number.
However, when it comes to testing a number such as 2341, i.e. $$2^{2341} \mod 2342$$ ... the numbers are two big for a calculator. I'm required as part of a course to generate a random 9 digit number and test for primality using the formula above.
Can I use congruence to reduce the numbers involved without invalidating the test?
Not sure how since shrinking the powers I'm shrinking the RHS of the equation and therefore testing another number completely for primality.