A small self-hosted Rust service for hashing, HMAC, and number-theoretic cryptography exploration (FoxMath algorithms). It is designed to run alongside lab-api on the same EC2 instance without a database, queue, container, or monitoring stack.
Internet
|
HTTPS :443 (abhrankan.duckdns.org)
|
Nginx (TLS termination & auth)
|-- /school/*, /api/* -> 127.0.0.1:8088 (lab-api)
`-- /crypto-api/* -> 127.0.0.1:8089 (crypto-lab)
The Rust service binds to 127.0.0.1:8089. Nginx terminates HTTPS, applies HTTP Basic Auth where configured, and proxies the public /crypto-api/ prefix to the local service.
JSON requests must use Content-Type: application/json. All /v1/math/* endpoints support both GET (query parameters) for instant browser/CLI exploration and POST (JSON bodies) for programmatic pipelines.
| Method | Route | Auth | Purpose |
|---|---|---|---|
| GET | /health |
No | Service health |
| GET | /v1/info |
No | Application metadata and endpoint discovery |
| POST | /v1/hash |
Basic Auth at Nginx | SHA-256 or SHA-512 digest |
| POST | /v1/hmac |
Basic Auth at Nginx | HMAC generation |
| POST | /v1/hmac/verify |
Basic Auth at Nginx | Constant-time HMAC verification |
| GET / POST | /v1/math/legendre |
Configurable (Public or Basic Auth) | Legendre symbol |
| GET / POST | /v1/math/jacobi |
Configurable (Public or Basic Auth) | Jacobi symbol |
| GET / POST | /v1/math/solovay |
Configurable (Public or Basic Auth) | Solovay–Strassen probabilistic primality test |
| GET / POST | /v1/math/sqrtmod |
Configurable (Public or Basic Auth) | Modular square roots via Tonelli-Shanks |
| GET / POST | /v1/math/factor |
Configurable (Public or Basic Auth) | Prime factorization via Pollard's rho & trial division |
| GET / POST | /v1/math/totient |
Configurable (Public or Basic Auth) | Euler's totient |
| GET / POST | /v1/math/order |
Configurable (Public or Basic Auth) | Multiplicative order |
| GET / POST | /v1/math/dlog |
Configurable (Public or Basic Auth) | Discrete logarithm solver via Baby-step Giant-step ( |
| GET / POST | /v1/math/mobius |
Configurable (Public or Basic Auth) | Möbius function |
| GET / POST | /v1/math/sigma |
Configurable (Public or Basic Auth) | Sum of divisors function |
| GET / POST | /v1/math/tau |
Configurable (Public or Basic Auth) | Divisor count function |
| GET / POST | /v1/math/arith |
Configurable (Public or Basic Auth) | Unified arithmetic suite ( |
| GET / POST | /v1/math/crt |
Configurable (Public or Basic Auth) | Chinese Remainder Theorem solver (Extended GCD) |
| GET / POST | /v1/math/cf |
Configurable (Public or Basic Auth) | Continued fraction expansion & convergents |
| GET / POST | /v1/math/ecadd |
Configurable (Public or Basic Auth) | Elliptic curve point addition over |
| GET / POST | /v1/math/ecmul |
Configurable (Public or Basic Auth) | Elliptic curve scalar multiplication |
| GET / POST | /v1/math/challenge |
Configurable (Public or Basic Auth) | Seeded, reproducible math & crypto challenges |
| GET / POST | /v1/math/rsa/keygen |
Configurable (Public or Basic Auth) | Textbook RSA keypair generation |
| GET / POST | /v1/math/rsa/encrypt |
Configurable (Public or Basic Auth) | Textbook RSA encryption ( |
| GET / POST | /v1/math/rsa/decrypt |
Configurable (Public or Basic Auth) | Textbook RSA decryption with optional CRT acceleration |
| GET / POST | /v1/math/rsa/crack |
Configurable (Public or Basic Auth) | RSA modulus factoring attack via Pollard |
| GET / POST | /v1/math/dh/keygen |
Configurable (Public or Basic Auth) | Diffie–Hellman keypair generation ( |
| GET / POST | /v1/math/dh/derive |
Configurable (Public or Basic Auth) | Diffie–Hellman shared secret derivation ( |
| GET / POST | /v1/math/dh/crack |
Configurable (Public or Basic Auth) | Diffie–Hellman discrete logarithm recovery via BSGS |
| GET / POST | /v1/math/fermat |
Configurable (Public or Basic Auth) | Fermat's difference of squares factorization (n = x² − y² = (x − y)(x + y)) with Legendre quadratic residue sieve |
| GET (WS) | /v1/math/chamber/ws |
Configurable (Public or Basic Auth) | WebSocket stream for real-time Fermat factorization visualization ("The Chamber of Primes") |
| GET / POST | /v1/math/mersenne |
Configurable (Public or Basic Auth) | Mersenne numbers Mp = 2p − 1, Lucas–Lehmer deterministic primality testing, and prime sequence enumeration |
| GET / POST | /v1/math/perfect |
Configurable (Public or Basic Auth) | Euclid–Euler even perfect numbers 2p−1(2p − 1) and aliquot divisor verification (σ(n) = 2n) |
| GET / POST | /v1/math/pm1 |
Configurable (Public or Basic Auth) | Pollard's p − 1 integer factorization with two-stage smoothness bounds (B1, B2) |
| GET / POST | /v1/math/ecm |
Configurable (Public or Basic Auth) | Lenstra's elliptic curve factorization (ECM) with multi-curve exploration & two-stage smoothness bounds |
| GET / POST | /v1/math/dixon |
Configurable (Public or Basic Auth) | Dixon's random squares integer factorization with factor base and linear algebra over GF(2) |
| GET / POST | /v1/math/qs |
Configurable (Public or Basic Auth) | Quadratic Sieve (QS) integer factorization over polynomial sieve array and GF(2) linear algebra |
| GET / POST | /v1/math/squfof |
Configurable (Public or Basic Auth) | Shanks's square forms factorization (SQUFOF) with binary quadratic form infrastructure |
The public equivalents use the /crypto-api/ prefix, for example https://abhrankan.duckdns.org/crypto-api/v1/math/sqrtmod?a=10&p=13.
Request:
curl -sS https://abhrankan.duckdns.org/crypto-api/v1/infoResponse:
{
"service": "crypto-lab",
"api": "v1",
"version": "0.14.0",
"endpoints": [
"GET /health",
"GET /v1/info",
"POST /v1/hash",
"POST /v1/hmac",
"POST /v1/hmac/verify",
"GET /v1/math/legendre",
"POST /v1/math/legendre",
"GET /v1/math/jacobi",
"POST /v1/math/jacobi",
"GET /v1/math/solovay",
"POST /v1/math/solovay",
"GET /v1/math/sqrtmod",
"POST /v1/math/sqrtmod",
"GET /v1/math/factor",
"POST /v1/math/factor",
"GET /v1/math/totient",
"POST /v1/math/totient",
"GET /v1/math/order",
"POST /v1/math/order",
"GET /v1/math/dlog",
"POST /v1/math/dlog",
"GET /v1/math/mobius",
"POST /v1/math/mobius",
"GET /v1/math/sigma",
"POST /v1/math/sigma",
"GET /v1/math/tau",
"POST /v1/math/tau",
"GET /v1/math/arith",
"POST /v1/math/arith",
"GET /v1/math/crt",
"POST /v1/math/crt",
"GET /v1/math/cf",
"POST /v1/math/cf",
"GET /v1/math/ecadd",
"POST /v1/math/ecadd",
"GET /v1/math/ecmul",
"POST /v1/math/ecmul",
"GET /v1/math/challenge",
"POST /v1/math/challenge",
"GET /v1/math/rsa/keygen",
"POST /v1/math/rsa/keygen",
"GET /v1/math/rsa/encrypt",
"POST /v1/math/rsa/encrypt",
"GET /v1/math/rsa/decrypt",
"POST /v1/math/rsa/decrypt",
"GET /v1/math/rsa/crack",
"POST /v1/math/rsa/crack",
"GET /v1/math/dh/keygen",
"POST /v1/math/dh/keygen",
"GET /v1/math/dh/derive",
"POST /v1/math/dh/derive",
"GET /v1/math/dh/crack",
"POST /v1/math/dh/crack",
"GET /v1/math/fermat",
"POST /v1/math/fermat",
"GET /v1/math/chamber/ws",
"GET /v1/math/mersenne",
"POST /v1/math/mersenne",
"GET /v1/math/perfect",
"POST /v1/math/perfect",
"GET /v1/math/pm1",
"POST /v1/math/pm1",
"GET /v1/math/ecm",
"POST /v1/math/ecm",
"GET /v1/math/dixon",
"POST /v1/math/dixon",
"GET /v1/math/qs",
"POST /v1/math/qs",
"GET /v1/math/squfof",
"POST /v1/math/squfof"
],
"build_profile": "release",
"environment": "production"
}The information endpoint is public and exposes only non-sensitive application metadata. environment comes from the optional LAB_API_ENV deployment label and defaults to unknown; it must never contain secrets.
Request:
{
"algorithm": "sha256",
"data": "hello"
}Response:
{
"algorithm": "sha256",
"digest": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
}Request:
{
"algorithm": "sha256",
"key": "secret",
"data": "message"
}Response:
{
"algorithm": "sha256",
"mac": "8b5f48702995c1598c573db1e21866a9b825d4a794d169d7060a03605796360b"
}Digest and MAC values are lowercase hexadecimal strings. Supported algorithms are exactly sha256 and sha512.
Request:
{
"algorithm": "sha256",
"key": "secret",
"data": "message",
"mac": "8b5f48702995c1598c573db1e21866a9b825d4a794d169d7060a03605796360b"
}Response:
{
"algorithm": "sha256",
"valid": true
}Verification compares the decoded MAC using a constant-time equality operation. An invalid hexadecimal MAC is a 400 Bad Request; a well-formed but incorrect MAC returns 200 OK with "valid": false.
All math endpoints accept either query parameters (GET) or a JSON payload (POST).
Computes 1 (quadratic residue), -1 (non-residue), or 0 (
# GET via query parameters
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/legendre?a=10&p=13"
# {"a":10,"p":13,"value":1}
# POST via JSON
curl -sS -H "content-type: application/json" \
-d '{"a": 5, "p": 17}' \
https://abhrankan.duckdns.org/crypto-api/v1/math/legendre
# {"a":5,"p":17,"value":-1}Generalizes the Legendre symbol 1, -1, or 0 (
# GET via query parameters
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/jacobi?a=10&n=21"
# {"a":10,"n":21,"value":-1}
# POST via JSON
curl -sS -H "content-type: application/json" \
-d '{"a": 2, "n": 15}' \
https://abhrankan.duckdns.org/crypto-api/v1/math/jacobi
# {"a":2,"n":15,"value":1}Probabilistic primality test checking Euler's criterion 20). Detects Euler pseudoprimes and Carmichael numbers that evade naive Fermat tests.
# Solovay-Strassen test on prime 104729
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/solovay?n=104729&rounds=20"
# {"n":104729,"rounds":20,"is_prime":true}
# Solovay-Strassen test on Carmichael composite 561
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/solovay?n=561&rounds=20"
# {"n":561,"rounds":20,"is_prime":false}Finds square roots modulo an odd prime
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/sqrtmod?a=10&p=13"{
"a": 10,
"p": 13,
"roots": [6, 7]
}Decomposes an integer
# GET via query parameters
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/factor?n=360"
# POST via JSON
curl -sS -H "content-type: application/json" \
-d '{"n": 360}' \
https://abhrankan.duckdns.org/crypto-api/v1/math/factor{
"n": 360,
"factors": [
{"prime": 2, "power": 3},
{"prime": 3, "power": 2},
{"prime": 5, "power": 1}
],
"prime_factors": [2, 3, 5],
"expression": "2^3 * 3^2 * 5",
"is_prime": false
}Computes Euler's totient
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/totient?n=360"{
"n": 360,
"phi": 96,
"lambda": 12,
"is_cyclic": false
}Computes the exact multiplicative order
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/order?a=3&m=7"{
"a": 3,
"m": 7,
"order": 6,
"is_primitive_root": true
}Solves the discrete logarithm problem
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/dlog?g=3&h=6&p=7"{
"g": 3,
"h": 6,
"p": 7,
"x": 3,
"order": 6
}Computes foundational multiplicative number-theoretic functions over positive integers
-
Möbius function
$\mu(n)$ : Returns$(-1)^k$ for square-free$n$ with$k$ distinct prime factors,$0$ if$n$ has a squared prime factor, and$\mu(1) = 1$ . -
Sum of divisors
$\sigma_k(n)$ : Computes$\sum_{d|n} d^k$ (defaults to$k=1$ ). -
Divisor count
$\tau(n)$ : Number of positive divisors of$n$ . -
Unified arithmetic suite (
/v1/math/arith): Derives$\mu(n)$ ,$\sigma_k(n)$ , and$\tau(n)$ simultaneously in a single request from a shared prime factorization of$n$ .
# Unified arithmetic suite (evaluates mu, sigma_k, and tau in 1 request)
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/arith?n=12&k=1"
# {"n":12,"k":1,"mobius":0,"sigma":28,"tau":6}
# Individual endpoints
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/mobius?n=30"
# {"n":30,"value":-1}
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/sigma?n=12"
# {"n":12,"k":1,"value":28}
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/tau?n=12"
# {"n":12,"value":6}Solves simultaneous congruences
# Query params: r=2,3,2 & m=3,5,7
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/crt?r=2,3,2&m=3,5,7"
# JSON request:
curl -sS -H "content-type: application/json" \
-d '{"remainders": [2, 3, 2], "moduli": [3, 5, 7]}' \
https://abhrankan.duckdns.org/crypto-api/v1/math/crt{
"remainders": [2, 3, 2],
"moduli": [3, 5, 7],
"x": 23,
"modulus": 105
}Expands rational fraction
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/cf?num=355&den=113"{
"num": 355,
"den": 113,
"cf": [3, 7, 16],
"convergents": [
[3, 1],
[22, 7],
[355, 113]
]
}Performs group operations over toy97 and toy193. Returns null if the result is the point at infinity (identity).
# Scalar multiplication k·G on toy193
curl -sS -H "content-type: application/json" \
-d '{"curve": "toy193", "k": 7}' \
https://abhrankan.duckdns.org/crypto-api/v1/math/ecmul{
"curve": "toy193",
"k": 7,
"point": [1, 59],
"result": [66, 24],
"result_on_curve": true
}Generates seeded, reproducible practice problems for self-study and learning. Supports topics: legendre, jacobi, sqrtmod, factor, totient, dlog, crt, ecdlp, rsa, dh, mersenne, perfect, pm1, and mixed.
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/challenge?topic=legendre&seed=42&count=1"{
"topic": "legendre",
"seed": 42,
"count": 1,
"problems": [
{
"topic": "legendre",
"question": "Legendre symbol (10/13)",
"answer": 1
}
]
}End-to-end toy RSA workflows with configurable key sizes (
-
Key Generation (
/v1/math/rsa/keygen):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/rsa/keygen?bits=32&seed=42"Returns
p,q,n,e,d,phi,lambda,dp,dq, andqinv. -
Encryption (
/v1/math/rsa/encrypt):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/rsa/encrypt?m=42&e=65537&n=3233"Computes
$c \equiv m^e \pmod n$ . -
Decryption (
/v1/math/rsa/decrypt):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/rsa/decrypt?c=2557&d=2753&n=3233&p=61&q=53"Decrypts
$m \equiv c^d \pmod n$ with optional CRT speedup when factors$p$ and$q$ are provided. -
Modulus Factoring Attack (
/v1/math/rsa/crack):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/rsa/crack?n=3233&e=17&c=2557"Recovers
$p$ ,$q$ ,$\lambda(n)$ , and private exponent$d$ , decrypting ciphertext$c$ if provided.
Textbook Diffie–Hellman protocol over
-
Key Generation (
/v1/math/dh/keygen):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/dh/keygen?p=23&g=5&private_key=6"Computes public key
$A \equiv g^a \pmod p$ ($A = 8$ ). -
Shared Secret Derivation (
/v1/math/dh/derive):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/dh/derive?private_key=6&peer_public_key=19&p=23"Computes shared secret
$S \equiv B^a \pmod p$ ($S = 2$ ). -
Discrete Log Attack (
/v1/math/dh/crack):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/dh/crack?g=5&public_key=8&p=23"Recovers private exponent
$a = 6$ using the Baby-step Giant-step solver.
Fermat's difference of squares method expresses an odd composite integer
Starting at
-
REST Factorization (
/v1/math/fermat):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/fermat?n=5959"Returns non-trivial factor pair
$p = 59, q = 101$ ,$x = 80, y = 21$ , step trace, and timing in microseconds. -
WebSocket Real-Time Stream (
/v1/math/chamber/ws): Interactive bidirectional streaming endpoint powering "The Chamber of Primes" frontend visualizer.- Client actions:
start(n,delay_ms,max_steps),pause,resume,step,speed(delay_ms),stop. - Server event frames:
start,step(with Legendre sieve filter info and rejection prime),candidate,found,done.
- Client actions:
Mersenne numbers take the form
X ≡ (X >> p) + (X & ((1 << p) − 1)) (mod Mp).
-
Single Exponent Primality Test (
pparameter):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/mersenne?p=7"Response:
{ "p": 7, "mp": "127", "p_is_prime": true, "is_prime": true, "bits": 7, "digits": 3, "perfect_number": "8128" } -
Mersenne Primes Sequence Search (
limitparameter):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/mersenne?limit=127"Response:
{ "limit": 127, "primes": [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127] } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"p": 31}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/mersenne
An integer
where
-
Check if Integer
$n$ is Perfect (nparameter):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/perfect?n=8128"Response:
{ "n": 8128, "is_perfect": true, "sigma": 16256 } -
Generate Even Perfect Number from Exponent
$p$ (pparameter):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/perfect?p=7"Response:
{ "p": 7, "perfect_number": "8128" } -
Combined Verification & Generation:
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/perfect?n=28&p=3"Response:
{ "n": 28, "is_perfect": true, "sigma": 56, "p": 3, "perfect_number": "28" }
John Pollard's 1974 special-purpose integer factorization algorithm exploits composite numbers
An optimized Stage 2 checks primes
-
Stage 1 Smooth Factorization (
nandb1parameters):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/pm1?n=1393429&b1=20"Response:
{ "n": 1393429, "factor": 1009, "cofactor": 1381, "success": true, "stage": 1, "b1": 20, "b2": 200, "base": 2, "p_minus_1": 1008, "p_minus_1_factors": [ {"prime": 2, "power": 4}, {"prime": 3, "power": 2}, {"prime": 7, "power": 1} ], "p_minus_1_expression": "2^4 * 3^2 * 7", "steps": 8, "message": "Found non-trivial factor p = 1009 in Stage 1 at prime 7", "elapsed_us": 14 } -
Two-Stage Pollard p − 1 (
b2parameter):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/pm1?n=1407239&b1=2&b2=600"Response:
{ "n": 1407239, "factor": 1019, "cofactor": 1381, "success": true, "stage": 2, "b1": 2, "b2": 600, "base": 2, "p_minus_1": 1018, "p_minus_1_factors": [ {"prime": 2, "power": 1}, {"prime": 509, "power": 1} ], "p_minus_1_expression": "2 * 509", "steps": 104, "message": "Found non-trivial factor p = 1019 in Stage 2 at prime 509", "elapsed_us": 48 } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"n": 1012173119, "b1": 50}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/pm1
Hendrik Lenstra's 1987 elliptic curve factorization algorithm (ECM) is a sub-exponential integer factorization method that generalizes Pollard's p − 1 algorithm. While Pollard's p − 1 algorithm is constrained by the fixed multiplicative group
By Hasse's Theorem, the curve group order satisfies:
If
-
Two-Stage ECM with Stage 1 and Stage 2 bounds (
b1,b2,curves,seed):curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/ecm?n=1393429&b1=50&curves=10&seed=42"Response:
{ "n": 1393429, "factor": 1009, "cofactor": 1381, "success": true, "curve_index": 1, "curves_tested": 1, "stage": 1, "b1": 50, "b2": 500, "a": 646064, "b": 784997, "steps": 15, "message": "Found non-trivial factor p = 1009 on curve 1 in Stage 1 at prime 3", "elapsed_us": 12 } -
Factoring non-smooth p − 1 composites (e.g. Stage 2):
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/ecm?n=1042387&b1=50&b2=200&curves=10&seed=42"Response:
{ "n": 1042387, "factor": 701, "cofactor": 1487, "success": true, "curve_index": 1, "curves_tested": 1, "stage": 2, "b1": 50, "b2": 200, "a": 543688, "b": 428154, "steps": 48, "message": "Found non-trivial factor p = 701 on curve 1 in Stage 2 at prime 61", "elapsed_us": 25 } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"n": 2369625997, "b1": 500, "b2": 2000, "curves": 20, "seed": 42}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/ecm
John Dixon's 1981 algorithm is the prototype of all modern sub-exponential general-purpose integer factorization algorithms (including the Quadratic Sieve and the General Number Field Sieve). Unlike special-purpose algorithms (Pollard
The algorithm operates in three stages:
-
Factor Base Construction: Generates a factor base
$F = {-1, 2} \cup {p \le B \mid \left(\frac{n}{p}\right) = 1}$ . Primes for which$n$ is a quadratic non-residue are filtered out via Euler's criterion. -
Relation Generation: For
$x = \lceil\sqrt{n}\rceil + 1, \lceil\sqrt{n}\rceil + 2, \dots$ , evaluates centered residues$r \equiv x^2 \pmod n$ and checks for$B$ -smoothness over$F$ . -
Linear Algebra over
$\mathbb{F}_2$ : Forms the exponent parity matrix over the Galois field$\mathbb{F}_2$ . Gaussian elimination extracts null-space combinations whose product yields congruent squares$X^2 \equiv Y^2 \pmod n$ . Non-trivial factors are obtained via$\gcd(|X - Y|, n)$ .
-
GET Request:
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/dixon?n=84923&b=30"Response:
{ "n": 84923, "factor": 163, "cofactor": 521, "success": true, "b": 30, "factor_base_size": 4, "relations_needed": 14, "relations_found": 14, "x": 505, "y": 16, "congruence": "505² ≡ 16² (mod 84923)", "steps": 14, "message": "Found factor p = 163 via congruent squares 505² ≡ 16² (mod 84923)", "elapsed_us": 68 } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"n": 1042387, "b": 50}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/dixon
Carl Pomerance's 1981 Quadratic Sieve algorithm is the fastest general-purpose integer factorization algorithm for composites up to 100 decimal digits. It optimizes Dixon's random squares method by systematically replacing trial division with a polynomial sieve over an array
The algorithm operates in four stages:
-
Factor Base Construction: Forms
$F = {-1, 2} \cup {p \le B \mid (n/p) = 1}$ , filtering out primes for which$n$ is a quadratic non-residue. -
Tonelli–Shanks Sieve Initialization: For each odd prime
$p \in F$ , computes the two roots of$(x + \lfloor\sqrt{n}\rfloor)^2 \equiv n \pmod p$ via modular square root. -
Logarithmic Sieve: Initializes an array of size
$2M + 1$ with approximations of$\log_2 |Q(x)|$ . For each factor base prime$p$ , walks through arithmetic progressions$r + k p$ across the sieve interval, subtracting$\log_2 p$ . Array cells falling below threshold indicate candidate$B$ -smooth values of$Q(x)$ . -
Linear Algebra over
$\mathbb{F}_2$ : Forms the exponent parity matrix and extracts null-space vectors using Gaussian elimination over$\mathbb{F}_2$ . Combines smooth relations into congruent squares$X^2 \equiv Y^2 \pmod n$ to reveal non-trivial factors via$\gcd(|X - Y|, n)$ .
Parameters:
-
n(integer, required): composite integer to factor ($n \ge 4$ ). -
b(integer, optional, default: 60): smoothness bound$B$ ($10 \le B \le 5000$ ). -
m(integer, optional, default: 3000): sieve radius$M$ defining interval$[-M, M]$ (100 ≤ m ≤ 100,000). -
GET Request:
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/qs?n=84923&b=60&m=3000"Response:
{ "n": 84923, "factor": 163, "cofactor": 521, "success": true, "b": 60, "m": 3000, "factor_base_size": 8, "relations_needed": 18, "relations_found": 18, "x": 84625, "y": 20021, "congruence": "84625² ≡ 20021² (mod 84923)", "candidates_checked": 168, "message": "Found factor p = 163 via quadratic sieve congruence 84625² ≡ 20021² (mod 84923)", "elapsed_us": 1631 } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"n": 1042387, "b": 60, "m": 3000}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/qs
Daniel Shanks's 1975 Square Forms Factorization algorithm (SQUFOF) is an unconditionally deterministic msieve and PARI/GP) as the primary factoring workhorse for 64-bit cofactors before launching general sieves.
The algorithm executes in two cycles:
-
Cycle 1 (Square Form Search): Computes continued-fraction-like reductions of the principal form of discriminant
$D = k n$ . At even step indices, checks whether$Q_i$ is a perfect square$r^2$ . -
Cycle 2 (Ambiguous Form Inversion): Initializes an inverse form from the square root form
$(r, P, \dots)$ and marches through reduced forms until reaching an ambiguous form where$P_0 = P_1$ . The non-trivial factor is recovered as$\gcd(n, P_1)$ .
Parameters:
-
n(integer, required): composite integer to factor ($n \ge 4$ ). -
max_steps(integer, optional, default: 50000): maximum reduction steps allowed per multiplier (1 ≤ max_steps ≤ 500,000). -
GET Request:
curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/squfof?n=84923"Response:
{ "n": 84923, "factor": 163, "cofactor": 521, "success": true, "multiplier": 1, "cycle1_steps": 4, "cycle2_steps": 2, "square_q": 1156, "sqrt_q": 34, "message": "Found non-trivial factor p = 163 via SQUFOF (multiplier k = 1, cycle 1 = 4 steps, cycle 2 = 2 steps)", "elapsed_us": 25 } -
JSON POST Request:
curl -sS -H "Content-Type: application/json" \ -d '{"n": 1042387}' \ https://abhrankan.duckdns.org/crypto-api/v1/math/squfof
- Request bodies are limited to 64 KiB.
- Each textual input (
data,key, andmac) is limited to 32 KiB. -
200 OK: successful health, hash, generation, verification, or math calculation request. -
400 Bad Request: unsupported algorithm, malformed MAC, invalid query parameters, or mathematical domain error (e.g.,$p$ not an odd prime, quadratic non-residue in modular square roots, inconsistent CRT system, zero denominator, or negative scalar$k$ ). -
415 Unsupported Media Type: operation request does not useapplication/json. -
401 Unauthorized: missing or invalid Basic Auth at Nginx for protected operations. -
413 Payload Too Large: body or textual input exceeds its limit. -
404 Not Found: route does not exist.
With Rust and Cargo installed:
cargo test
cargo run
# Health & metadata
curl -sS http://127.0.0.1:8089/health
curl -sS http://127.0.0.1:8089/v1/info
# Cryptographic primitives (direct to local service; no Basic Auth required)
curl -sS -H 'content-type: application/json' \
-d '{"algorithm":"sha256","data":"hello"}' \
http://127.0.0.1:8089/v1/hash
# Number theory & elliptic curves (GET or POST)
curl -sS "http://127.0.0.1:8089/v1/math/sqrtmod?a=10&p=13"
curl -sS -H 'content-type: application/json' \
-d '{"curve":"toy193","k":7}' \
http://127.0.0.1:8089/v1/math/ecmulAuthentication (HTTP Basic Auth) is enforced exclusively upstream at Nginx for production deployments (/crypto-api/). When hitting 127.0.0.1:8089 directly during local development, no credentials are required.
The service is intentionally not a wallet, miner, exchange, payment processor, or key-management system. Do not send private keys or production secrets to it.
A representative location configuration from the production server (/etc/nginx/conf.d/abhrankan.conf) is:
location = /crypto-api/health {
proxy_pass http://127.0.0.1:8089/health;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
location = /crypto-api/v1/info {
proxy_pass http://127.0.0.1:8089/v1/info;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
# Optional: expose math endpoints publicly for educational tools / playgrounds
location /crypto-api/v1/math/ {
proxy_pass http://127.0.0.1:8089/v1/math/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
location /crypto-api/ {
auth_basic "crypto-lab";
auth_basic_user_file /etc/nginx/status.htpasswd;
proxy_pass http://127.0.0.1:8089/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}The exact health and info matches keep /crypto-api/health and /crypto-api/v1/info unauthenticated (as well as /crypto-api/v1/math/ if exposed publicly). The trailing slash on the authenticated location preserves the backend route shape: /crypto-api/v1/hash becomes /v1/hash.
Install crypto-lab.service as /etc/systemd/system/crypto-lab.service, then run:
sudo systemctl daemon-reload
sudo systemctl enable --now crypto-lab
sudo systemctl status crypto-lab --no-pagerThe unit binds the service to localhost and applies process, filesystem, and network hardening. Build the release binary with cargo build --release and install it at /usr/local/bin/crypto-lab.