public BigInteger[] EncryptMontgomery(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.MonExp(new BigInteger(s), key.KeyFirst); } return(bigNumArray); }
public string DescryptMontgomery(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.MonExp(encryptedMessage[i], key.KeyFirst).ToByteArray()); } return(message); }