website

Abhrankan Chakrabarti

The Chamber of Primes

Fermat's Difference of Squares & The Sieve of Ma'at

𓁨 𓆐 π“‚­ 𓆼 𓍒 π“Ž† 𓏺
Connecting to WebSocket...
Pharaoh Presets & Cryptographic Demonstrations
60 ms
𓁨 Factorization Revealed in the Chamber 𓁨
Modulus n (Decimal)
5,959
Egyptian Hieroglyphic Numerals
𓆼𓆼𓆼𓆼𓆼 𓍒𓍒𓍒𓍒𓍒𓍒𓍒𓍒𓍒 π“Ž†π“Ž†π“Ž†π“Ž†π“Ž† 𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺𓏺
Outer Side x
78
Remainder r = x² - n
125
Inner Void Root y = √r
β€”
Outer square represents x². The carved void represents y² = x² - n. When y² is an exact square, the remaining L-tromino (gnomon) area equals n!

Live Chamber Telemetry

Attempt Step
0
Square x²
6,084
Legendre Sieve Filter
Ready
Exact Square Check
Ready

Difference of Squares Theorem: Every odd composite integer satisfies n = x² - y² = (x - y)(x + y).

Starting at x = ⌈√n⌉, each attempt increments x → x + 1 and tests whether r is a perfect square. The Sieve of Ma'at eliminates >99.999% of non-squares using Legendre table lookups before any square root is computed.

The Sieve of Ma'at (Legendre Symbol Residue Filter) 20 Small Primes (3 … 73)
If r mod p has Legendre symbol (r/p) = -1, r cannot be a square. The sieve rejects it instantly in O(1) time.

Fermat's Difference of Squares Factorization

In 1643, Pierre de Fermat discovered that every odd composite number n can be factored by finding two integers x and y such that:

n = x² - y² = (x - y)(x + y) = p × q

The algorithm sets the initial candidate to the ceiling of the square root, x = ⌈√n⌉, and computes the remainder:

r = x² - n

If r is a perfect square, say r = y², we have found the factors p = x - y and q = x + y. If not, x is incremented by 1. Because:

(x + 1)² - n = (x² - n) + (2x + 1)

The remainder can be updated using only additions: r += 2x + 1, completely eliminating expensive multiplications from the inner loop.

The Sieve of Ma'at: Legendre Symbol Quadratic Residue Filter

Testing whether an integer is an exact square using square roots is computationally costly. However, a square y² must be a quadratic residue modulo every prime p.

For any prime p, the Legendre symbol (a/p) indicates whether a is a quadratic residue modulo p:

By checking r against precomputed Legendre lookup tables for 20 small primes (3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73), more than 99.999% of non-squares are rejected in a fraction of a microsecond before any square root is attempted!

The RSA Vulnerability: Why Primes Must Not Be Close

In textbook RSA key generation, the modulus is n = p × q. If the primes p and q are chosen too close to each other, Fermat's difference of squares factorization cracks the private key almost instantly!

When |p - q| is small:

x = (p + q) / 2 ≈ √n

The initial candidate x = ⌈√n⌉ is already adjacent to the true factor midpoint. In the Ramses II preset above, a 34-bit RSA modulus (n = 10,969,629,527 = 104,723 × 104,749) is factored in step 1! This visually demonstrates why cryptographic standards (FIPS 186-4, RFC 8017) strictly require |p - q| > 2nlen/2 - 100.

Ancient Egyptian Hieroglyphic Numerals

Ancient Egyptians used a base-10 additive numeral system represented in stone carvings across temples, tombs, and papyri (such as the Rhind and Moscow Mathematical Papyri). Numbers were written by repeating glyphs for each power of 10:

Value Glyph Egyptian Name / Symbol Description
1 𓏺 Single vertical stroke A single tally mark carved in stone
10 π“Ž† Hobble / Heel bone (medj) An arch of woven cattle hobble
100 𓍒 Coil of rope (shet) A coil of measuring surveyor rope
1,000 𓆼 Lotus plant (khaa) A water lily blooming in the Nile
10,000 π“‚­ Pointing finger (djeba) A bent finger pointing upwards
100,000 𓆐 Tadpole / Frog (hefen) A fertile tadpole in the Nile mud
1,000,000 𓁨 God Heh (heh) The god Heh kneeling with upraised arms supporting eternity
Read the Chamber of Primes Article → Read Full Implementation Report →