Safe prime checker
Checks whether a prime p is safe, meaning (p − 1)/2 is prime too: 23 is safe because its half, 11, is prime, which also makes 11 a Sophie Germain prime. The half is always shown, so you can verify it yourself. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Power (W)
- 23
- Q
- 11
The safe prime checker accepts a prime integer p and determines whether the related value q = (p − 1) / 2 is also prime. When both numbers are prime, p is a safe prime and q is its Sophie Germain prime. Composite inputs are rejected instead of being labeled false, keeping the answer faithful to the definition and making input mistakes visible in automated workflows.
What a safe prime means
A safe prime is a prime number p whose associated half q = (p − 1) / 2 is prime too. Equivalently, p can be written as 2q + 1 with q prime; that smaller q is called a Sophie Germain prime. For example, 23 is safe because it is prime and its half candidate is 11, which is also prime.
By contrast, 13 is prime but not safe because (13 − 1) / 2 equals 6, a composite number. This checker keeps those two tests conceptually separate. It first verifies the premise supplied by the caller: p itself must be prime.
Only then does it calculate and test q. The exceptional prime 2 is accepted, but it is not safe: its candidate is 0.5, which is not an integer and therefore cannot be prime. This treatment follows the definition without silently narrowing valid prime input to odd primes.
How the deterministic check works
The capability validates that p is a whole integer from 2 through JavaScript’s maximum safe integer. It then performs an exact primality test using BigInt arithmetic, small-prime divisibility checks, modular exponentiation, and a fixed Miller–Rabin witness set that is deterministic throughout the supported range. Fixed witnesses matter because a random witness selection could make repeated calls follow different paths or offer only a probability-based answer.
For a valid odd prime, subtraction by one produces an even integer, so division by two is exact. All calculations happen locally with no network request, lookup table, random source, or clock dependency. Numeric output remains exact because both p and q are constrained to values that JavaScript numbers can safely represent.
Using the result in learning and software
Use the checker when the distinction between an ordinary prime and a safe prime is the actual question. In number theory lessons, it provides a concise demonstration of the paired relationship and exposes q so students can verify the arithmetic themselves. In test-data generation, it can validate a candidate selected elsewhere before that value enters a protocol exercise or benchmark.
The capability is useful for validation and education, but it does not generate primes, factor composite inputs, prove primality with a portable certificate, or claim suitability for production cryptography. Large cryptographic parameters commonly exceed this tool’s safe-integer limit and need specialized big-number libraries plus protocol-specific review.
What you can do with it
Verify number theory exercises
Check a proposed safe prime and show the corresponding Sophie Germain candidate so each part of the definition can be reviewed.
Separate primes from safe primes
Classify already-prime values by the primality of their half candidate without conflating composite input with a valid negative result.
FAQ
What does the safe prime checker cost?
The same deterministic check can run free in the browser interface.
Why is 23 a safe prime?
23 is prime, and (23 − 1) / 2 equals 11, which is also prime.
Can I use this to generate cryptographic safe primes?
No. It only checks one supplied value within the safe-integer range; it does not generate parameters or certify them for a cryptographic protocol.
Why is 13 not a safe prime?
13 is prime, but (13 − 1)/2 equals 6, which is composite. A safe prime needs both numbers to be prime, so the answer is no even though the number you entered is prime.
What happens if I enter a number that is not prime?
It is rejected with a message instead of a plain no, because a composite number cannot be a safe prime in the first place. Correct the number and try again rather than reading it as a negative result.
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/safe-prime \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"p":23}'const res = await fetch("https://api.kit.forhosting.com/numth/safe-prime", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"p": 23
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/safe-prime",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"p": 23
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/safe-prime", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"p":23}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"p":23}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/safe-prime", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"p": 23
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.safe_prime",
"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 result returns p, the computed q, and a direct safe_prime boolean.
What a safe prime means
The response echoes p, reports q, and sets safe_prime to true or false, so there is no need to reconstruct the intermediate value elsewhere.
How the deterministic check works
Here, the same input always produces the same JSON result. If p is composite, processing stops with an invalid_input error that names the failed premise; safe_prime is not returned as false, because false would incorrectly suggest that a composite number was a non-safe prime. The checker applies the same primality routine to that q value and returns the boolean decision.
Using the result in learning and software
In application code, treat invalid_input as a correction for the caller, not as a negative safe-prime result and not as a transient failure to retry. A successful response with safe_prime false says that p passed primality testing but q did not; a true value says both passed. The same deterministic implementation supports the free browser interface and API automation at $0.002 per request, giving interactive checks and scripted validation an identical input rule and output shape.
Integration use cases
Validate generated test fixtures
Confirm that a prime chosen by another deterministic generator is actually safe before saving it in protocol or algorithm test data.
Technical questions
What happens if p is composite?
The request returns invalid_input because safe primes are defined only for prime p. It does not return safe_prime false for a composite input.
Is 2 considered a safe prime?
No. Although 2 is prime, (2 − 1) / 2 is 0.5, which is not an integer prime, so safe_prime is false.