Sha256: 044167fb0f4c0ea727060d4b6de34a517f1fd89a5dddf870beb1781929898cd7

Contents?: true

Size: 388 Bytes

Versions: 10

Compression:

Stored size: 388 Bytes

Contents

class String
  
  # Convert hex string to binary
  def to_bin
    to_a.pack('H*')
  end
  
  # Convert binary string to hex
  def to_hex
    unpack('H*')[0]
  end
  
  # Check if the string is hex encoded
  def hex?
    self =~ /^[0-9a-fA-F]+$/ ? true : false
  end
  
  # Check if the string is modhex encoded
  def modhex?
    self =~ /^[cbdefghijklnrtuv]+$/ ? true : false
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
titanous-yubikey-1.0.0 lib/yubikey/hex.rb
titanous-yubikey-1.0.1 lib/yubikey/hex.rb
titanous-yubikey-1.0.2 lib/yubikey/hex.rb
titanous-yubikey-1.1.0 lib/yubikey/hex.rb
titanous-yubikey-1.1.1 lib/yubikey/hex.rb
yubikey-1.2.0 lib/yubikey/hex.rb
yubikey-1.1.1 lib/yubikey/hex.rb
yubikey-1.0.2 lib/yubikey/hex.rb
yubikey-1.0.0 lib/yubikey/hex.rb
yubikey-1.1.0 lib/yubikey/hex.rb