---------------------------------------------------------------- -- Montgomery Product (Montgomery_product.adb) -- -- A simple example of -- MP(x,y) = x.y/R mod M -- ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; procedure Montgomery_product is R: constant Natural := 256; M: constant Natural := 239; --Inv_R: constant := 225; Minus_Inv_M: constant := 241; X, Y, Product, Q, Z: Natural; begin loop Put("x = "); Get(X); Put("y = "); Get(Y); --------------------------------------------------------------------- Product := X*Y; Q := (Product + ((Product*Minus_Inv_M) mod R)*M) / R; if Q >= M then Z := Q-M; else Z := Q; end if; ---------------------------------------------------------------------- Put("x.y/R mod m = "); Put(Z); New_Line; end loop; end Montgomery_product;