OptimusId v0.1.0 OptimusId View Source

Obfuscates 32-bit numbers.

Transform your internal ids to obfuscated integers. Similar to Hashids, although around 1000x faster (see the priv/benchmark/benchmark.exs).

Elixir implementation is compatible with PHP implementation.

Usage

In order to encode/decode anything, you'll first have to fetch yourself the OptimusId.Secret tuple. That's the mystic 2nd argument to encode/2 and decode/2 that you'll see in the examples below.

Now, let's start by encoding:

iex> OptimusId.encode(17, {2078493839, 1968460399, 2327522479})
2963487184

Our internal identifier (17) was transformed into obfuscated identifier (2963487184) which is safe to be made public.

In order to recover original identifier we have to call decode function:

iex> OptimusId.decode(2963487184, {2078493839, 1968460399, 2327522479})
17

Link to this section Summary

Functions

Decodes given cryptogram value using provided OptimusId.Secret tuple.

Encodes given message value using provided OptimusId.Secret tuple.

Link to this section Types

Link to this type

integer_32bit() View Source
integer_32bit() :: 1..4_294_967_295

Link to this section Functions

Decodes given cryptogram value using provided OptimusId.Secret tuple.

Examples

iex> OptimusId.decode(2963487184, {2078493839, 1968460399, 2327522479})
17

Encodes given message value using provided OptimusId.Secret tuple.

Examples

iex> OptimusId.encode(17, {2078493839, 1968460399, 2327522479})
2963487184