function Pollardpminus1(n, B) % Pollardpminus1(n, B) % Inputs: an odd composite integer n > 3, and a positive integer B: % Program will apply Pollard's p-1 factorization algorithm to look for a % nontrivial factor of n. A primality test (such as Miller-Rabin) should % be applied first to assure that n is composite. If no factor is found, % algorithm may be reapplied with a larger value of B. %CAUTION: This program does not have symbolic functionality, the analogous %program that has is is named as Pollardpminus1Sym %First we need to compute a^(B!) (mod n); we take a = 2. A = 2; for i = 2:B A = FastExp(A,i,n); end d = gcd(A-1,n); if d>1 fprintf('The following factor of n has been found: d = %d.\r', d) else fprintf('No factor of n was detected; you may wish to reapply the test with a larger value of B.\r') end