I'm studying cryptography. According to Fermat's theorem... $$a^{p-1} \pmod p = 1$$ .. when $p$ is a prime number. The above should prove whether a number is prime or not yet it doesn't work for simple primes like $7$...
Having ran through a routine to show all values up to $50$ it seems to indicate that only $17$ passes the primality test as being probably (or in this case definitely) a prime. Had I picked random values for $a$, every other prime number from $1$ to $50$ would have failed the test.
Result of prime modulus $7$
$$8 = (2^{6}) \mod 7$$ $$8 = (3^{6}) \mod 7$$ $$8 = (4^{6}) \mod 7$$ $$8 = (5^{6}) \mod 7$$ $$1 = (6^6) \mod 7$$
Result of prime modulus $17$ $$1 = (2^{16}) \mod 17$$ $$1 = (3^{16}) \mod 17$$ $$1 = (4^{16}) \mod 17$$ $$1 = (5^{16}) \mod 17$$ $$1 = (6^{16}) \mod 17$$ $$1 = (7^{16}) \mod 17$$ $$1 = (8^{16}) \mod 17$$ $$1 = (9^{16}) \mod 17$$ $$1 = (10^{16}) \mod 17$$ $$1 = (11^{16}) \mod 17$$ $$1 = (12^{16}) \mod 17$$ $$1 = (13^{16}) \mod 17$$ $$1 = (14^{16}) \mod 17$$ $$1 = (15^{16}) \mod 17$$ $$1 = (16^{16}) \mod 17$$
Have I misunderstood the use of the theorem as a primality tester?