Module: StringHelpers

Included in:
String
Defined in:
lib/ooxml_decrypt/string_helpers.rb

Instance Method Summary collapse

Instance Method Details

#base64_decodeObject



23
24
25
# File 'lib/ooxml_decrypt/string_helpers.rb', line 23

def base64_decode
  return self.unpack("m").first
end

#hexifyObject

Convert a string to ASCII hex string (Adapted from the Ruby Black Bag [github.com/emonti/rbkb/])



5
6
7
8
9
10
11
12
13
14
# File 'lib/ooxml_decrypt/string_helpers.rb', line 5

def hexify()
  out=Array.new
  hexchars = [("0".."9").to_a, ("a".."f").to_a].flatten

  self.each_byte do |c|
    hc = (hexchars[(c >> 4)] + hexchars[(c & 0xf )])
    out << (hc)
  end
  out.join("")
end

#pad_or_trim!(final_length, pad_byte = "\x36") ⇒ Object

Makes the string a given length by trimming excess bytes from the endi, or padding with the given padding byte.

Parameters:

  • final_length (Integer)


31
32
33
34
35
# File 'lib/ooxml_decrypt/string_helpers.rb', line 31

def pad_or_trim!( final_length, pad_byte="\x36" )
  self.slice!(final_length..-1)
  self << pad_byte * (final_length - self.length)
  return self
end

#unhexify(d = /\s*/) ⇒ Object

Convert ASCII hex string to raw. (Adapted from the Ruby Black Bag [github.com/emonti/rbkb/])

Parameters:

  • d (Regex) (defaults to: /\s*/)

    (Optional) ‘delimiter’ between hex bytes (zero+ spaces by default)



19
20
21
# File 'lib/ooxml_decrypt/string_helpers.rb', line 19

def unhexify(d=/\s*/)
  self.strip.gsub(/([A-Fa-f0-9]{1,2})#{d}?/) { $1.hex.chr }
end