obfuskey.
Integer obfuscation · Python · TS · Rust · Ruby

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.

Install

Add it to your project.

$ npm install obfuskey
github.com/bnlucas/obfuskey-js
Playground

Encode an integer.

Tweak the alphabet, key length, and multiplier. The code tabs regenerate in every language as you edit.

Max value218340105584895
REtCHqs2
CodeCross-language
import { Obfuskey, BASE62_ALPHABET } from 'obfuskey';

const obf = new Obfuskey(BASE62_ALPHABET, 8);

const key = obf.getKey(1234567890n);
const value = obf.getValue(key);
Bit-packing

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.

Total bits: 27Min key length: 5
Schema
Packed integer
42930689
Obfuscated key
TmWvz
Unpacked
category_id: 5
item_id: 123456
status: 1
CodeCross-language
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);
What it is

Encoding, not hashing.

Reversible

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.

Uniform length

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.

Cross-language

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.

Bit-packed IDs

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.

Reference

Built-in alphabets.

Or pass your own string — any unique-character set becomes a valid alphabet.

AlphabetBaseCharacters
  • BASE16
    Hex.
    16
    0123456789ABCDEF
  • BASE32
    32
    234567ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • BASE36
    Digits + uppercase.
    36
    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • BASE52
    Consonants only.
    52
    0123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz
  • BASE56
    No ambiguous chars.
    56
    23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz
  • BASE58
    Bitcoin-style.
    58
    123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
  • BASE62
    Digits + alpha.
    62
    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  • BASE64
    64
    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/
  • BASE64_URL_SAFE
    URL-safe.
    64
    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_
  • BASE94
    All printable ASCII.
    94
    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  • CROCKFORD_BASE32
    Crockford.
    32
    0123456789ABCDEFGHJKMNPQRSTVWXYZ
  • ZBASE32
    z-base32.
    32
    ybndrfg8ejkmcpqxot1uwisza345h769