[19079] in cryptography@c2.net mail archive

home help back first fref pref prev next nref lref last post

Re: Fermat's primality test vs. Miller-Rabin

daemon@ATHENA.MIT.EDU (Sidney Markowitz)
Sat Dec 3 13:55:31 2005

X-Original-To: cryptography@metzdowd.com
X-Original-To: cryptography@metzdowd.com
Date: Sun, 04 Dec 2005 03:41:54 +1300
From: Sidney Markowitz <sidney@sidney.com>
To: Joseph Ashwood <ashwood@msn.com>
Cc: cryptography@metzdowd.com
In-Reply-To: <BAY0-SMTP0499FBEE8C0BA37A1E6F73AC4D0@phx.gbl>

Joseph Ashwood wrote:
>   byte [] rawBytes = new byte[lenNum/8];
>   rand.nextBytes(rawBytes);
>   curNum = new BigInteger(rawBytes);

I haven't thought through why it would produce non-primes, but it
doesn't seem to do what you want. That produces a 512 bit
twos-complement number, which gives you a 511 bit positive integer, not
512 bit. It also is unnecessarily complicated compared to this form of
the BigInteger constructor and the or method (see the javadoc):

curNum = BigInteger.ONE.or(new BigInteger(512, rand));

 -- Sidney Markowitz
    http://www.sidney.com

---------------------------------------------------------------------
The Cryptography Mailing List
Unsubscribe by sending "unsubscribe cryptography" to majordomo@metzdowd.com

home help back first fref pref prev next nref lref last post