Class: RQRCodeCore::QRPolynomial

Inherits:
Object
  • Object
show all
Defined in:
lib/rqrcode_core/qrcode/qr_polynomial.rb

Instance Method Summary collapse

Constructor Details

#initialize(num, shift) ⇒ QRPolynomial

Returns a new instance of QRPolynomial.

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rqrcode_core/qrcode/qr_polynomial.rb', line 5

def initialize( num, shift )
  raise QRCodeRunTimeError, "#{num.size}/#{shift}" if num.empty?
  offset = 0

  while offset < num.size && num[offset] == 0
    offset = offset + 1
  end

  @num = Array.new( num.size - offset + shift )

  ( 0...num.size - offset ).each do |i|
    @num[i] = num[i + offset]
  end
end

Instance Method Details

#get(index) ⇒ Object



20
21
22
# File 'lib/rqrcode_core/qrcode/qr_polynomial.rb', line 20

def get( index )
  @num[index]
end

#get_lengthObject



24
25
26
# File 'lib/rqrcode_core/qrcode/qr_polynomial.rb', line 24

def get_length
  @num.size
end

#mod(e) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rqrcode_core/qrcode/qr_polynomial.rb', line 41

def mod( e )
  if get_length - e.get_length < 0
    return self
  end

  ratio = QRMath.glog(get(0)) - QRMath.glog(e.get(0))
  num = Array.new(get_length)

  ( 0...get_length ).each do |i|
    num[i] = get(i)
  end

  ( 0...e.get_length ).each do |i|
    tmp = num[i].nil? ? 0 : num[i]
    num[i] = tmp ^ QRMath.gexp(QRMath.glog(e.get(i)) + ratio)
  end

  return QRPolynomial.new( num, 0 ).mod(e)
end

#multiply(e) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rqrcode_core/qrcode/qr_polynomial.rb', line 28

def multiply( e )
  num = Array.new( get_length + e.get_length - 1 )

  ( 0...get_length ).each do |i|
    ( 0...e.get_length ).each do |j|
      tmp = num[i + j].nil? ? 0 : num[i + j]
      num[i + j] = tmp ^ QRMath.gexp(QRMath.glog( get(i) ) + QRMath.glog(e.get(j)))
    end
  end

  return QRPolynomial.new( num, 0 )
end