public QRPolynomial Multiply(QRPolynomial e) { var num = new DataCache(GetLength() + e.GetLength() - 1); for (var i = 0; i < GetLength(); i++) { for (var j = 0; j < e.GetLength(); j++) { num[i + j] ^= QRMath.GExp(QRMath.GLog(Get(i)) + QRMath.GLog(e.Get(j))); } } return(new QRPolynomial(num, 0)); }
internal static QRPolynomial GetErrorCorrectPolynomial(int errorCorrectLength) { var a = new QRPolynomial(new DataCache() { 1 }, 0); for (var i = 0; i < errorCorrectLength; i++) { a = a.Multiply(new QRPolynomial(new DataCache() { 1, QRMath.GExp(i) }, 0)); } return(a); }
public QRPolynomial Mod(QRPolynomial e) { if (Convert.ToInt64(GetLength()) - Convert.ToInt64(e.GetLength()) < 0L) { return(this); } var ratio = QRMath.GLog(Get(0)) - QRMath.GLog(e.Get(0)); var num = new DataCache(GetLength()); for (var i = 0; i < GetLength(); i++) { num[i] = Get(i); } for (var i = 0; i < e.GetLength(); i++) { num[i] ^= QRMath.GExp(QRMath.GLog(e.Get(i)) + ratio); } // recursive call return(new QRPolynomial(num, 0).Mod(e)); }
private DataCache CreateBytes(QRBitBuffer buffer, List <QRRSBlock> rsBlocks) { var offset = 0; var maxDcCount = 0; var maxEcCount = 0; var dcdata = new DataCache[(rsBlocks.Count)]; var ecdata = new DataCache[(rsBlocks.Count)]; for (var r = 0; r < rsBlocks.Count; r++) { var dcCount = rsBlocks[r].DataCount; var ecCount = rsBlocks[r].TotalCount - dcCount; maxDcCount = Math.Max(maxDcCount, dcCount); maxEcCount = Math.Max(maxEcCount, ecCount); dcdata[r] = new DataCache(dcCount); for (var i = 0; i < dcdata[r].Count; i++) { dcdata[r][i] = 0xff & buffer._buffer[i + offset]; } offset += dcCount; var rsPoly = QRUtil.GetErrorCorrectPolynomial(ecCount); var rawPoly = new QRPolynomial(dcdata[r], rsPoly.GetLength() - 1); var modPoly = rawPoly.Mod(rsPoly); ecdata[r] = new DataCache(rsPoly.GetLength() - 1); for (var i = 0; i < ecdata[r].Count; i++) { int modIndex = i + modPoly.GetLength() - ecdata[r].Count; ecdata[r][i] = (modIndex >= 0) ? modPoly.Get(modIndex) : 0; } } var totalCodeCount = 0; for (var i = 0; i < rsBlocks.Count; i++) { totalCodeCount += rsBlocks[i].TotalCount; } var data = new DataCache(totalCodeCount); var index = 0; for (var i = 0; i < maxDcCount; i++) { for (var r = 0; r < rsBlocks.Count; r++) { if (i < dcdata[r].Count) { data[index++] = dcdata[r][i]; } } } for (var i = 0; i < maxEcCount; i++) { for (var r = 0; r < rsBlocks.Count; r++) { if (i < ecdata[r].Count) { data[index++] = ecdata[r][i]; } } } return(data); }