Esempio n. 1
0
        public BigInteger[] EncryptMontgomeryBin(string message, Key key)
        {
            montRed = new MontgomeryReducer(key.KeySecond);

            int numArrayBlock = (message.Length / lenghtString) + 1;

            string[]     arrayString = new string[numArrayBlock];
            BigInteger[] bigNumArray = new BigInteger[numArrayBlock];

            for (int i = 0; i < arrayString.Length; i++)
            {
                if (numArrayBlock - i == 1)
                {
                    arrayString[i] = message.Substring(i * lenghtString, message.Length - i * lenghtString);
                }
                else
                {
                    arrayString[i] = message.Substring(i * lenghtString, lenghtString);
                }

                byte[] s = System.Text.Encoding.UTF8.GetBytes(arrayString[i]);
                bigNumArray[i] = montRed.MonBinExp(new BigInteger(s), key.KeyFirst);
            }

            return(bigNumArray);
        }
Esempio n. 2
0
        public string DescryptMontgomeryBin(BigInteger[] encryptedMessage, Key key)
        {
            montRed = new MontgomeryReducer(key.KeySecond);

            string message = "";

            for (int i = 0; i < encryptedMessage.Length; i++)
            {
                message += System.Text.Encoding.UTF8.GetString
                               (montRed.MonBinExp(encryptedMessage[i], key.KeyFirst).ToByteArray());
            }

            return(message);
        }