Module: EzChaff

Defined in:
lib/ez_chaff.rb

Class Method Summary collapse

Class Method Details

.chaff(string) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/ez_chaff.rb', line 18

def self.chaff(string)
  how_much_chaff = string.length
  chaff = EzChaff.randomize_full_ascii(how_much_chaff)
  chaffed_string = ''
  string.length.times do |pos|
    chaffed_string << "#{string[pos,1]}#{chaff[pos,1]}"
  end
  return chaffed_string
end

.randomize_full_ascii(length = 10) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ez_chaff.rb', line 3

def self.randomize_full_ascii(length = 10)
  unless defined?(EzChaff::RANDOM_STRING_SEED)
    chars = Array.new(126 - 32 + 1,nil)
    32.upto(126) do |char|
      chars[char - 32] = char.chr
    end
    EzChaff.const_set('RANDOM_STRING_SEED',chars)
  end
  chars = EzChaff::RANDOM_STRING_SEED
  new_string = ""
  rand_limit = EzChaff::RANDOM_STRING_SEED.size - 1
  1.upto(length) { |i| new_string << chars[rand(rand_limit)] }
  return new_string
end

.unchaff(string) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/ez_chaff.rb', line 28

def self.unchaff(string)
  unchaffed_string = ''
  chaff = false
  string.length.times do |pos|
    unchaffed_string << string[pos,1] unless chaff
    chaff = ! chaff
  end
  return unchaffed_string
end