Deterministic Miller–Rabin test
97 is prime: it passes all seven fixed bases, 2, 3, 5, 7, 11, 13 and 23, proven to settle every whole number up to 9007199254740991. For a composite you also see the first base that exposed it. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 97
- Bound
- 9,007,199,254,740,991
- Witness count
- 7
The deterministic Miller–Rabin test decides whether an integer n is prime by running the strong probable-prime witness test against a short, fixed list of bases that are known to settle every integer below a published guarantee bound. Unlike a probabilistic Miller–Rabin run that draws random witnesses and only estimates error, this capability always uses the same bases, always returns the same verdict for the same n, and refuses input that sits above the bound where those bases are no longer proven sufficient. You send a single whole number at least two and at most the bound, and you receive a prime flag, the witness list, the bound itself, and—when the number is composite—the first witness that proved it.
How the fixed-base strong probable-prime test works
Miller–Rabin rewrites an odd candidate n as n minus one equals d times two to the s with d odd, then for each witness a computes a to the d mod n. If that power is one or n minus one, the witness passes. Otherwise the algorithm repeatedly squares the value up to s minus one times and accepts the witness only if some intermediate square equals n minus one; any other path proves that n is composite for that base.
A number that passes every witness is called a strong probable prime to those bases. For carefully chosen fixed sets, number-theory results show there is no composite below a known threshold that fools every base in the set—so the probable-prime outcome becomes a true prime outcome inside the bound. This capability uses the seven bases two, three, five, seven, eleven, thirteen, and twenty-three, which are sufficient for every sixty-four-bit integer and therefore for every safe JavaScript integer up to nine quadrillion.
Tiny primes two and three short-circuit as prime. When a witness divides n and is smaller than n, that witness is reported as the failing base because n is an obvious multiple.
What you can do with it
Teach fixed-base Miller–Rabin certificates
Show students a prime or composite verdict together with the exact witness list and guarantee bound, so the difference from random-witness probabilistic tests is concrete.
Validate prime-shaped parameters under a bound
Reject configuration values, puzzle seeds, or toy crypto moduli that fail fixed-base Miller–Rabin, and record the failing witness in the audit trail.
FAQ
What does the deterministic Miller–Rabin test cost?
The same check also runs free in your browser on this page; invalid input is not billed.
Which numbers are accepted?
Whole integers from 2 through the published guarantee bound 9007199254740991.
Which witness bases are used?
The fixed list 2, 3, 5, 7, 11, 13, and 23. They are returned in the witnesses field on every successful response so clients never have to hard-code the set.
Is this probabilistic Miller–Rabin?
No. Bases are fixed and proven sufficient for every integer in the supported bound, so the same n always produces the same deterministic prime or composite verdict.
What happens if n is larger than the bound?
The capability will not claim a deterministic verdict outside the range where the fixed bases are certified.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/numth/miller-rabin-deterministic \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":97}'const res = await fetch("https://api.kit.forhosting.com/numth/miller-rabin-deterministic", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 97
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/miller-rabin-deterministic",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 97
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/miller-rabin-deterministic", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":97}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":97}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/miller-rabin-deterministic", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 97
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.miller_rabin_deterministic",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The same pure modular arithmetic powers the free browser path and the API path, so homework checks, crypto toys, and automation scripts never disagree on a borderline Carmichael number or a strong pseudoprime.
What deterministic Miller–Rabin returns and how the bound works
Every successful call answers four related questions: is n prime under the fixed-base Miller–Rabin suite, which witness bases were applied, what is the largest integer this suite is guaranteed to decide correctly, and—if n is composite—which witness first failed the strong probable-prime test. The response is a compact JSON object with a boolean prime flag, the integer n echoed back, an ordered witnesses array, the numeric bound, a witness_count, a failing_witness field (null for primes, a concrete base for composites), and a method label set to miller_rabin_deterministic so clients can log the algorithm path. Input that is missing, fractional, non-numeric, or strictly less than two is rejected with invalid_input before any modular exponentiation runs. Values larger than the published guarantee bound are also rejected with invalid_input and a message that names the bound, because a fixed witness list is only a mathematical certificate inside that range; above it the same bases may leave a composite undetected. That hard stop is the product difference versus a general is-prime checker that might quietly switch strategies or claim primality without stating its certificate limit. Use this endpoint when you need an auditable deterministic Miller–Rabin verdict with the witness list and bound written into the result, not a probabilistic guess and not a full factorization of every divisor.
How the fixed-base strong probable-prime test works
Even composites are rejected immediately with failing_witness two without running the full loop.
Where a deterministic Miller–Rabin API earns its keep
Cryptography courses and CTF trainers use a deterministic Miller–Rabin test to show students the difference between random-witness probabilistic checks and fixed-base certificates that name their guarantee bound in the response. Application developers validate prime-shaped configuration values, puzzle seeds, or toy Diffie–Hellman parameters before a longer pipeline, catching even values and small composites without standing up a computer-algebra system. Prefer this tool when the search intent is specifically the deterministic Miller–Rabin algorithm with fixed witnesses and a hard bound—not when you need the smallest divisor of a composite, a complete prime factorization, Lucas–Lehmer for Mersenne numbers, or probabilistic tests with a custom witness list you supply yourself. Data engineers gate numeric columns that claim to be primes and store the failing_witness field in the audit log when a row fails. Because the capability is tier A, you can paste a number on this page and run the identical logic free in the browser; automate the same contract later at $0.002 per request when you wire tasks into scripts or SDKs. Keep n an integer of at least two within the published bound, treat invalid_input as a client fix rather than a retry, and log the witnesses and bound fields whenever you need a reproducible certificate of what was checked.
Integration use cases
Pin unit tests for modular primality code
Assert golden primes, composites, and out-of-bound rejections against a stable deterministic Miller–Rabin oracle before shipping a crypto or number-theory library change.