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
integer_32bit()
View Source
integer_32bit() :: 1..4_294_967_295
integer_32bit() :: 1..4_294_967_295
Link to this section Functions
decode(cryptogram, secret)
View Source
decode(integer_32bit(), OptimusId.Secret.t()) :: integer_32bit()
decode(integer_32bit(), OptimusId.Secret.t()) :: integer_32bit()
Decodes given cryptogram value using provided OptimusId.Secret tuple.
Examples
iex> OptimusId.decode(2963487184, {2078493839, 1968460399, 2327522479})
17
encode(message, secret)
View Source
encode(integer_32bit(), OptimusId.Secret.t()) :: integer_32bit()
encode(integer_32bit(), OptimusId.Secret.t()) :: integer_32bit()
Encodes given message value using provided OptimusId.Secret tuple.
Examples
iex> OptimusId.encode(17, {2078493839, 1968460399, 2327522479})
2963487184