Modular exponentiation: Difference between revisions
Content deleted Content added
m added whitespace. |
factorised out function exp_factor to improve structure |
||
Line 466:
Mod > 0 ->
binary_exp_mod(Base,Exp,Mod).
binary_exp(Base,Exponent) ->▼
binary_exp(Base,Exponent,1).▼
Result;▼
binary_exp_mod(Base,Exponent,Mod) ->
binary_exp_mod(Base rem Mod,Exponent,Mod,1).
binary_exp_mod(_,0,_,Result) ->
Result;
binary_exp_mod(Base,Exponent,Mod,Acc) ->
binary_exp_mod((Base
Exponent bsr 1,Mod,(Acc * exp_factor(Base,Exponent))rem Mod).
exp_factor(_,0) ->
Base;
test() ->
|