Write nโ1 = 2หขยทd (d odd). This exposes the 2-adic structure needed for squaring.
โ
For witness a: compute x = aแต mod n. Square up to s times. Must hit 1 or nโ1 at the right step โ otherwise โ COMPOSITE.
Each round catches composites with prob โฅ 3/4 (Rabin). After k=5 rounds: error โค 4โปโต < 0.1%. Used in RSA key generation.