Integers in,
short keys out.
A tiny, reversible encoder for turning integers into fixed-length keys — and back. Same output in Python, TypeScript, Rust, and Ruby.
Add it to your project.
Encode an integer.
Tweak the alphabet, key length, and multiplier. The code tabs regenerate in every language as you edit.
import { Obfuskey, BASE62_ALPHABET } from 'obfuskey';
const obf = new Obfuskey(BASE62_ALPHABET, 8);
const key = obf.getKey(1234567890n);
const value = obf.getValue(key);Pack multiple fields.
Describe a schema of named integer fields. Obfusbit packs them into a single big integer, then runs it through Obfuskey for a compact string.
import { Obfuskey, Obfusbit, BASE58_ALPHABET } from 'obfuskey';
const schema = [
{ name: 'category_id', bits: 4n },
{ name: 'item_id', bits: 20n },
{ name: 'status', bits: 3n },
];
const obf = new Obfuskey(BASE58_ALPHABET, 5);
const packer = new Obfusbit(schema, obf);
const values = {
category_id: 5n,
item_id: 123456n,
status: 1n,
};
const key = packer.pack(values, true) as string;
const unpacked = packer.unpack(key, true);Encoding, not hashing.
It's encoding, not hashing.
Every key round-trips back to its original integer. Pure arithmetic — no lookup tables, no secret state beyond the multiplier.
Every key is the same width.
Pick an alphabet and a length; every value from 0 to the max produces a key of exactly that many characters. No leading-zero weirdness.
Same bytes in Python, TS, Rust, and Ruby.
A key encoded in one language decodes cleanly in the other three, given the same alphabet, length, and multiplier.
Pack multiple fields into one key.
Obfusbit lets you describe a schema of named integer fields and pack them into a single short, obfuscated string.
Built-in alphabets.
Or pass your own string — any unique-character set becomes a valid alphabet.
- BASE16Hex.160123456789ABCDEF
- BASE3232234567ABCDEFGHIJKLMNOPQRSTUVWXYZ
- BASE36Digits + uppercase.360123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
- BASE52Consonants only.520123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz
- BASE56No ambiguous chars.5623456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz
- BASE58Bitcoin-style.58123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
- BASE62Digits + alpha.620123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
- BASE64640123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/
- BASE64_URL_SAFEURL-safe.640123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_
- BASE94All printable ASCII.94!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
- CROCKFORD_BASE32Crockford.320123456789ABCDEFGHJKMNPQRSTVWXYZ
- ZBASE32z-base32.32ybndrfg8ejkmcpqxot1uwisza345h769