to cliff, I've converted the file, I will upload a repository late today. Converting is relatively easy, as J helpfully points out any ommissions. A tip to avoid local variables x,y is worth heeding.
to Raul, I think Cliff's code is the right approach, as it is 1000x faster than my adaptation of the python code which, to my inconvenience, didn't seem to produce fully correct results either. ----- Original Message ----- From: Raul Miller <rauldmil...@gmail.com> To: Programming forum <programm...@jsoftware.com> Cc: Sent: Friday, January 31, 2014 9:50:10 AM Subject: Re: [Jprogramming] math requests I have tried to transcribe the python code as J. https://gist.github.com/rdm/8733290 Currently this code has two issues. First, the objects are not garbage collected. This is a trivial issue because it's also failing the test suite. (I see no value in adding complexity to buggy code to make it more efficient - I'd rather first get it working so I have a reference implementation and then start rephrasing it to not use objects at all). The first problem triggered by the test suite happens in the loop that begins with for_i. i. 7+1 do. p=. mul__g 7 | i It fails when i is 3, and this is the first test with multiplcation where either of the if statements in the point multiplication code gets triggered: while. 1 < i=. <. -: i do. result=. double__result'' if. (0 ~: e3 bitAnd i) *. (0 = e bitAnd i) do. result=. add__This result end. if. (0 = e3 bitAnd i) *. (0 ~: e bitAnd i) do. result=. add__negativeSelf result end. end. It's the second if statement which triggers and the result is incorrect. Anyways, I've been staring at this for hours an it's probably a trivial mistake. So I'm hoping that someone with a deeper understanding of the math can explain to me how to think about this. Or, I am hoping that someone with a fresher set of eyes can see my mistake. (And, I should probably have capitalized the name negativeSelf for consistency.) Thanks, -- Raul On Wed, Jan 29, 2014 at 11:35 AM, Pascal Jasmin <godspiral2...@yahoo.ca>wrote: > > > With all of the mathematicians on this list, these functions have likely > been implemented before in J. > > elyptic curve point add, multiplication and double > a python reference implementation: > https://github.com/warner/python-ecdsa/blob/master/ecdsa/ellipticcurve.py > > the functions are: __add__ __mul__ and double > > if I may suggest J explicit signatures for the first 2 functions as: > > F =: 4 : 0 > 'yx yy yo' =. y > 'xx xy xo' =. x > ) > > Some other methods than the python reference could be considered here: > > http://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication > > > also appreciated if you have in implementation of inverse_mod > for reference function of same nate at: > https://github.com/warner/python-ecdsa/blob/master/ecdsa/numbertheory.py > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm