MCPcopy
hub / github.com/kciter/qart.js / qrPolynomial

Function qrPolynomial

src/qrcode.js:974–1034  ·  view source on GitHub ↗
(num, shift)

Source from the content-addressed store, hash-verified

972 // ---------------------------------------------------------------------
973
974 function qrPolynomial (num, shift) {
975 if (typeof num.length === 'undefined') {
976 throw new Error(num.length + '/' + shift)
977 }
978
979 var _num = (function () {
980 var offset = 0
981 while (offset < num.length && num[offset] == 0) {
982 offset += 1
983 }
984 var _num = new Array(num.length - offset + shift)
985 for (var i = 0; i < num.length - offset; i += 1) {
986 _num[i] = num[i + offset]
987 }
988 return _num
989 }())
990
991 var _this = {}
992
993 _this.getAt = function (index) {
994 return _num[index]
995 }
996
997 _this.getLength = function () {
998 return _num.length
999 }
1000
1001 _this.multiply = function (e) {
1002 var num = new Array(_this.getLength() + e.getLength() - 1)
1003
1004 for (var i = 0; i < _this.getLength(); i += 1) {
1005 for (var j = 0; j < e.getLength(); j += 1) {
1006 num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)))
1007 }
1008 }
1009
1010 return qrPolynomial(num, 0)
1011 }
1012
1013 _this.mod = function (e) {
1014 if (_this.getLength() - e.getLength() < 0) {
1015 return _this
1016 }
1017
1018 var ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0))
1019
1020 var num = new Array(_this.getLength())
1021 for (var i = 0; i < _this.getLength(); i += 1) {
1022 num[i] = _this.getAt(i)
1023 }
1024
1025 for (var i = 0; i < e.getLength(); i += 1) {
1026 num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio)
1027 }
1028
1029 // recursive call
1030 return qrPolynomial(num, 0).mod(e)
1031 }

Callers 2

createBytesFunction · 0.85
qrcode.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected