Module: Cryptools::Converters

Defined in:
lib/cryptools.rb

Class Method Summary collapse

Class Method Details

.bytes2hex(bytes) ⇒ Object



22
23
24
# File 'lib/cryptools.rb', line 22

def bytes2hex(bytes)
  bytes.map{|b| b.to_s(16)}.join
end

.hex2bytes(hexStr) ⇒ Object



18
19
20
# File 'lib/cryptools.rb', line 18

def hex2bytes(hexStr)
  hex2str(hexStr).unpack('C*')
end

.hex2str(hexStr) ⇒ Object



10
11
12
# File 'lib/cryptools.rb', line 10

def hex2str(hexStr)
  [hexStr].pack('H*')
end

.str2bytes(str) ⇒ Object



26
27
28
# File 'lib/cryptools.rb', line 26

def str2bytes(str)
  str.split('').map!{|c| c.ord}
end

.str2hex(str) ⇒ Object



14
15
16
# File 'lib/cryptools.rb', line 14

def str2hex(str)
  str.unpack('H*').first
end