1

I am currently working on creating a dataset of prime and composite numbers to run against 100 random witnesses using the Miller-Rabin primality test. However, the results I have obtained so far are consistent with the correct answers: i.e., if a number is prime, all iterations return prime, and if a number is composite, all return composite. There are no false positives in my results.

To make my dataset more comprehensive, I would like to introduce some false positives. In particular, I am looking for an algorithm that, given a composite number can generate

random witnesses such that

is a strong pseudoprime to all of them. Alternatively, I am interested in an algorithm that, given a set

of witnesses, can produce a composite number

such that

is a strong pseudoprime to all elements in .

Additionally, I would like to know if there is an algorithm that can generate Carmichael numbers randomly, or a method for producing large Carmichael numbers. This would further help diversify my dataset, especially with composite numbers that may pass multiple primality tests.

Constraints: The data I am working with is within the range 2^64 - to 2^2048. I need to generate 50,000 records that contain false positives. My dataset is structured as follows: 1 column listing the number. 100 columns listing the random witnesses for that number. 1 additional column indicating whether the number is prime (using the Elliptic Curve Primality Proving (ECPP) test). I have reviewed a few papers related to these topics but have not come across a solution that fits my requirements. Any guidance on generating such numbers or references to relevant algorithms would be greatly appreciated!

  • You might want to check out the 'Constructing Pseudoprimes' section of this document https://pure.royalholloway.ac.uk/ws/portalfiles/portal/39023193/2020MassimoJPhD.pdf – Simon Goater Mar 22 '25 at 11:10
  • Please note that the document above is a bit out of date regarding the state of library primality tests. For a list of all base 2 pseudoprimes below 2^64, see https://www.cecm.sfu.ca/Pseudoprimes/ which will include all Carmichael numbers below 2^64. – Simon Goater Mar 22 '25 at 11:35

2 Answers2

1

I don't think there will be very efficient methods in the range you're interested in, i.e., up to $2^{2048}.$

You can have a look at Pinch's method, see paper, with abstract

There are 105212 Carmichael numbers up to 10^{15} : we describe the calculations. The numbers were generated by a back-tracking search for possible prime factorizations, and the computations checked by searching selected ranges of integers directly using a sieving technique, together with a "large-prime variation".

was used to generate all carmichael numbers up to $10^{15}.$ The table here may also help you, it goes up to $2^{64}$ and covers part of the range you are interested in.

An algorithm in Python code for computing the Carmichael numbers in a given range was given in the answer to this question. It is claimed that the algorithm is efficient, you might want to test it.

kodlu
  • 10,287
1
import random

def single_test_odd(a, p, q):
    m = pow(a, q, p)
    return m

def single_test_even(a, p, q, tp):
    c = 0
    m = pow(a, q, p)
    for _ in range(tp):
        m = pow(m, 2, p)
        if m == p - 1:
            c += 1
    return c

# Pseudoprimes test
t = 1000
r = 2**64
cc = 0

for n in range(1, 10**3 + 1):
    c1 = c2 = 0
    r = nextprime(r)
    p_candidate = (r - 1) * 2 + 1
    if isprime(p_candidate):
        p = r * p_candidate
        q = (p - 1) // 2
        tp = 0
        while q % 2 == 0:
            tp += 1
            q //= 2

        for _ in range(t):
            a = random.randint(3, p - 1)
            s = single_test_odd(a, p, q)
            if s == 1 or s == p - 1:
                c1 += 1
            if single_test_even(a, p, q, tp):
                c2 += 1
        c=c1+c2
        if c > t / 6:
            cc += 1
            print(f"{cc} {r} {p} {c1} {c2} {c/t*100:.2f} % {c}")

This Python code can generate single test MR pseudo primes of any length. r is the start value of the base prime to make the pseudoprime. It outputs all pseudo primes that pass for more than 1/6 ( c > t /6 ), you can also adjust that if you like.

1 18446744073709555927 680564733841877245003957277837372102731 245 0 24.50 % 245
2 18446744073709557979 680564733841877396414832634845415570903 265 0 26.50 % 265
3 18446744073709559287 680564733841877492928197628493826337451 232 0 23.20 % 232
4 18446744073709560139 680564733841877555794701431696005838503 248 0 24.80 % 248
5 18446744073709560199 680564733841877560221920009386300279003 261 0 26.10 % 261
6 18446744073709562077 680564733841877698793861491092523545781 57 123 18.00 % 180
7 18446744073709566691 680564733841878039246970115476243812271 250 0 25.00 % 250
8 18446744073709569691 680564733841878260607898999991062101271 243 0 24.30 % 243
9 18446744073709573051 680564733841878508532139350647701324151 254 0 25.40 % 254
10 18446744073709577029 680564733841878802056731051514459356653 62 136 19.80 %% 198
11 18446744073709582837 680564733841879230611489371935420354301 61 122 18.30 % 183
12 18446744073709583161 680564733841879254518469691463039920681 20 160 18.00 % 180
13 18446744073709585021 680564733841879391762245599862345555861 70 131 20.10 % 201
14 18446744073709585399 680564733841879419653722639311238393003 232 0 23.20 % 232
15 18446744073709588411 680564733841879641900095239364341421431 220 0 22.00 % 220
16 18446744073709590577 680564733841879801722685893984224795281 0 170 17.00 % 170

use scroll to view percentages if not visible.