Exemplo n.º 1
0
        /// <summary>
        /// Decrypt a cipher text
        /// </summary>
        /// 
        /// <param name="Input">The cipher text</param>
        /// 
        /// <returns>The plain text</returns>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if cipher has not been initialized</exception>
        public byte[] Decrypt(byte[] Input)
        {
            if (!_isInitialized)
                throw new CryptoAsymmetricException("RLWEEncrypt:Decrypt", "The cipher has not been initialized!", new InvalidOperationException());
            if (_isEncryption)
                throw new CryptoAsymmetricException("RLWEEncrypt:Decrypt", "The cipher is not initialized for decryption!", new ArgumentException());

            int plen = _N >> 3;

            if (_N == 512)
            {
                NTT512 ntt = new NTT512(_rndEngine);
                return ntt.Decrypt((RLWEPrivateKey)_asmKey, Input).SubArray(_mFp, plen - _mFp);
            }
            else
            {
                NTT256 ntt = new NTT256(_rndEngine);
                return ntt.Decrypt((RLWEPrivateKey)_asmKey, Input).SubArray(_mFp, plen - _mFp);
            }
        }