# Base64 Ascend (b64a)

Base64 Ascend, or b64a, is an order-preserving Base64 variant.

Alphabet:

`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~`

Canonical form omits `=` padding and zero-fills trailing bits.

## Alphabet Mapping

- `0..9`   -> `'0'..'9'`
- `10..35` -> `'A'..'Z'`
- `36`     -> `'_'`
- `37..62` -> `'a'..'z'`
- `63`     -> `'~'`

`~` keeps the alphabet ASCII-sorted and path-safe.

## Encoding Rules

- Pack bits like RFC 4648 Base64 (MSB-first 6-bit groups).
- Do not emit `=`.
- Zero-fill the final partial 6-bit group.
- Output length is `ceil(8*N/6)` for `N` input bytes.

## Decoding and Validation

- Reject bytes outside the b64a alphabet.
- Decode first, then validate tail bits:
  - `len % 4 == 2`: low 4 bits must be zero
  - `len % 4 == 3`: low 2 bits must be zero
- Implementations should validate by decoding, not by regex.

## Ordering Guarantees

- Equal-length strings compare exactly like decoded bytes.
- If one canonical string is a strict prefix of another, the shorter string
  sorts first.

## Conformance

- MUST emit and accept only the b64a alphabet above.
- MUST forbid `=` padding.
- MUST zero-fill trailing bits and reject non-zero filler bits.
- SHOULD validate by decoding plus explicit tail checks.

## Test Vectors

| Hex      | b64a | Notes             |
|----------|------|-------------------|
| (empty)  |      | empty input       |
| `00`     | `00` | 1 byte            |
| `0000`   | `000`| 2 bytes           |
| `000000` | `0000` | 3 bytes         |
| `FF`     | `~l` | tail 4 bits zero  |
| `FF00`   | `~l0`| tail 2 bits zero  |
| `000102` | `0012`| exact 3 bytes    |

Reject examples: `01`, `001`, `~m`, `~l1`, `=`, `+`, `/`.
