Miller–Rabin primality test: Difference between revisions

Line 1,015:
 
=={{header|Crystal}}==
=== This is a directcorrect translationM-R oftest the Ruby versionimplementation for arbitraryusing sizedbases integers> input. ===
==== It is a direct translation of the Ruby version for arbitrary sized integers. ====
==== It is deterministic for all integers < 3_317_044_064_679_887_385_961_981. Increase 'primes' array members for more "confidence" past this value. ====
==== Increase 'primes' array members for more "confidence" past this value. ====
 
It is deterministic for all integers < 3_317_044_064_679_887_385_961_981. Increase 'primes' array members for more "confidence" past this value.
<lang Crystal>
require "big"
Line 1,042 ⟶ 1,044:
while (d & 0xf) == 0; d >>= 4 end # suck out factors of 2
(d >>= (d & 3)^2; d >>= (d & 1)^1) if d.even? # 4 bits at a time
witnesses.each do |b| # loopdo overM-R test with each witness basesbase
next if (b % self) == 0 # **skip base if a multiple of input**
y = powmod(b, d, self) # y = (b**d) mod self
Anonymous user