website

Abhrankan Chakrabarti

The Chamber of Primes: Fermat Factorization & Sieve of Ma'at

Releases: crypto-lab v0.8.0 & website v0.10.0
Status: All 45 tests passing, zero Clippy/formatting warnings, pushed to GitHub and deployed to production.


1. Overview & Conceptual Connection

The Chamber of Primes brings Pierre de Fermat's 1643 Difference of Squares factorization algorithm to life through a real-time, bidirectional WebSocket streaming visualizer wrapped in an Ancient Egyptian temple aesthetic.

By pairing the high-performance number-theoretic primitives of diffsquare with the async Axum backend in crypto-lab and the static showcase in website, the visualizer demonstrates:

  1. Geometric Factorization (n = x² − y² = (x − y)(x + y)): Real-time canvas rendering of the outer stone square (x × x) and carved void (y × y) until the remaining gnomon area matches n.
  2. The Sieve of Ma'at: A 20-prime Legendre symbol quadratic residue filter (p ∈ [3, 73]) eliminating >99.999% of non-squares in O(1) table lookups.
  3. The RSA Close Primes Vulnerability: Visual proof of why RSA prime selection requires distant factors (e.g. Ramses II factoring an RSA-style modulus in step 1).
  4. Ancient Egyptian Hieroglyphic Numerals: Authentic base-10 additive numeral conversion rendered using Unicode Block U+13000 (๐“จ ๐“† ๐“‚ญ ๐“†ผ ๐“ข ๐“ކ ๐“บ).

Visualizer Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Browser Client (chamber.html)             โ”‚
โ”‚   Canvas Gnomon ยท Sieve Rune Grid ยท Cartouche Displays โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚ โ–ฒ Bidirectional WebSocket
                           โ”‚ โ”‚ (/v1/math/chamber/ws)
                           โ–ผ โ”‚ (Automatic REST Fallback)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 crypto-lab (Axum 0.7)                  โ”‚
โ”‚                      src/fermat.rs                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚                               โ”‚
           โ–ผ                               โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Legendre Sieve Engine โ”‚      โ”‚   Exact Integer Sqrt   โ”‚
โ”‚  (20 Primes: 3 โ€ฆ 73)   โ”‚      โ”‚    & Fermat Stepper    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2. Backend Implementation (crypto-lab v0.8.0)

Core Fermat Engine (src/fermat.rs)

API Routes & Endpoints


3. Frontend Showcase (website v0.10.0)

Components Created & Updated

  1. chamber.html: Dedicated showcase page featuring:
    • Basalt tomb and Egyptian gold card styling (#090c10, #d4af37, #ffd700).
    • Pharaoh presets:
      • Tutankhamun (n = 5959 = 59 × 101, factors in 3 steps)
      • Cleopatra (n = 8051 = 83 × 97, factors in 8 steps)
      • Ramses II (n = 10,969,629,527 = 104,723 × 104,749, factors in step 1 — RSA vulnerability demo)
      • Nefertiti (n = 1,000,000,007, prime modulus search)
      • Custom input for any odd integer n ≥ 3.
    • Play/Pause, Step-by-Step, Delay slider (10ms to 400ms), and Reset.
    • Live stone tablet cartouches for n, x, r, and y.
    • Victory banner revealing n = p × q = (x − y)(x + y).
  2. assets/chamber.css: Responsive Egyptian styling, glowing sieve rune tiles, stone cartouche borders, and dark ambient atmosphere.
  3. assets/chamber.js:
    • Dual-mode streaming: Connects to WebSocket on wss:// with automated fallback to the REST simulation engine.
    • Hieroglyphic Numeral Encoder: Translates any decimal or BigInt value into Egyptian Unicode glyphs (๐“จ ๐“† ๐“‚ญ ๐“†ผ ๐“ข ๐“ކ ๐“บ).
    • HTML5 Canvas: Draws outer square x × x, carved void y × y, measurement lines, and the L-tromino (gnomon).
    • Sieve Grid: 20 glowing rune tiles showing live residue and rejection states.
  4. Site Integration: Updated lab.html with a featured visualizer banner, added project cards to projects.html, and added navbar links across all pages (index.html, writing.html, now.html, API.html, RELEASES.html).
  5. Documentation & Changelogs: Updated API.md, API.html, RELEASES.md, and RELEASES.html.

4. Egyptian Hieroglyphic Numeral System

Value Unicode Glyph Ancient Name Significance
1 U+133FA ๐“บ Single stroke A simple tally mark carved into stone
10 U+13386 ๐“ކ Cattle hobble (medj) An arch of woven cattle tether rope
100 U+13362 ๐“ข Coil of rope (shet) A coil of surveyor measuring rope
1,000 U+131BC ๐“†ผ Water lily (khaa) A sacred lotus blooming in the Nile
10,000 U+130AD ๐“‚ญ Pointing finger (djeba) A bent finger pointing toward the heavens
100,000 U+13190 ๐“† Tadpole (hefen) A fertile frog emerging from Nile silt
1,000,000 U+13068 ๐“จ God Heh (heh) Kneeling deity with upraised arms supporting eternity

5. Deployment Guide (EC2 Server)

On your EC2 server (ec2-user@ip-172-31-77-184), run the following commands in fish shell:

Step 1: Update & Rebuild crypto-lab

cd ~/rust/crypto-lab
git pull
cargo build --release
sudo install -m 755 target/release/crypto-lab /usr/local/bin/crypto-lab
sudo systemctl restart crypto-lab

Step 2: Deploy Updated Website

~/deploy.sh

In /etc/nginx/conf.d/abhrankan.conf, ensure the math proxy block forwards WebSocket upgrade headers:

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;
}

(Note: If Nginx is not yet updated for WebSockets, assets/chamber.js automatically falls back to the REST simulation engine, ensuring 100% immediate availability.)


6. Verification & Test Commands

1. Test REST Factorization Endpoint

curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/fermat?n=5959" | jq .

Expected output:

{
  "ok": true,
  "n": 5959,
  "initial_x": 78,
  "steps_count": 3,
  "found": true,
  "p": 59,
  "q": 101,
  "x": 80,
  "y": 21,
  "reason": "found"
}

2. Test 34-bit RSA Modulus Factorization (Ramses II)

curl -sS "https://abhrankan.duckdns.org/crypto-api/v1/math/fermat?n=10969629527" | jq .

Expected output:

{
  "ok": true,
  "n": 10969629527,
  "initial_x": 104736,
  "steps_count": 2,
  "found": true,
  "p": 104723,
  "q": 104749,
  "x": 104736,
  "y": 13,
  "reason": "found"
}

3. Test Metadata Endpoint

curl -sS https://abhrankan.duckdns.org/crypto-api/v1/info | jq '{version: .version, count: (.endpoints | length)}'

Expected output:

{
  "version": "0.8.0",
  "count": 56
}