Пример #1
0
        public void DecodeTest()
        {
            EncryptionParameters parms = new EncryptionParameters(SchemeType.BFV)
            {
                PlainModulus = new SmallModulus(1024)
            };
            SEALContext    context = SEALContext.Create(parms);
            IntegerEncoder encoder = new IntegerEncoder(context);

            Plaintext plain = new Plaintext("0x^5 + 1x^4 + 1x^3 + 1x^1 + 0");

            Assert.AreEqual(6ul, plain.CoeffCount);

            ulong resultU64 = encoder.DecodeUInt64(plain);

            Assert.AreEqual(26UL, resultU64);

            long resultI64 = encoder.DecodeInt64(plain);

            Assert.AreEqual(26L, resultI64);

            uint resultU32 = encoder.DecodeUInt32(plain);

            Assert.AreEqual(26U, resultU32);

            int resultI32 = encoder.DecodeInt32(plain);

            Assert.AreEqual(26, resultI32);

            BigUInt bui = encoder.DecodeBigUInt(plain);

            Assert.IsNotNull(bui);
            Assert.AreEqual(0, bui.CompareTo(26ul));
        }
Пример #2
0
        public void DecodeTest()
        {
            IntegerEncoder encoder = new IntegerEncoder(GlobalContext.BFVContext);

            Plaintext plain = new Plaintext("0x^5 + 1x^4 + 1x^3 + 1x^1 + 0");

            Assert.AreEqual(6ul, plain.CoeffCount);

            ulong resultU64 = encoder.DecodeUInt64(plain);

            Assert.AreEqual(26UL, resultU64);

            long resultI64 = encoder.DecodeInt64(plain);

            Assert.AreEqual(26L, resultI64);

            uint resultU32 = encoder.DecodeUInt32(plain);

            Assert.AreEqual(26U, resultU32);

            int resultI32 = encoder.DecodeInt32(plain);

            Assert.AreEqual(26, resultI32);

            BigUInt bui = encoder.DecodeBigUInt(plain);

            Assert.IsNotNull(bui);
            Assert.AreEqual(0, bui.CompareTo(26ul));
        }
Пример #3
0
        public ulong decryptDistance(string publicFile, string secretFile, string distanceFile)
        {
            using EncryptionParameters parms = new EncryptionParameters(SchemeType.BFV);
            ulong polyModulusDegree = 4096;

            parms.PolyModulusDegree = polyModulusDegree;
            parms.CoeffModulus      = CoeffModulus.BFVDefault(polyModulusDegree);
            parms.PlainModulus      = new Modulus(1024);

            using SEALContext context = new SEALContext(parms);

            using KeyGenerator keygen = new KeyGenerator(context);

            using PublicKey riderPub = new PublicKey();
            using (var sr = new StreamReader(publicFile))
            {
                riderPub.Load(context, sr.BaseStream);
            }

            using SecretKey riderSec = new SecretKey();
            using (var sr = new StreamReader(secretFile))
            {
                riderSec.Load(context, sr.BaseStream);
            }

            using Ciphertext X2MinusX1SquaredPlusY2MinusY1Squared = new Ciphertext();
            using (var sr = new StreamReader(distanceFile))
            {
                X2MinusX1SquaredPlusY2MinusY1Squared.Load(context, sr.BaseStream);
            }

            using Encryptor riderEncryptor = new Encryptor(context, riderPub);
            using Decryptor riderDecryptor = new Decryptor(context, riderSec);


            using Plaintext distance = new Plaintext();
            riderDecryptor.Decrypt(X2MinusX1SquaredPlusY2MinusY1Squared, distance);

            using IntegerEncoder encoder = new IntegerEncoder(context);

            //Console.WriteLine("Decrypted polynomial f(x) = {0}.", distance );
            //Console.WriteLine("     distance from rider {0}", encoder.DecodeUInt64(distance));
            return(encoder.DecodeUInt64(distance));
        }