Class: Fuzzer

Inherits:
Object
  • Object
show all
Defined in:
lib/vcseif/utils/fuzzer.rb

Overview

Thanks to Erika for the idea about adding some text at the beginning of the encoded password This clues people in that the password is encoded and also makes sure that the encoding decoding will never fail. Without the extra text, “It will fail if a password has the same number of SEPARATORs as characters”

Constant Summary collapse

SEPARATOR =
"-"
ENCODED =
"encoded" + SEPARATOR

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/vcseif/utils/fuzzer.rb', line 33

def self.decode(string)
  return string if string.class.name != 'String'
  return string if string.empty?
  if self.is_encoded?(string)
    decoded = self.remove_every_second_char(string.slice(ENCODED.length,string.length))
    return Base64.decode64(decoded)
  else
    return string
  end
end

.defuzz(string) ⇒ Object



44
45
46
47
# File 'lib/vcseif/utils/fuzzer.rb', line 44

def self.defuzz(string)
  #would have been nice to be able to do alias_method :defuzz, :decode
  return self.decode(string)
end

.encode(string) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vcseif/utils/fuzzer.rb', line 15

def self.encode(string)
  return string if string.class.name != 'String'
  return string if string.empty?
  encoded = ""
  Base64.encode64(string).each_byte { |b|
    if ( b != 10 ) # \n
      encoded = encoded + b.chr + SEPARATOR
    end 
  }
  return ENCODED + encoded
end

.fuzz(string) ⇒ Object



27
28
29
30
# File 'lib/vcseif/utils/fuzzer.rb', line 27

def self.fuzz(string)
  # would have been nice to be able to do alias_method :fuzz, :encode
  return self.encode(string) 
end

.is_encoded?(string) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
# File 'lib/vcseif/utils/fuzzer.rb', line 50

def self.is_encoded?(string)
  %{
     Does the string arg  start with "encoded-" and are there an 
     equal number of separator strings and regular characters?
   } 
  return false if string.class.name != 'String'
  sliced = string.slice(ENCODED.length, string.length)
  return string.slice(0,ENCODED.length) == ENCODED && sliced.length == sliced.count(SEPARATOR)*2
end