lib/megar/crypto/support.rb
def mpi_to_a32(s)
    bs=28
    bx2=1<<bs
    bm=bx2-1

    bn=1
    r=[0]
    rn=0
    sb=256
    c = nil
    sn=s.length
    return 0 if(sn < 2)

    len=(sn-2)*8
    bits=s[0].ord*256+s[1].ord

    return 0 if(bits > len || bits < len-8)

    len.times do |n|
      if ((sb<<=1) > 255)
        sb=1
        sn -= 1
        c=s[sn].ord
      end
      if(bn > bm)
        bn=1
        rn += 1
        r << 0
      end
      if(c & sb != 0)
        r[rn]|=bn
      end
      bn<<=1
    end
    r
  end
# Returns multiple precision integer (MPI) as an array of 32-bit unsigned integers decoded from raw string +s+
# This first 16-bits of the MPI is the MPI length in bits
#
# Javascript reference implementation: function mpi2b(s)
#
Returns multiple precision integer (MPI) as an array of 32-bit unsigned integers decoded from raw string +s+
This first 16-bits of the MPI is the MPI length in bits

Javascript reference implementation: function mpi2b(s)
Returns multiple precision integer ( MPI ) as an array of 32 - bit unsigned integers decoded from raw string + s + This first 16 - bits of the MPI is the MPI length in bits Javascript reference implementation : function mpi2b ( s )
def mpi_to_a32(s)
    bs=28
    bx2=1<<bs
    bm=bx2-1
    bn=1
    r=[0]
    rn=0
    sb=256
    c = nil
    sn=s.length
    return 0 if(sn < 2)
    len=(sn-2)*8
    bits=s[0].ord*256+s[1].ord
    return 0 if(bits > len || bits < len-8)
    len.times do |n|
      if ((sb<<=1) > 255)
        sb=1
        sn -= 1
        c=s[sn].ord
      end
      if(bn > bm)
        bn=1
        rn += 1
        r << 0
      end
      if(c & sb != 0)
        r[rn]|=bn
      end
      bn<<=1
    end
    r
  end
def mpi_to_a32 ( s ) bs = 28 bx2 = 1 << bs bm = bx2 - 1 bn = 1 r = [ 0 ] rn = 0 sb = 256 c = nil sn = s . length return 0 if ( sn < 2 ) len = ( sn - 2 ) * 8 bits = s [ 0 ] . ord * 256 + s [ 1 ] . ord return 0 if ( bits > len || bits < len - 8 ) len . times do | n | if ( ( sb <<= 1 ) > 255 ) sb = 1 sn -= 1 c = s [ sn ] . ord end if ( bn > bm ) bn = 1 rn += 1 r << 0 end if ( c & sb != 0 ) r [ rn ] |= bn end bn <<= 1 end r end
Returns multiple precision integer (MPI) as an array of 32-bit unsigned integers decoded from raw string +s+
This first 16-bits of the MPI is the MPI length in bits
Returns multiple precision integer ( MPI ) as an array of 32 - bit unsigned integers decoded from raw string + s + This first 16 - bits of the MPI is the MPI length in bits
s