1 USING: kernel math errors math-contrib ;
4 ! As per http://www.cyphercalc.com/index.htm
5 : montgomery-image ( a n -- a' )
6 #! a' = a * nextpowerof2(a) mod n
7 >r dup next-power-of-2 * r> mod ;
9 ! : montgomery* ( a b -- a*b )
12 : montgomery-r^2 ( n -- a )
13 #! ans = r^2 mod n, where r = nextpowerof2(n)
14 [ next-power-of-2 sq ] keep mod ;
16 : montgomery-n0' ( n0 size -- n0' )
17 #! size should be a multiple of 2, n0 is odd and n0 < 2^size
18 #! n0 * n0' = -1 mod 2^w
19 2 swap ^ swap neg mod-inv ;