Modular exponentiation by squares (fast)

Bug: BAD for big values ( I'm trying to fix :)

Fixed: converted to JS BigInt type ( new JS type - maybe, not every browser supports it??? )

 
 
 
  a=   n=   p=