public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) { for (int i = 0; i < inputCount; ++i) { // TODOL to another func transform_simple_block Array.Copy(inputBuffer, inputOffset + i * _inputBlockSize, _inputBuf, 0, _inputBlockSize); BigInteger text = new BigInteger(_inputBuf); BigInteger transformed = RSAAlg.BinPowMod(text, _e, _n); byte[] bytes = transformed.ToByteArrayWithoutZero(); Array.Copy(bytes, 0, outputBuffer, outputOffset + i * _outputBlockSize, bytes.Length); for (int j = bytes.Length; j < _outputBlockSize; ++j) { outputBuffer[outputOffset + i * _outputBlockSize + j] = 0; } } return(inputCount); }
// static private static bool TryFindExponents(BigInteger eulerFuncN, out BigInteger e, out BigInteger d) { List <int> primes = RSAAlg.CalcPrimes(100); Random random = new Random(123); // TODOL remove seed e = primes[random.Next(2, primes.Count)]; if (RSAAlg.GCD(e, eulerFuncN, out d, out BigInteger _) == 1) { if (d < 0) { d = (d % eulerFuncN) + eulerFuncN; } return(true); } else { return(false); } }