Skip to content

Instantly share code, notes, and snippets.

@opsec-ee
Created January 20, 2026 02:56
Show Gist options
  • Select an option

  • Save opsec-ee/04d7d14fbdb03d61ef067f518eeee30c to your computer and use it in GitHub Desktop.

Select an option

Save opsec-ee/04d7d14fbdb03d61ef067f518eeee30c to your computer and use it in GitHub Desktop.
bijective_maths
do {
value = feistel_encrypt(value);
} while (value >= N);
```
### 4. Proof: Cycle-Walking Preserves Bijection
**Theorem:** f: S → S is a bijection.
**Proof:**
**(a) Well-defined:** For any x ∈ S, the cycle containing x has finite length. Since x ∈ S ⊂ T and the cycle returns to x, it must pass through S at least once more. Therefore m exists.
**(b) Injective:** Suppose f(x) = f(y) for x, y ∈ S.
Let f(x) = πᵐ(x) and f(y) = πⁿ(y).
**Case m = n:** Then πᵐ(x) = πᵐ(y), so x = y (πᵐ is bijective).
**Case m ≠ n (WLOG m < n):**
- πᵐ(x) = πⁿ(y)
- x = πⁿ⁻ᵐ(y)
- The path y → π(y) → ... → πⁿ⁻ᵐ(y) = x
- But x ∈ S and n-m < n
- This contradicts minimality of n
Therefore x = y. ∎
**(c) Surjective:** For any z ∈ S, walk backwards:
```
z ← π⁻¹(z) ← π⁻²(z) ← ...
```
The first element in S along this reverse path maps to z under f. ∎
### 5. Expected Iterations
**Lemma:** Expected cycle-walk iterations = |T|/|S| = 2³⁶/62⁶ ≈ 1.21
**Proof:** Each encryption step has probability |S|/|T| of landing in S.
Geometric distribution: E[iterations] = |T|/|S| = 68,719,476,736 / 56,800,235,584 ≈ 1.21
**Worst case** is bounded by cycle length, which is at most |T|. In practice, ≤3 iterations covers 99.9%+ of cases.
### 6. Visual Representation
```
Working Space T = [0, 2³⁶)
┌─────────────────────────────────────────────────────┐
│ │
│ Target Space S = [0, 62⁶) │
│ ┌─────────────────────────────────┐ │
│ │ x ──π──▶ ○ ──π──▶ ○ ──π──▶ y │ ← y ∈ S │
│ │ │ │ │ │
│ │ ▼ (out) ▼ (out) │ │
│ └──────────│─────────│────────────┘ │
│ ○ ○ ← points ∈ T\S │
│ │ │ │
│ └────π────┘ │
│ │
└─────────────────────────────────────────────────────┘
Cycle-walk: Keep following π until landing in S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment