private List<string> CalculateECCWords(string bitString, ECCInfo eccInfo) { var eccWords = eccInfo.ECCPerBlock; var messagePolynom = this.CalculateMessagePolynom(bitString); var generatorPolynom = this.CalculateGeneratorPolynom(eccWords); for (var i = 0; i < messagePolynom.PolyItems.Count; i++) messagePolynom.PolyItems[i] = new PolynomItem(messagePolynom.PolyItems[i].Coefficient, messagePolynom.PolyItems[i].Exponent + eccWords); for (var i = 0; i < generatorPolynom.PolyItems.Count; i++) generatorPolynom.PolyItems[i] = new PolynomItem(generatorPolynom.PolyItems[i].Coefficient, generatorPolynom.PolyItems[i].Exponent + (messagePolynom.PolyItems.Count-1)); var leadTermSource = messagePolynom; for (var i = 0; i < messagePolynom.PolyItems.Count || (leadTermSource.PolyItems.Count > 0 && leadTermSource.PolyItems[leadTermSource.PolyItems.Count-1].Exponent > 0); i++) { if (leadTermSource.PolyItems[0].Coefficient == 0) { leadTermSource.PolyItems.RemoveAt(0); } else { var resPoly = this.MultiplyGeneratorPolynomByLeadterm(generatorPolynom, this.ConvertToAlphaNotation(leadTermSource).PolyItems[0], i); resPoly = this.ConvertToDecNotation(resPoly); resPoly = this.XORPolynoms(leadTermSource, resPoly); leadTermSource = resPoly; } } return leadTermSource.PolyItems.Select(x => DecToBin(x.Coefficient, 8)).ToList(); }
private List<string> CalculateEccWords(string bitString, ECCInfo eccInfo) { var eccWords = eccInfo.ECCPerBlock; var messagePolynom = CalculateMessagePolynom(bitString); var generatorPolynom = CalculateGeneratorPolynom(eccWords); for (var i = 0; i < messagePolynom.PolyItems.Count; i++) messagePolynom.PolyItems[i] = new PolynomItem() { Coefficient = messagePolynom.PolyItems[i].Coefficient, Exponent = messagePolynom.PolyItems[i].Exponent + eccWords }; var genLeadtermFactor = messagePolynom.PolyItems[0].Exponent - generatorPolynom.PolyItems[0].Exponent; for (var i = 0; i < generatorPolynom.PolyItems.Count; i++) generatorPolynom.PolyItems[i] = new PolynomItem() { Coefficient = generatorPolynom.PolyItems[i].Coefficient, Exponent = generatorPolynom.PolyItems[i].Exponent + genLeadtermFactor }; var leadTermSource = messagePolynom; for (var i = 0; i < messagePolynom.PolyItems.Count; i++) { if (leadTermSource.PolyItems[0].Coefficient == 0) { // First coefficient is already 0, simply remove it and continue leadTermSource.PolyItems.RemoveAt(0); } else { var resPoly = MultiplyGeneratorPolynomByLeadterm(generatorPolynom, ConvertToAlphaNotation(leadTermSource).PolyItems[0], i); resPoly = ConvertToDecNotation(resPoly); resPoly = XorPolynoms(leadTermSource, resPoly); leadTermSource = resPoly; } } return leadTermSource.PolyItems.Select(x => DecToBin(x.Coefficient, 8)).ToList(); }