base256
Dense byte-to-unicode encoding. 32 bytes → 32 characters.
// Before: Debug output for [u8; 32]
// After: base256 encoding
_Гî┤gÅωυ3î·ж┤;ÏÌЦXXλÎ2M÷·
Install
Library:
CLI:
Use
Library:
use Base256;
// Basic encoding/decoding
let key = ;
let encoded = encode; // !#%&()*+,-./0123456789:;<=>?@AB
let decoded = decode.unwrap;
// Hex conversions (new in 0.3.0)
let hex_bytes = to_hex.unwrap; // [48, 48, 48, ...] (64 bytes)
let from_hex = from_hex.unwrap; // back to base256
// Direct byte-hex conversions
let hex = bytes_to_hex; // "0000...0000" as bytes
let bytes = hex_to_bytes.unwrap;
CLI:
# Encode stdin to base256 (default)
|
# Decode base256 to raw bytes
| |
# Encode to hex (new in 0.3.0)
|
# Convert hex to base256
|
# Convert base256 to hex
|
# Convert hex to raw bytes
|
# SSH public key to base256
| | |
# SSH public key to hex
| | |
What's New in 0.3.0
- Hex support: Convert between base256 and hex formats
- Flexible CLI: Combined flags like
-dxfor base256→hex conversion - Direct conversions:
bytes_to_hex()andhex_to_bytes()skip base256 entirely - Universal interop: Use hex when interfacing with tools that don't support base256
Design
- 256 unique unicode characters for 256 byte values
- No expansion: 32 bytes → 32 characters (base64: 32 → 44, hex: 32 → 64)
- Shell-safe: no quotes, backslashes, or dollar signs
- No-std, no dependencies, no allocations
Character set:
- ASCII printables (89) - excluding shell metacharacters
- Latin-1 supplement (95)
- Greek letters (48) - visually distinct from Latin
- Cyrillic/Box drawing (24)
When to use
Use base256 for:
- Ed25519/Curve25519 public keys as human-visible identifiers
- SHA-256 hashes in logs or terminal output
- P2P network node identifiers
- Any 32-byte value where visual length matters
Use hex for:
- Interoperability with existing tools
- Copy-paste in environments with poor Unicode support
- Debugging and development
Don't use for:
- Variable-length data
- Binary formats requiring specific encoding standards
- Non-unicode environments
Examples
# Generate a keypair identifier
| \
| \
| \
# Compare encodings of the same key
KEY=
| | |
# Quick conversion between formats
| |
License
MIT OR Apache-2.0