I just tried to implement Fermat's little theorem in JavaScript. I tried this in both directions, a ^ (p-1) mod p = 1 and a ^ p mod p = a mod p.
function fermat(a, p) { return (((a ^ (p - 1)) % p) === 1); }
and
function fermat(a, p) { return ( ( a^p ) % p ) === ( a % p ); }
This does not work in both directions, is there a way to fix this?
javascript algebra
fb55
source share