예제 #1
0
        static public EncryptedSealBfvVector DenseMatrixBySparseVectorMultiply(EncryptedSealBfvVector[] denses, EncryptedSealBfvVector sparse, EncryptedSealBfvEnvironment env)
        {
            var res = new EncryptedSealBfvVector()
            {
                Scale    = denses[0].Scale * sparse.Scale,
                eVectors = denses[0].ForEveryEncryptedVector(i => AtomicSealBfvEncryptedVector.DenseMatrixBySparseVectorMultiplyTask(denses.Select(d => d.eVectors[i]).ToArray(), sparse.eVectors[i], env.Environments[i]))
            };

            return(res);
        }
예제 #2
0
        static public EncryptedSealBfvVector Stack(EncryptedSealBfvVector[] vecs, EncryptedSealBfvEnvironment env)
        {
            var res = new EncryptedSealBfvVector()
            {
                eVectors = vecs[0].ForEveryEncryptedVector(i => AtomicSealBfvEncryptedVector.StackTask(vecs.Select(v => v.eVectors[i]).ToArray(), env.Environments[i])),
                Scale    = vecs[0].Scale
            };

            return(res);
        }
예제 #3
0
        public EncryptedSealBfvVector(IEnumerable <BigInteger> v, IComputationEnvironment env, bool EncryptData = true, EVectorFormat Format = EVectorFormat.dense)
        {
            this.Scale = Scale;
            var leenv  = env as EncryptedSealBfvEnvironment;
            var splits = SplitBigNumbers(v, leenv);

            eVectors = new AtomicSealBfvEncryptedVector[leenv.Environments.Length];
            Parallel.For(0, eVectors.Length, i =>
            {
                eVectors[i] = new AtomicSealBfvEncryptedVector(splits[i], leenv.Environments[i], Scale: 1, SignedNumbers: false, EncryptData: EncryptData, Format: Format);
            });
        }
예제 #4
0
        public static IVector GenerateSpareOfArray(IVector[] SparseVectors, IComputationEnvironment env)
        {
            var lenv = env as EncryptedSealBfvEnvironment;
            var res  = new EncryptedSealBfvVector()
            {
                Scale    = SparseVectors[0].Scale,
                eVectors = new AtomicSealBfvEncryptedVector[((EncryptedSealBfvVector)(SparseVectors[0])).eVectors.Length]
            };

            for (int i = 0; i < res.eVectors.Length; i++)
            {
                res.eVectors[i] = AtomicSealBfvEncryptedVector.GenerateSparseOfArray(SparseVectors.Select(v => ((EncryptedSealBfvVector)v).eVectors[i]).ToArray(), lenv.Environments[i]);
            }
            return(res);
        }
예제 #5
0
        public static EncryptedSealBfvVector Read(StreamReader str, EncryptedSealBfvEnvironment env)
        {
            var vct  = new EncryptedSealBfvVector();
            var line = str.ReadLine();

            if (line != "<Start LargeEncryptedVector>")
            {
                throw new Exception("Bad stream format.");
            }
            vct.Scale    = double.Parse(str.ReadLine());
            vct.eVectors = new AtomicSealBfvEncryptedVector[int.Parse(str.ReadLine())];
            for (int i = 0; i < vct.eVectors.Length; i++)
            {
                vct.eVectors[i] = AtomicSealBfvEncryptedVector.Read(str, env.Environments[i]);
            }

            line = str.ReadLine();
            if (line != "<End LargeEncryptedVector>")
            {
                throw new Exception("Bad stream format.");
            }
            return(vct);
        }