Skip to content

Protonk/BIDDER

Repository files navigation

BIDDER

Numbers are weird and perfect uniformity is (almost uniformly) a trap. Do not use BIDDER to generate secrets.

Every generator is uniform. BIDDER is exact, algebraically. 20 keys, 9000 outputs each, digits 1-9. BIDDER produces exactly 1000 of each digit on every key (blue squares on the reference line). numpy produces approximately 1000 with up to 77 counts of deviation (yellow circles scattered above and below).

Arithmetic Congruence Monoids encoded as Champernowne reals, and the BIDDER block generator that falls out of them. Named for George Bidder's logarithms, which everyone seems to forget about.

What this is

For each positive integer n, the multiplicative monoid nZ+ has irreducible elements, which we call n-primes (numbers which would be prime were (n-1) factorization not available). Concatenating these into a decimal real produces a signal whose leading-digit distribution is exactly uniform — not approximately uniform, exactly uniform.

The first few n-primes for small n:

n first n-primes
2 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, …
3 3, 6, 12, 15, 21, 24, 30, 33, 39, 42, …
4 4, 8, 12, 20, 24, 28, 36, 40, 44, 52, …
5 5, 10, 15, 20, 30, 35, 40, 45, 55, 60, …
10 10, 20, 30, 40, 50, 60, 70, 80, 90, 110, …

Concatenating those digits as a sequence in order gives the Champernowne real C(n):

n C(n)
2 0.2610141822263034…
3 0.3612152124303339…
4 0.4812202428364044…
5 0.5101520303540455…
10 0.1020304050607080…

The mathematical definitions shown in this README and the core theory docs are written in BQN, used here as executable mathematical notation: dense enough to fit a construction on one line, unambiguous enough to actually run, and structurally close to the array-and-index style the math itself uses. The full vocabulary lives in guidance/BQN-AGENT.md. Reading BQN is not required to follow this README — the prose carries the meaning, the tables above show the result, and the block below is the precise form for anyone who wants to run it.

NPn2         ← {(0𝕨|·)/ 𝕨×1+↕𝕩×𝕨}       # n-primes for n >= 2
Digits10     ← {𝕩<10 ? ⟨𝕩⟩ ; (𝕊⌊𝕩÷10)10|𝕩⟩}
ChamDigits10 ← { Digits10¨ 𝕩}               # exact digit concatenation
LeadingInt10 ← { Digits10 𝕩}                # leading digit of an integer

ChamDigits10 (5 3 NPn2 5)   # ⟨3,6,1,2,1,5,2,1⟩ — digits of C(3)
LeadingInt10 3                # 3 — the leading digit of n is the
                              #     leading digit of C(n)

Quick examples

Python:

import bidder

list(bidder.sawtooth(n=3, count=10))
# [3, 6, 12, 15, 21, 24, 30, 33, 39, 42]

B = bidder.cipher(period=10, key=b'doc')
list(B)
# [0, 4, 8, 1, 7, 6, 9, 3, 2, 5]

Construction, generator, art

This repo is now best read in three passes: the exact construction, the keyed generator that sits on top of it, and the art that falls out when you give exact data enough room to move.

Construction

The construction is small but exact, and the consequences keep getting larger.

The Champernowne real C(n) plotted against n on a log scale. A sawtooth wave: each tooth spans one digit class, and the running mean (blue curve) converges to the exact value 31/20 = 1.55 (red dashed line). The wave is the exact uniformity; the convergence is the proof.

Leading base-b digits of an ACM-Champernowne real are uniform — not approximately, exactly — over every full digit block in base b. That exact count now supports a compact stable core:

Around that core sit the block sawtooth, the epsilon function that controls its phase, and the rolling-shutter relationship between addition and multiplication that the sawtooth makes visible.

The base-2 side is the active frontier. Bit-balance of an n-prime stream has a closed form that depends only on v_2(n). The Walsh-Hadamard spectrum carries 44 robust higher-order coefficients that all collapse under entry-order shuffle and that the v_2(n) story explains only a minority of. The current working conjecture is that no finite automaton can generate or recognize a binary ACM stream at all.

Generator

Not that kind of crypto. A block-structured randomization tool that mates smoothly with a small, well-understood block cipher.

Side-by-side anatomy of bidder.cipher (left, yellow) and bidder.sawtooth (right, blue). Four rows: output scatter, output histogram, first differences, and autocorrelation. The cipher path is flat, noisy, and uncorrelated — a keyed permutation. The sawtooth path is structured, deterministic, and strongly correlated — exact n-primes in order. Two paths, one interface, opposite guarantees.

BIDDER exists to keep two guarantees separable. An algebraic substrate — the ACM-Champernowne digit block [b^(d-1), b^d - 1] — gives exact leading-digit uniformity by a counting argument from positional notation: across the block there are exactly b^(d-1) integers with each leading digit, with no error term. A keyed permutation — Speck32/64 in cycle-walking mode for operating blocks well below 2^32, with a Feistel fallback when the cycle-walking ratio gets bad — provides the disorder. Neither piece is asked to do the other's job.

Proved:

  • The algebraic substrate is exact, not merely tested. The integer block lemma in core/BLOCK-UNIFORMITY.md is a counting argument from positional notation; there is no hidden block size where it stops working.
  • At N = period, the MC estimate equals the left-endpoint Riemann sum R for any key and any integrand. This is the structural permutation-invariance theorem in core/RIEMANN-SUM.md.
  • The root entry points are stable: BIDDER.md documents bidder.cipher(period, key) and bidder.sawtooth(n, count), with core/API.md as the detailed cipher-path reference.

Measured:

  • Full-period digit counts are exactly period / (b - 1) for every digit, every key, across the tested bases and digit classes.
  • All d digit positions of each permuted index are independently uniform, with pairwise joints exact on the tested ranges.
  • SHA-256 rekeying across period boundaries shows no detectable seam for d ≥ 3.
  • Stratified sampling at block boundaries is totalizing for smooth functions.
  • The theory front is now executable. Three red-team test files under tests/theory/ attack the structural, quadrature, and statistical layers independently. The organizing document is RED-TEAM-THEORY.md — it decomposes the total error E_N − I = (E_N − R) + (R − I) into four layers, names what would falsify each claim, and tracks the measured coupling gap between the cipher backend and the ideal without-replacement null.

Not claimed:

  • The PRP properties anyone would want for adversarial use — distinguishing advantage in this exact composition, key independence beyond the structural E_P = R result, side-channel behavior, robustness under chosen input — are inherited from Speck and have not been independently verified for BIDDER.

  • The Feistel fallback at small block sizes shows a measurable variance gap at intermediate N: the random.shuffle null matches the finite-population correction formula, but the Feistel-keyed permutations run roughly 1.5× to 2.5× worse. This is a backend property, not an algebra failure.

  • The warning at the top of this file is literal: BIDDER is not a secret-generation tool.

  • BIDDER.md — root API reference: bidder.cipher and bidder.sawtooth in three layers (natural language, Python, BQN)

  • core/API.md — detailed cipher-path reference

  • core/RIEMANN-SUM.md — the permutation-invariance theorem and finite-population correction

  • generator/BIDDER.md — cipher design doc, observed properties, known limitations, open questions

  • coupler.py / bidder.c — alphabet-pinned Python and C implementations, byte-identical output

  • bidder.py / bidder_root.c — root entry points in Python and C; same two-path surface, with one explicit range limit on the C side: sawtooth values that exceed uint64_t report overflow instead of returning Python-style bignums

  • speck.py — full Speck family reference (all 10 variants, all Appendix C vectors)

  • experiments/bidder/unified/ — dither, period anatomy, MC diagnostics, Riemann proof, adversarial integrands

  • experiments/bidder/stratified/ — the totalizing demonstration

  • experiments/bidder/reseed/ — the rekeying experiment

Art

Uniform numbers, given too much room, make a star.

Binary run lengths of n-prime streams plotted on polar axes. Short runs dominate exponentially, collapsing the plot toward the center and producing concentric rings of light. The result looks like a sun — bright core, banded corona, radial spikes at long rare runs. An instructive failure: the visualization was meant to show structure in the runs, but the structure of the structure made a star instead.

Art folders coordinate experiments on exact data. The next time someone says some of science is an art you should take it seriously. The below are a random set of examples.

  • corona_attempt.png — the sun above. An instructive failure: binary run lengths on polar axes collapse toward the center because short runs dominate exponentially. The "sun" is a failure mode caused by structure of structure.
  • dense_bloom.png — decimal block structure rendered as a bloom.
  • escalating_bidder_mul.png — 1, then 5, then 10 multiplications in a sea of additions. Each burst deepens the Benford scar. The additive staircase is the Champernowne sawtooth; the multiplicative kick is ε doing its work.
  • art_groove.png — four Benford demos rendered as vinyl records. Groove eccentricity is mantissa non-uniformity; a perfect circle is Benford equilibrium. The BS(1,2) walk's record has one bright scratch (the initial delta) and then a machined surface.
  • butterfly.png — a keyed permutation of 20,000 integers, rotated 45 degrees and cropped to an oval. Colored by output mod 9 on a CMB scale. The density variations are the Feistel round function's fingerprint, almost but not quite uniform.

Building

Python core tests (requires sage for numpy):

sage -python tests/test_acm_core.py
sage -python tests/test_sawtooth.py

Python generator and cipher tests (plain python3):

python3 tests/test_bidder.py
python3 tests/test_speck.py
python3 tests/test_bidder_block.py
python3 tests/test_api.py
python3 tests/test_bidder_root.py

Theory red-team tests (plain python3):

python3 tests/theory/test_riemann_property.py
python3 tests/theory/test_quadrature_rates.py
python3 tests/theory/test_fpc_shape.py

Doc verifier (plain python3):

python3 core/api_doc_examples.py

C:

gcc -O2 -o test_acm_core_c tests/test_acm_core_c.c core/acm_core.c -lm
./test_acm_core_c

gcc -O2 -o test_bidder_c tests/test_bidder_c.c generator/bidder.c -lm
./test_bidder_c

gcc -O2 -o test_bidder_root_c tests/test_bidder_root_c.c bidder_root.c generator/bidder.c core/acm_core.c -lm
./test_bidder_root_c

About

Algebraically Uniform Number Generator

Topics

Resources

Stars

Watchers

Forks

Contributors