Module: ScatterSwap

Defined in:
lib/scatter_swap.rb,
lib/scatter_swap/hasher.rb,
lib/scatter_swap/version.rb

Defined Under Namespace

Classes: Hasher

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.hash(plain_integer, spin = 0, length = 10) ⇒ String

Note:

To obtain the corresponding hashed integer value call hash(plain_integer).to_i

Hash the given plain_integer into its obfuscated String form.

Parameters:

  • plain_integer (Fixnum)

    the numeric value to be hashed.

  • spin (Fixnum) (defaults to: 0)

    the seed value for the hashing algorithm.

  • length (Fixnum) (defaults to: 10)

    the number of digits in the returned hash.

Returns:

  • (String)

    a ‘0’ padded string of length digits containing the hashed numeric value.



14
15
16
# File 'lib/scatter_swap.rb', line 14

def self.hash(plain_integer, spin = 0, length = 10)
  Hasher.new(plain_integer, spin, length).hash
end

.reverse_hash(hashed_integer, spin = 0, length = 10) ⇒ String

Note:

To obtain the corresponding reverse-hashed integer value call reverse_hash(hashed_integer).to_i

Reverse hashed_integer from its obfuscated form to its serial value.

Parameters:

  • hashed_integer (Fixnum)

    the numeric value to be hashed.

  • spin (Fixnum) (defaults to: 0)

    the seed value for the hashing algorithm.

  • length (Fixnum) (defaults to: 10)

    the number of digits in the returned hash.

Returns:

  • (String)

    a ‘0’ padded string of length digits containing the reverse-hashed numeric value.



27
28
29
# File 'lib/scatter_swap.rb', line 27

def self.reverse_hash(hashed_integer, spin = 0, length = 10)
  Hasher.new(hashed_integer, spin, length).reverse_hash
end