---------------------------------------------------------------- -- Binary mod M subtraction (binary_mod_M_subtraction.adb) -- -- Subtract Y form X mod M using K bits numbers -- Preconditions X < M, X < 2**K, Y < M, Y < 2**K and M < 2**K ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; --with finite_fields; use finite_fields; procedure binary_mod_m_subtraction is x, y, sum, z1, z2, c1, m, k, z: integer; begin loop Put("x = "); Get(x); New_Line; Put("y = "); Get(y); New_Line; Put("m = "); Get(m); New_Line; Put("k = "); Get(k); New_Line; ---------------------------------------------- sum := x + (2**k - y); z1 := (sum mod 2**k); c1 := sum/2**k; z2 := (z1 + m) mod 2**k; if c1 = 1 then z := z1; else z := z2; end if; ---------------------------------------------- Put(x); Put(" - "); Put(y); Put(" mod "); Put(m); Put(" = "); Put(z); New_Line; New_Line; end loop; end binary_mod_m_subtraction;