Module: NdrSupport::Obfuscator

Extended by:
Obfuscator
Included in:
Obfuscator
Defined in:
lib/ndr_support/obfuscator.rb

Overview

Contains logic for consistently obfuscating names and addresses using a simple substitution cipher.

Instance Method Summary collapse

Instance Method Details

#obfuscate(name, seed = nil) ⇒ Object

Obfuscate a name or address, either with the given seed, or default seed



13
14
15
16
17
18
19
20
21
22
# File 'lib/ndr_support/obfuscator.rb', line 13

def obfuscate(name, seed = nil)
  rnd = Random.new(seed || @seed)
  vowels = %w(A E I O U)
  consonants = ('A'..'Z').to_a - vowels
  digits = ('0'..'9').to_a
  dict = Hash[(vowels + consonants + digits).zip(vowels.shuffle(random: rnd) +
                                                 consonants.shuffle(random: rnd) +
                                                 digits.shuffle(random: rnd))]
  name.upcase.split(//).map { |s| dict[s] || s }.join
end

#setup(seed) ⇒ Object

Set default obfuscation seed



8
9
10
# File 'lib/ndr_support/obfuscator.rb', line 8

def setup(seed)
  @seed = seed
end