lib/ctf_party/hex.rb in ctf-party-1.3.0 vs lib/ctf_party/hex.rb in ctf-party-1.3.1

- old
+ new

@@ -88,20 +88,30 @@ out = out.upcase if opts[:case] == :upper # adding prefix must be done after case change return opts[:prefix] + out end + # Alias for {String#to_hex}. + def str2hex(opts = {}) + to_hex(opts) + end + # Encode a string into hexadecimal in place as described # for {String#to_hex}. # @example # a = 'noraj' # a.to_hex! # a # => "6e6f72616a" def to_hex!(opts = {}) replace(to_hex(opts)) end + # Alias for {String#to_hex!}. + def str2hex!(opts = {}) + to_hex!(opts) + end + # Decode a hexadecimal string # @param opts [Hash] optional parameters # @option opts [String] :prefix Prefix of the input. Default value is a void # string. Example of values: +0x+, +\x+. # @option opts [Symbol] :nibble Display input with high nibble first @@ -121,17 +131,27 @@ return Array(out).pack('h*') if opts[:nibble] == :low raise ArgumentError ':nibble expects :high or :low' end + # Alias for {String#from_hex}. + def hex2str(opts = {}) + from_hex(opts) + end + # Decode a hexadecimal string in place as described # for {String#from_hex}. # @example # a = "6e6f72616a" # a.from_hex! # a # => "noraj" def from_hex!(opts = {}) replace(from_hex(opts)) + end + + # Alias for {String#from_hex!}. + def hex2str!(opts = {}) + from_hex!(opts) end # Encode an hexadecimal string to a binary string # @param opts [Hash] optional parameters # @option opts [String] :prefix Prefix of the input. Default value is a void