---------------------------------------------------------------- -- Double, Add and Reduce Multiplication mod M (dar_mod_multiplication.adb) -- -- Multiplies X by Y mod M using K bits numbers -- ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; with finite_fields; use finite_fields; procedure dar_mod_multiplication is int_x, y, m, k, p, q, product: integer; x: bit_vector(0 .. k-1); begin loop Put("x = "); Get(int_x); New_Line; Put("y = "); Get(y); New_Line; Put("m = "); Get(m); New_Line; Put("k = "); Get(k); New_Line; q := int_x; for i in 0 .. k-1 loop x(i) := q mod 2; q := q/2; end loop; ---------------------------------------------- p := 0; for i in 0 .. k-1 loop p := mod_m_addition(p, p, m, k); if x(k-i-1) = 1 then p := mod_m_addition(p, y, m, k); end if; end loop; product := p; ---------------------------------------------- Put(int_x); Put(" * "); Put(y); Put(" mod "); Put(m); Put(" = "); Put(product); New_Line; New_Line; end loop; end dar_mod_multiplication;