Modular exponentiation: Difference between revisions

Content added Content deleted
(factorised out function exp_factor to improve structure)
(missed out binary_exp in list edit)
Line 466: Line 466:
Mod > 0 ->
Mod > 0 ->
binary_exp_mod(Base,Exp,Mod).
binary_exp_mod(Base,Exp,Mod).

binary_exp(Base,Exponent) ->
binary_exp(Base,Exponent,1).
binary_exp(_,0,Result) ->
Result;
binary_exp(Base,Exponent,Acc) ->
binary_exp(Base*Base,Exponent bsr 1,Acc * exp_factor(Base,Exponent)).



binary_exp_mod(Base,Exponent,Mod) ->
binary_exp_mod(Base,Exponent,Mod) ->