Sha256: c40b0e8092ee51a813c1a95daa50df6c0fc2a1ca8395ec17812709ca0ce3a9d3

Contents?: true

Size: 1.6 KB

Versions: 37

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

#--
# Copyright 2004 by Duncan Robertson (duncan@whomwah.com).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#++

module RQRCode #:nodoc:

  class QRPolynomial

    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


    def get( index )
      @num[index]
    end


    def get_length
      @num.size
    end


    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


    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 

  end

end

Version data entries

37 entries across 37 versions & 7 rubygems

Version Path
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_polynomial.rb
oshpark-rqrcode-0.10.2 lib/rqrcode/qrcode/qr_polynomial.rb
oshpark-rqrcode-0.10.1 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.10.1 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.10.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.8.2 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.9.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.8.1 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.8.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.7.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.6.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.6.0 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.5.5 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.5.4 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.5.3 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.5.2 lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-with-patches-0.5.1 lib/rqrcode/qrcode/qr_polynomial.rb
arena_barby-0.3.2 vendor/rqrcode/lib/rqrcode/qrcode/qr_polynomial.rb
barby-chunky_png-0.3.4 vendor/rqrcode/lib/rqrcode/qrcode/qr_polynomial.rb
rqrcode-0.4.2 lib/rqrcode/qrcode/qr_polynomial.rb