static void TestFr() { Console.WriteLine("TestFr"); Fr x = new Fr(); assert("x.isZero", x.IsZero()); x.Clear(); assert("0", x.GetStr(10) == "0"); assert("0.IzZero", x.IsZero()); assert("!0.IzOne", !x.IsOne()); x.SetInt(1); assert("1", x.GetStr(10) == "1"); assert("!1.IzZero", !x.IsZero()); assert("1.IzOne", x.IsOne()); x.SetInt(3); assert("3", x.GetStr(10) == "3"); assert("!3.IzZero", !x.IsZero()); assert("!3.IzOne", !x.IsOne()); x.SetInt(-5); x = -x; assert("5", x.GetStr(10) == "5"); x.SetInt(4); x = x * x; assert("16", x.GetStr(10) == "16"); assert("10", x.GetStr(16) == "10"); Fr y; y = x; assert("x == y", x.Equals(y)); x.SetInt(123); assert("123", x.GetStr(10) == "123"); assert("7b", x.GetStr(16) == "7b"); assert("y != x", !x.Equals(y)); Console.WriteLine("exception test"); try { x.SetStr("1234567891234x", 10); Console.WriteLine("x = {0}", x); } catch (Exception e) { Console.WriteLine("OK ; expected exception: {0}", e); } x.SetStr("1234567891234", 10); assert("1234567891234", x.GetStr(10) == "1234567891234"); { byte[] buf = x.Serialize(); y.Deserialize(buf); assert("x == y", x.Equals(y)); } }
static void TestFr() { Console.WriteLine("TestFr"); Fr x = new Fr(); x.Clear(); assert("0", x.ToString() == "0"); assert("0.IzZero", x.IsZero()); assert("!0.IzOne", !x.IsOne()); x.SetInt(1); assert("1", x.ToString() == "1"); assert("!1.IzZero", !x.IsZero()); assert("1.IzOne", x.IsOne()); x.SetInt(3); assert("3", x.ToString() == "3"); assert("!3.IzZero", !x.IsZero()); assert("!3.IzOne", !x.IsOne()); x.SetInt(-5); x = -x; assert("5", x.ToString() == "5"); x.SetInt(4); x = x * x; assert("16", x.ToString() == "16"); Fr y; y = x.Clone(); assert("x == y", x.Equals(y)); x.SetInt(123); assert("123", x.ToString() == "123"); assert("y != x", !x.Equals(y)); try { x.SetStr("1234567891234x"); Console.WriteLine("x = {0}", x); } catch (Exception e) { Console.WriteLine("exception test OK\n'{0}'", e); } x.SetStr("1234567891234"); assert("1234567891234", x.ToString() == "1234567891234"); }
static void TestSS_Fr() { const int n = 5; const int k = 3; // can't change because the following loop Fr[] cVec = new Fr[k]; // init polynomial coefficient for (int i = 0; i < k; i++) { cVec[i].SetByCSPRNG(); } Fr[] xVec = new Fr[n]; Fr[] yVec = new Fr[n]; // share cVec[0] with yVec[0], ..., yVec[n-1] for (int i = 0; i < n; i++) { xVec[i].SetHashOf(i.ToString()); MCL.Share(ref yVec[i], cVec, xVec[i]); } // recover cVec[0] from xVecSubset and yVecSubset Fr[] xVecSubset = new Fr[k]; Fr[] yVecSubset = new Fr[k]; for (int i0 = 0; i0 < n; i0++) { xVecSubset[0] = xVec[i0]; yVecSubset[0] = yVec[i0]; for (int i1 = i0 + 1; i1 < n; i1++) { xVecSubset[1] = xVec[i1]; yVecSubset[1] = yVec[i1]; for (int i2 = i1 + 1; i2 < n; i2++) { xVecSubset[2] = xVec[i2]; yVecSubset[2] = yVec[i2]; Fr s = new Fr(); MCL.Recover(ref s, xVecSubset, yVecSubset); assert("Recover", s.Equals(cVec[0])); } } } }