Project

obfuskey

0.0
No release in over 3 years
A Ruby port of obfuskey that produces deterministic, reversible keys from integers using a custom alphabet. Cross-compatible with the Python, JavaScript, and Rust implementations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.0
~> 3.12
 Project Readme

obfuskey-rb

A Ruby port of Obfuskey. Generates deterministic, reversible, fixed-length keys from integer values using a custom alphabet. Cross-compatible with the Python, JavaScript, and Rust implementations — the same (alphabet, key_length, value) triple produces the same key in every language.

Install

# Gemfile
gem "obfuskey"

Usage

require "obfuskey"

obf = Obfuskey.new(Obfuskey::Alphabets::BASE62)
key = obf.get_key(12345)       # => "d2Aasl"
obf.get_value(key)             # => 12345

Custom key length or multiplier

Obfuskey.new(Obfuskey::Alphabets::BASE62, key_length: 8)
Obfuskey.new(Obfuskey::Alphabets::BASE62, multiplier: 123)   # odd integer

Obfusbit (bit-packed structured keys)

schema = [
  { name: "id",   bits: 10 },
  { name: "type", bits: 2  },
  { name: "flag", bits: 1  }
]

key_maker = Obfuskey.new(Obfuskey::Alphabets::BASE62, key_length: 3)
ob = Obfusbit.new(schema, obfuskey: key_maker)

encoded = ob.pack({ "id" => 100, "type" => 2, "flag" => 1 }, obfuscate: true)
ob.unpack(encoded, obfuscated: true)
# => { "id" => 100, "type" => 2, "flag" => 1 }

Alphabets

Obfuskey::Alphabets provides BASE16, BASE32, BASE36, BASE52, BASE56, BASE58, BASE62, BASE64, BASE94, CROCKFORD_BASE32, ZBASE32, BASE64_URL_SAFE.

Tests

bundle install
bundle exec rspec

License

MIT