algorithm - Modular exponentiation relatively slow in Pascal -
i have been developing program in pascal generating large primes. after many tries have (i hope) implemented modular exponentiation using montgomery exponentiation algorithm. way faster right-to-left binary method tests. used algorithms handbook of applied cryptography chapter 14, because used http://www.javascripter.net/math/calculators/100digitbigintcalculator.htm checking mistakes , online calculator big numbers.
modular exponentiation of 100 digit numbers (base,exp,mod) takes 300ms compared javascript version. feels slow. have tried using profiling code , fixed couple of bottlenecks still pretty slow imo compared javascript implementation. profiling shows of calls used basic multiplication (vynasob function) , subtraction (odecti function), dont see how can made faster. because represent numbers base 10 in array? dont think of problem. here code https://github.com/honzaik/pprime/blob/master/pprime.lpr if kind , skimmed through if find weird stuff might help. code in czech sadly tho. important functions are:
isprime = rabin-miller montexp = montgomery exponentiation montmult = montgomery multiplication secti = addition odecti = subtraction vynasob = multiplication vydel = division modulus = modulus as said, represent numbers array in base 10. eg 10587 = [7,8,5,0,1]
thank responses
the answer/advice improvement use biggest base can. changed base 10 base 2097151 , 300ms became 8ms. thank in comments advices
Comments
Post a Comment