A*B modulo N - - 2


i- FOR  P).  i (i=[1,...,n]) abs(Pi)<N, rm-1£N£rm.

.

.

k=abs(p_short) DIV n_short, DIV - ,

p_short=(k+d)*n_short, (2.1.6)

k - , 0£k<r-1 0£d<1.

if p_short-k*n_short>n_short DIV 2 ,

d>0.5 (2.1.7)

i- :

P'=Pi-1*r+A*B[i] (2.1.8)

 


 

 

 

 

P

 

m_shifts:=0;

while n[m_shifts]=0 do

begin

shift_left(N and A);

m_shifts:=m_shifts+1;

end;

m:=m_shifts;

reset(P);

n_short:=N[m];

for i:=n downto 1 do

begin

shift_left(P); { 1 P*r}

if b<>0 then

addk(A*B[i],{to}P);

let p_short represent the 2 high assimilated digits of P;

k:=abs(p_short) div n_short;

if p_short-k*n_short>n_short div 2 then k:=k+1;

if k>0 then

begin

if p_short<0 then

addk(k*N,{to} P)

else

addk(-k*N,{to} P);

end;

end;{for}

right shift P, N by m_shifts;

if P<0 then

P:=P+N;

write(P); {P - }

 

 

 

. 2.2. A*B modulo N

 


 

:

 1. k=0, .. n_short>abs(p_short) (. ), ADDK , ..


- -  - -  - -