Module: StringHelpers
- Included in:
- String
- Defined in:
- lib/ooxml_decrypt/string_helpers.rb
Instance Method Summary collapse
- #base64_decode ⇒ Object
-
#hexify ⇒ Object
Convert a string to ASCII hex string (Adapted from the Ruby Black Bag [github.com/emonti/rbkb/]).
-
#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.
-
#unhexify(d = /\s*/) ⇒ Object
Convert ASCII hex string to raw.
Instance Method Details
#base64_decode ⇒ Object
23 24 25 |
# File 'lib/ooxml_decrypt/string_helpers.rb', line 23 def base64_decode return self.unpack("m").first end |
#hexify ⇒ Object
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.
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/])
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 |