internal static Polynomial GetErrorCorrectPolynomial(int errorCorrectLength) { Polynomial a = new Polynomial(new int[] { 1 }); for (int i = 0; i < errorCorrectLength; i++) { a = a.Multiply(new Polynomial(new int[] { 1, QRMath.Gexp(i) })); } return(a); }
public Polynomial Multiply(Polynomial e) { int[] array = new int[this.GetLength() + e.GetLength() - 1]; for (int i = 0; i < this.GetLength(); i++) { for (int j = 0; j < e.GetLength(); j++) { array[i + j] ^= QRMath.Gexp(QRMath.Glog(this.Get(i)) + QRMath.Glog(e.Get(j))); } } return(new Polynomial(array)); }
public Polynomial Multiply(Polynomial e) { int[] num = new int[GetLength() + e.GetLength() - 1]; for (int i = 0; i < GetLength(); i++) { for (int j = 0; j < e.GetLength(); j++) { num[i + j] ^= QRMath.Gexp(QRMath.Glog(Get(i)) + QRMath.Glog(e.Get(j))); } } return(new Polynomial(num)); }
public Polynomial Mod(Polynomial e) { if (this.GetLength() - e.GetLength() < 0) { return(this); } int num = QRMath.Glog(this.Get(0)) - QRMath.Glog(e.Get(0)); int[] array = new int[this.GetLength()]; for (int i = 0; i < this.GetLength(); i++) { array[i] = this.Get(i); } for (int j = 0; j < e.GetLength(); j++) { array[j] ^= QRMath.Gexp(QRMath.Glog(e.Get(j)) + num); } return(new Polynomial(array).Mod(e)); }
public Polynomial Mod(Polynomial e) { if (GetLength() - e.GetLength() < 0) { return(this); } int ratio = QRMath.Glog(Get(0)) - QRMath.Glog(e.Get(0)); int[] num = new int[GetLength()]; for (int i = 0; i < GetLength(); i++) { num[i] = Get(i); } for (int i = 0; i < e.GetLength(); i++) { num[i] ^= QRMath.Gexp(QRMath.Glog(e.Get(i)) + ratio); } return(new Polynomial(num).Mod(e)); }