function GF256Poly(e,i){if(null==i||0==i.length)throw"System.ArgumentException";this.field=e;var t=i.length;if(t>1&&0==i[0]){for(var f=1;t>f&&0==i[f];)f++;if(f==t)this.coefficients=e.Zero.coefficients;else{this.coefficients=new Array(t-f);for(var r=0;r<this.coefficients.length;r++)this.coefficients[r]=0;for(var n=0;n<this.coefficients.length;n++)this.coefficients[n]=i[f+n]}}else this.coefficients=i;Object.defineProperties(this,{Zero:{get:function(){return 0==this.coefficients[0]}},Degree:{get:function(){return this.coefficients.length-1}},Coefficients:{get:function(){return this.coefficients}}}),this.getCoefficient=function(e){return this.coefficients[this.coefficients.length-1-e]},this.evaluateAt=function(e){if(0==e)return this.getCoefficient(0);var i=this.coefficients.length;if(1==e){for(var t=0,f=0;i>f;f++)t=GF256.addOrSubtract(t,this.coefficients[f]);return t}for(var r=this.coefficients[0],f=1;i>f;f++)r=GF256.addOrSubtract(this.field.multiply(e,r),this.coefficients[f]);return r},this.addOrSubtract=function(i){if(this.field!=i.field)throw"GF256Polys do not have same GF256 field";if(this.Zero)return i;if(i.Zero)return this;var t=this.coefficients,f=i.coefficients;if(t.length>f.length){var r=t;t=f,f=r}for(var n=new Array(f.length),o=f.length-t.length,s=0;o>s;s++)n[s]=f[s];for(var h=o;h<f.length;h++)n[h]=GF256.addOrSubtract(t[h-o],f[h]);return new GF256Poly(e,n)},this.multiply1=function(e){if(this.field!=e.field)throw"GF256Polys do not have same GF256 field";if(this.Zero||e.Zero)return this.field.Zero;for(var i=this.coefficients,t=i.length,f=e.coefficients,r=f.length,n=new Array(t+r-1),o=0;t>o;o++)for(var s=i[o],h=0;r>h;h++)n[o+h]=GF256.addOrSubtract(n[o+h],this.field.multiply(s,f[h]));return new GF256Poly(this.field,n)},this.multiply2=function(e){if(0==e)return this.field.Zero;if(1==e)return this;for(var i=this.coefficients.length,t=new Array(i),f=0;i>f;f++)t[f]=this.field.multiply(this.coefficients[f],e);return new GF256Poly(this.field,t)},this.multiplyByMonomial=function(e,i){if(0>e)throw"System.ArgumentException";if(0==i)return this.field.Zero;for(var t=this.coefficients.length,f=new Array(t+e),r=0;r<f.length;r++)f[r]=0;for(var r=0;t>r;r++)f[r]=this.field.multiply(this.coefficients[r],i);return new GF256Poly(this.field,f)},this.divide=function(e){if(this.field!=e.field)throw"GF256Polys do not have same GF256 field";if(e.Zero)throw"Divide by 0";for(var i=this.field.Zero,t=this,f=e.getCoefficient(e.Degree),r=this.field.inverse(f);t.Degree>=e.Degree&&!t.Zero;){var n=t.Degree-e.Degree,o=this.field.multiply(t.getCoefficient(t.Degree),r),s=e.multiplyByMonomial(n,o),h=this.field.buildMonomial(n,o);i=i.addOrSubtract(h),t=t.addOrSubtract(s)}return new Array(i,t)}}