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 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); }
private void init() { millerRabbin = new MillerRabin(); random = new Random(); p = GetSimpleNum(length); q = GetSimpleNum(length); eyler = (p - 1) * (q - 1); N = p * q; montRed = new MontgomeryReducer(N); expSqr = new ExponentiationSquaring(); //byte[] arr = N.ToByteArray(); e = GetOpenExponent(2 * length / 3); d = MathMethods.GCD(e, eyler); }