ForHosting KIT · Math

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
Use it from WebAPIEmailTelegramApp soon
If you enter
Power (W)
23
You get
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.

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.

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.

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.

POSThttps://api.kit.forhosting.com/numth/safe-prime

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.

curl -X POST https://api.kit.forhosting.com/numth/safe-prime \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"p":23}'
{
  "p": 23
}
{
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

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.

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.

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.

Read the full KIT documentation →