class CryptoGost3410::Converter

Public Class Methods

bignumToBytes(bn, size) click to toggle source

Big number -> byte string (big-endian) of given size

# File lib/crypto_gost3410/converter.rb, line 4
def self.bignumToBytes(bn, size)
  s = bn.to_s(16)
  s = ('0' * (size * 2 - s.length)) + s 
  sa = s.scan(/../)
  ba = []
  sa.each{|c| ba << c.to_i(16).chr} 
  bytes = ba.join
end
bytesToBignum(bytes) click to toggle source

Byte string (big-endian) to big number

# File lib/crypto_gost3410/converter.rb, line 14
def self.bytesToBignum(bytes)
  bytes.unpack('H*')[0].hex
end
printBytes(bytes, line_size = 16) click to toggle source

Byte string hex printer

# File lib/crypto_gost3410/converter.rb, line 19
def self.printBytes(bytes, line_size = 16)
  bytes.unpack('H*')[0].scan(/.{1,#{line_size}}/).each{|s| puts(s)}
end