public void CompareToTest() { BigInt a = new BigInt(123); BigInt b = new BigInt(9); Assert.AreEqual(0, a.CompareTo(a)); Assert.AreEqual(1, a.CompareTo(b)); Assert.AreEqual(-1, b.CompareTo(a)); }
public static BigInt HashToField(byte[] toHash, Field field) { int byteLength = 1 + (field.GetP().BitLength() - 1) / 8; byte[] ba = HashToLength(toHash, byteLength); BigInt b = new BigInt(ba); //This could fail while (b.CompareTo(field.GetP()) >= 0) { b = b.ShiftRight(1); } return(b); }
public static KeyPair Setup(Pairing e, Random rnd) { Point P = e.Curve2.RandomPoint(rnd); BigInt s = new BigInt(e.GroupOrder.BitLength(), rnd); while (s.CompareTo(e.GroupOrder) >= 0) { s = s.ShiftRight(1); } Point Ppub = e.Curve2.Multiply(P, s); BFMasterPublicKey pk = new BFMasterPublicKey(e, P, Ppub); BFMasterPrivateKey sk = new BFMasterPrivateKey(s); //return new KeyPair(pk, sk); return(new KeyPair(null, null)); }
[TestMethod] public void TestCmp() { int[] arr = new int[] { 0, 2, -2, 0x2211, -0x2211, 0x323232, -0x323232, }; foreach (int ia in arr) { BigInt a_ = (BigInt)ia; foreach (int ib in arr) { BigInt b_ = (BigInt)ib; AssertEquals("cmp", a_ == b_, ia == ib); AssertEquals("cmp", a_ != b_, ia != ib); AssertEquals("cmp", a_ <= b_, ia <= ib); AssertEquals("cmp", a_ > b_, ia > ib); } } BigInt a = (BigInt)0x0A_0F22; BigInt b = (BigInt)0x0A_0F22; BigInt c = (BigInt)0x0; BigInt d = (BigInt)(-0x0A_0F22); var two = (BigInt)2; AssertEquals("cmp", a == b, true); AssertEquals("cmp", a == (BigInt)0x0A_0F22, true); AssertEquals("cmp", a != b, false); AssertEquals("cmp", a <= b, true); AssertEquals("cmp", a <= two, false); AssertEquals("cmp", a > two, true); AssertEquals("cmp", a == two, false); AssertEquals("cmp", a < (BigInt)0xA0_ABCD, true); AssertEquals("cmp", a < (BigInt)0xABCD, false); AssertEquals("cmp", a < (BigInt)0x100ABCD, true); AssertEquals("cmp", c.CompareTo(d), 1); AssertEquals("cmp", a < (BigInt)0x09_ABCD, false); }