Montgomery reduction: Difference between revisions

(Added c#)
Line 108:
{{trans|D}}
<lang csharp>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
 
Line 129 ⟶ 125:
return result;
}
 
/// https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
//public static BigInteger ModPow(this BigInteger b, BigInteger e, BigInteger n) {
// if (n.IsOne) return BigInteger.Zero;
// BigInteger result = 1;
// b %= n;
// while (e > 0) {
// if (!e.IsEven) {
// result = (result * b) % n;
// }
// e >>= 1;
// b = (b * b) % n;
// }
// return result;
//}
}
 
1,452

edits