public void TestRSA(decimal input, decimal encodePower, decimal modulus, decimal totient) { var rsa = new RSA(encodePower, modulus); var decodePower = Modular.ModInverse(rsa.EncodePower, totient); #if DEBUG OutputHelper.WriteLine($"decodePower = {decodePower} = ModInverse(encodePower = {rsa.EncodePower}, totient = {totient})"); var product = rsa.EncodePower * decodePower % totient; Assert.True(product == 1, $"1 != {product} = encodePower = {rsa.EncodePower} * decodePower = {decodePower} % totient = {totient}"); #endif var encoded = rsa.Encode(input); #if DEBUG OutputHelper.WriteLine($"{encoded} = Encode(input = {input}, encodePower = {rsa.EncodePower}, modulus = {rsa.Modulus})"); #endif var decoded = rsa.Decode(encoded, totient); #if DEBUG OutputHelper.WriteLine($"{decoded} = Decode(encoded = {encoded}, decodePower = {decodePower}, modulus = {rsa.Modulus})"); #endif Assert.True(decoded == input, $"decoded = {decoded} != input = {input}"); }