Exemplo n.º 1
0
        public VectorIntPair[] Encrypt(string message)
        {
            //всю строку в бинарь
            string binary = string.Join("", Encoding.UTF8.GetBytes(message).Select(n => Convert.ToString(n, 2).PadLeft(8, '0')));

            VectorIntPair[] output = new VectorIntPair[binary.Length];
            for (int i = 0; i < binary.Length; i++)
            {
                //каждый бит - в пару вектор-число
                List <int> subset = _rng.GetSubset(_dimension);
                int[]      a      = new int[_N];
                int        b      = int.Parse(binary[i].ToString()) + _module;
                if (b % 2 == 1)
                {
                    b += _module;
                }
                b /= 2;
                for (int j = 0; j < subset.Count; j++)
                {
                    a  = CalculateVectorSum(a, _open[subset[j]].A);
                    b += _open[subset[j]].B;
                }
                b        %= _module;
                output[i] = new VectorIntPair(a, b);
            }
            return(output);
        }
Exemplo n.º 2
0
 private void GenerateOpenKey()
 {
     _open = new VectorIntPair[_dimension];
     for (int i = 0; i < _dimension; i++)
     {
         int[] a = _rng.GenerateVector(_N);
         //вот тут волшебная неправильная ошибка
         int error = _rng.GenerateInt(2);
         int b     = (CalculateScalar(a, _secret) + error) % _module;
         _open[i] = new VectorIntPair(a, b);
     }
 }