What version of je are you running? I get innocuous results:
genkey 32
15970092203996114281 4061548213 3932020837
genkey 32
14979749644274477941 4038627851 3709118591
genkey 32
15125320685289546439 3974107847 3805966337
If you are not running the latest beta, I suggest doing so; among other
things, support for extended-precision numbers was much improved.
On Thu, 16 Feb 2023, Mike Duvos wrote:
I wrote a brief J script to generate random RSA keys in various lengths. I
put a copy in my Dropbox at the following URL…
https://www.dropbox.com/s/0y0tpgtjtv4vvd2/rsakeys.ijs
In this script is a function called “genkey” which crashes J.
genkey =: 3 : 0"0
q =. p =. randprime y
while. q = p
do.
q =. randprime y
end.
if. p < q
do.
'p q'=. q,p
end.
(p*q),p,q
)
randprime y returns a random prime of length y bits with the upper two bits
set as an extended precision integer. It seems rock solid and has been
called millions of times without issue.
genkey picks a prime, p, and another prime not equal to it, q, and swaps
them if necessary so p is the larger one. It then returns a vector of
length 3, consisting of p*q, p, and q.
If you load this script, and type “genkey 32”, you get a “J has stopped
working, reporting to Microsoft” dialogue box immediately.
If I write another function, “keygen” which does the same thing as genkey,
but phrased slightly differently, it works perfectly.
keygen =: 3 : 0"0
z =. ''
while. 2 > #z
do.
z =. ~. z , randprime y
end.
(*/z),\:~z
)
keygen 5#32
13636890702424146503 3697445573 3688192411
14042631972443509627 3975272443 3532495489
15856784938324374101 4290006247 3696214883
12482175669738327193 3743048207 3334762199
14012721502477771067 4146478969 3379426643
I’m new to J programming, so I’m sure I’ve just done something dumb. Any
insights would be appreciated.
Thanks.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm