public void SaveLoadUIntNET() { using (MemoryStream stream = new MemoryStream()) { var value = new BigUInt(); var value2 = new BigUInt("100"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("123"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("FFFFFFFFFFFFFFFFFFFFFFFFFF"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("0"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); } }
public void ExponentiateBigUIntModNET() { var myUInt = new BigUInt("ABABABAB"); var modulus = new BigUInt("CAACAACAA"); var exponent = new BigUInt("5"); var result = Utilities.ExponentiateUIntMod(myUInt, exponent, modulus); Assert.AreEqual("33773505765", result.ToDecimalString()); myUInt.Set("1"); exponent.Set("F00F00F00F00F00"); result = Utilities.ExponentiateUIntMod(myUInt, exponent, modulus); Assert.AreEqual("1", result.ToDecimalString()); modulus.Set("AAAAAAAAAAAAAAAAAAAAA"); myUInt.Set("F00F00F00F00F00"); exponent.Set("1"); result = Utilities.ExponentiateUIntMod(myUInt, exponent, modulus); Assert.AreEqual("F00F00F00F00F00", result.ToString()); myUInt.Set("F00F00F00F00F00"); exponent.Set("0"); result = Utilities.ExponentiateUIntMod(myUInt, exponent, modulus); Assert.AreEqual("1", result.ToString()); }
public void BigPolyEvalUIntModNET() { var modulus = new BigUInt("5"); var poly = new BigPoly("1x^2 + 1x^1 + 1"); var value = new BigUInt("0"); var result = Utilities.PolyEvalUIntMod(poly, value, modulus); Assert.AreEqual("1", result.ToString()); value.Set("1"); result = Utilities.PolyEvalUIntMod(poly, value, modulus); Assert.AreEqual("3", result.ToString()); value.Set("4"); result = Utilities.PolyEvalUIntMod(poly, value, modulus); Assert.AreEqual("1", result.ToString()); }
public void ExponentiatePolyPolyPolyModCoeffModNET() { var poly = new BigPoly("1x^2 + 2x^1 + 3"); var modulus = new BigUInt("5"); var exponent = new BigUInt("1"); var polymod = new BigPoly("1x^3 + 3x^1 + 1"); var result = Utilities.ExponentiatePolyPolymodCoeffmod(poly, exponent, polymod, modulus); Assert.AreEqual("1x^2 + 2x^1 + 3", result.ToString()); exponent.Set("2"); result = Utilities.ExponentiatePolyPolymodCoeffmod(poly, exponent, polymod, modulus); Assert.AreEqual("2x^2 + 4x^1", result.ToString()); poly.Set("1"); exponent.Set("2"); result = Utilities.ExponentiatePolyPolymodCoeffmod(poly, exponent, polymod, modulus); Assert.AreEqual("1", result.ToString()); exponent.Set("F00F000F00"); result = Utilities.ExponentiatePolyPolymodCoeffmod(poly, exponent, polymod, modulus); Assert.AreEqual("1", result.ToString()); }
public void BigUInt99BitsNET() { var biguint = new BigUInt(99); Assert.AreEqual(99, biguint.BitCount); Assert.IsTrue(biguint.UInt64Count != 0ul); Assert.AreEqual(13ul, biguint.ByteCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual(0, biguint.GetSignificantBitCount()); Assert.AreEqual("0", biguint.ToString()); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.Set(1); Assert.AreEqual(1, biguint.GetSignificantBitCount()); Assert.AreEqual("1", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(13ul, biguint.ByteCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual(1UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(1, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.SetZero(); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); biguint.Set("7FFFFFFFFFFFFFFFFFFFFFFFF"); Assert.AreEqual(99, biguint.GetSignificantBitCount()); Assert.AreEqual("7FFFFFFFFFFFFFFFFFFFFFFFF", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0xFFFFFFFFFFFFFFFFUL, biguint.Data(0)); Assert.AreEqual(0x7FFFFFFFFUL, biguint.Data(1)); Assert.AreEqual(0xFF, biguint[0]); Assert.AreEqual(0xFF, biguint[1]); Assert.AreEqual(0xFF, biguint[2]); Assert.AreEqual(0xFF, biguint[3]); Assert.AreEqual(0xFF, biguint[4]); Assert.AreEqual(0xFF, biguint[5]); Assert.AreEqual(0xFF, biguint[6]); Assert.AreEqual(0xFF, biguint[7]); Assert.AreEqual(0xFF, biguint[8]); Assert.AreEqual(0xFF, biguint[9]); Assert.AreEqual(0xFF, biguint[10]); Assert.AreEqual(0xFF, biguint[11]); Assert.AreEqual(0x07, biguint[12]); biguint.SetZero(); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); biguint.Set("4000000000000000000000000"); Assert.AreEqual(99, biguint.GetSignificantBitCount()); Assert.AreEqual("4000000000000000000000000", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0x400000000UL, biguint.Data(1)); Assert.AreEqual(0, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0x04, biguint[12]); biguint.Set(0x8001); Assert.AreEqual(16, biguint.GetSignificantBitCount()); Assert.AreEqual("8001", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0x8001UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0x01, biguint[0]); Assert.AreEqual(0x80, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); var biguint2 = new BigUInt("123"); Assert.IsFalse(biguint.Equals(biguint2)); Assert.IsFalse(biguint2.Equals(biguint)); Assert.AreNotEqual(biguint.GetHashCode(), biguint2.GetHashCode()); biguint.Set(biguint2); Assert.IsTrue(biguint.Equals(biguint2)); Assert.IsTrue(biguint2.Equals(biguint)); Assert.AreEqual(biguint.GetHashCode(), biguint2.GetHashCode()); Assert.AreEqual(9, biguint.GetSignificantBitCount()); Assert.AreEqual("123", biguint.ToString()); Assert.AreEqual(0x123UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0x23, biguint[0]); Assert.AreEqual(0x01, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.Resize(8); Assert.AreEqual(8, biguint.BitCount); Assert.AreEqual(1ul, biguint.UInt64Count); Assert.AreEqual("23", biguint.ToString()); biguint.Resize(100); Assert.AreEqual(100, biguint.BitCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual("23", biguint.ToString()); biguint.Resize(0); Assert.AreEqual(0, biguint.BitCount); Assert.AreEqual(0ul, biguint.UInt64Count); Assert.IsTrue(biguint.UInt64Count == 0); }