bisani

Obfuscating IDs made simple with modular multiplicative inverse

( ͡° ͜ʖ├┬┴┬ Bisani

Crystal implementation of Go's Hide

Role

Bisani's role is to hide the actual id from a database, using Modular Multiplicative Inverse.

Installation

Add this to your application's shard.yml:

dependencies:
  bisani:
    github: kuende/bisani

Usage

require "bisani"

To obfuscate (hide) a certain value you simply need to do this:

##
# Random Int32 number.
# Works for Int32, Int64, UInt32, UInt64
# EXPLICIT CONVERSION MUST BE MADE!
##
x = 3_i32

# Bisani Magic
x = x.to_bis
# x will now be 206383517

To deobfuscate (revert/unhide) the value to the one it used to be:

# Let's asume x's value is 206383517
x = Bisani.to_i32(x)
# x will now be 3

That's it. Pretty simple, huh?

Custom primes

This library comes with custom primes set in Bisani::Values class. You should replace them with your own primes. Using the default ones is a serious security vulnerability and will yield this library useless for you.

Bisani.set_i32_prime(1234567.to_i32)
Bisani.set_i64_prime(1234567.to_i64)

Bisani.set_u32_prime(1234567.to_u32)
Bisani.set_u64_prime(1234567.to_u64)

Notes

It currently works only on

Int32
Int64
UInt32
UInt64

therefore, explicit conversion must be made:

my_int_var.to_i32
my_int_var.to_i64
my_int_var.to_u32
my_int_var.to_u64

TODO

Contributing

  1. Fork it ( https://github.com/kuende/bisani/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

bisani

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 1
  • over 8 years ago
  • April 27, 2016
License

Other

Links
Synced at

Sat, 21 Dec 2024 13:03:20 GMT

Languages