# Modular Arithmetic API
> Modular-arithmetic maths as an API, computed locally and deterministically with exact big-integer arithmetic. The power endpoint computes modular exponentiation, aᵇ mod m, by square-and-multiply, fast and exact even for the huge exponents used in cryptography. The inverse endpoint finds the modular multiplicative inverse a⁻¹ mod m with the extended Euclidean algorithm, returning the inverse when a and m are coprime and reporting the gcd when no inverse exists. The totient endpoint computes Euler's totient φ(n) — the count of integers from 1 to n coprime to n — with the prime factorization it comes from, and an optional Euler-theorem check that a^φ(n) ≡ 1 (mod n) for a coprime base. These are the building blocks of RSA and much of modern cryptography. Inputs are integers and can be passed as strings for very large values. Everything is computed locally and deterministically, so it is instant and private. Ideal for cryptography, security, blockchain and mathematics app developers, RSA and number-theory tools, and computer-science education. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is modular arithmetic; for prime factorization and GCD use a number-theory API and for integer sequences a sequences API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/modular-api/..."
```

## Pricing
- **Free** (Free) — 3,000 calls/Mo, 2 req/s
- **Starter** ($7/Mo) — 25,000 calls/Mo, 5 req/s
- **Pro** ($19/Mo) — 150,000 calls/Mo, 15 req/s
- **Mega** ($59/Mo) — 1,000,000 calls/Mo, 40 req/s

## Endpoints

### Modular

#### `GET /v1/inverse` — Modular inverse

**Parameters:**
- `a` (query, required, string) — Value a Example: `3`
- `modulus` (query, required, string) — Modulus m (> 0) Example: `11`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/modular-api/v1/inverse?a=3&modulus=11"
```

**Response:**
```json
{
    "data": {
        "gcd": "1",
        "note": "Modular multiplicative inverse a⁻¹ mod m via the extended Euclidean algorithm.",
        "check": "3 × 4 ≡ 1 (mod 11)",
        "inputs": {
            "a": "3",
            "modulus": "11"
        },
        "inverse": "4",
        "invertible": true
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:00.480Z",
        "request_id": "a4c03f21-ffcb-4b40-92bc-1d68d3a0e8ad"
    },
    "status": "ok",
    "message": "Modular inverse",
    "success": true
}
```

#### `GET /v1/power` — Modular exponentiation

**Parameters:**
- `base` (query, required, string) — Base a Example: `7`
- `exponent` (query, required, string) — Exponent b (≥ 0) Example: `256`
- `modulus` (query, required, string) — Modulus m (> 0) Example: `13`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/modular-api/v1/power?base=7&exponent=256&modulus=13"
```

**Response:**
```json
{
    "data": {
        "note": "Modular exponentiation aᵇ mod m by square-and-multiply, exact for very large numbers.",
        "inputs": {
            "base": "7",
            "modulus": "13",
            "exponent": "256"
        },
        "result": "9"
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:00.569Z",
        "request_id": "7273c47a-e621-4aca-81bf-cd37cc46fb3d"
    },
    "status": "ok",
    "message": "Modular power",
    "success": true
}
```

#### `GET /v1/totient` — Euler totient

**Parameters:**
- `n` (query, required, string) — Integer n (> 0) Example: `36`
- `a` (query, optional, string) — Base a for an Euler-theorem check Example: `5`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/modular-api/v1/totient?n=36&a=5"
```

**Response:**
```json
{
    "data": {
        "note": "Euler's totient φ(n) counts the integers in 1..n coprime to n. For gcd(a,n)=1, a^φ(n) ≡ 1 (mod n) (Euler's theorem).",
        "inputs": {
            "n": "36"
        },
        "totient": "12",
        "euler_check": {
            "a": "5",
            "coprime": true,
            "a_pow_phi_mod_n": "1"
        },
        "prime_factorization": [
            {
                "prime": "2",
                "exponent": 2
            },
            {
                "prime": "3",
                "exponent": 2
            }
        ]
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:00.695Z",
        "request_id": "9390e275-8e49-4442-b060-1ebaceefb5dc"
    },
    "status": "ok",
    "message": "Euler totient",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/modular-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "All inputs are integers (passed as strings for very large values); the modulus must be positive. The basis of RSA and many cryptographic schemes.",
        "service": "modular-api",
        "formulae": {
            "euler": "a^φ(n) ≡ 1 (mod n) when gcd(a,n)=1",
            "inverse": "a·a⁻¹ ≡ 1 (mod m), exists iff gcd(a,m)=1",
            "mod_pow": "aᵇ mod m",
            "totient": "φ(n) = n·∏(1 − 1/p) over distinct primes p | n"
        },
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/power": "Modular exponentiation aᵇ mod m (square-and-multiply).",
            "GET /v1/inverse": "Modular multiplicative inverse a⁻¹ mod m (extended Euclid).",
            "GET /v1/totient": "Euler's totient φ(n), its prime factorization, and an optional Euler check."
        },
        "description": "Modular-arithmetic calculator with exact big-integer maths: modular exponentiation, the modular multiplicative inverse, and Euler's totient with an Euler-theorem check."
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:00.787Z",
        "request_id": "edce2263-38c7-4cbd-8ab3-f9a99056e4cf"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/modular-api
OpenAPI spec: https://www.oanor.com/api/modular-api/openapi.json
