2025-12-15 23:25:12 -05:00
2025-12-11 23:49:34 -05:00
2025-12-11 23:49:34 -05:00
2025-12-15 21:05:52 -05:00
2025-12-15 21:05:52 -05:00
2025-12-15 21:18:12 -05:00
2025-12-15 21:05:52 -05:00
2025-12-15 22:37:25 -05:00
2025-12-15 23:25:12 -05:00
2025-12-11 23:49:35 -05:00
2025-12-15 21:05:52 -05:00

mcalc

mcalc is a calculator for modular arithmetic.

Quirks

Why can't exponents be expressions? Why do they have to be integers?

This is easiest to explain with an example: what should 2^(3+4) evaluate to modulo 7? In my opinion, it should be 2, since 2^7 = 2 (mod 7). However, because all the operators in the calculator are implemented as modular operators, it will first evaluate (3+4) as 0, leading to 2^0 = 1 (mod 7). I saw three options:

  1. Leave this behavior in, even if it's not what I think most people would expect.
  2. Complicate the code by handling exponent expressions non-modularly.
  3. Simply don't let exponents be expressions.

I chose 3.

Why can't I compute square roots for a composite modulus?

It is certainly possible to compute modular square roots with a composite modulus, and I would like to add the capability at some point, but as implemented, the calculator only supports a prime modulus.

Why is the ord() function so slow when the modulus is large?

Partly because computing multiplicative order is a hard problem, and partly because I'm too lazy at the moment to implement a slightly more efficient algorithm.

Description
modular arithmetic calculator
Readme 106 KiB
Languages
JavaScript 74.7%
HTML 17.3%
CSS 8%