mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-21 03:14:50 +00:00
new upstream
git-svn-id: file:///srv/svn/joey/trunk/src/packages/bsdgames@10080 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.10 2002/09/19 03:15:39 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.11 2004/02/08 13:16:25 jsm Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
# For MKCRYPTO
|
||||
@@ -17,7 +17,6 @@ DPADD+= ${LIBCRYPTO}
|
||||
.endif
|
||||
|
||||
MAN= factor.6
|
||||
MLINKS+=factor.6 primes.6
|
||||
.PATH: ${PRIMES}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: factor.6,v 1.8 2003/08/07 09:37:12 agc Exp $
|
||||
.\" $NetBSD: factor.6,v 1.9 2004/02/08 13:16:25 jsm Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@@ -37,54 +37,45 @@
|
||||
.\"
|
||||
.\" chongo <for a good prime call: 391581 * 2^216193 - 1> /\oo/\
|
||||
.\"
|
||||
.Dd May 31, 1993
|
||||
.Dt PRIMES 6
|
||||
.Dd February 8, 2004
|
||||
.Dt FACTOR 6
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm primes
|
||||
.Nd generate primes
|
||||
.Nm factor
|
||||
.Nd factor a number
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar number ...
|
||||
.br
|
||||
.Nm primes
|
||||
.Op Ar start Op Ar stop
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm primes
|
||||
utility prints primes in ascending order, one per line, starting at or above
|
||||
.Ar start
|
||||
and continuing until, but not including
|
||||
.Ar stop .
|
||||
The
|
||||
.Ar start
|
||||
value must be at least 0 and not greater than
|
||||
.Ar stop .
|
||||
The
|
||||
.Ar stop
|
||||
value must not be greater than 4294967295.
|
||||
The default value of
|
||||
.Ar stop
|
||||
is 4294967295.
|
||||
.Nm
|
||||
utility will factor integers between \-2147483648 and 2147483647 inclusive.
|
||||
When a number is factored, it is printed, followed by a
|
||||
.Dq \&: ,
|
||||
and the list of factors on a single line.
|
||||
Factors are listed in ascending order, and are preceded by a space.
|
||||
If a factor divides a value more than once, it will be printed more than once.
|
||||
.Pp
|
||||
When the
|
||||
.Nm primes
|
||||
utility is invoked with no arguments,
|
||||
.Ar start
|
||||
is read from standard input.
|
||||
.Ar stop
|
||||
is taken to be 4294967295.
|
||||
The
|
||||
.Ar start
|
||||
value may be preceded by a single +.
|
||||
The
|
||||
.Ar start
|
||||
value is terminated by a non-digit character (such as a newline).
|
||||
The input line must not be longer than 255 characters.
|
||||
When
|
||||
.Nm
|
||||
is invoked with one or more arguments, each argument will be factored.
|
||||
.Pp
|
||||
When
|
||||
.Nm
|
||||
is invoked with no arguments,
|
||||
.Nm
|
||||
reads numbers, one per line, from standard input, until end of file or error.
|
||||
Leading white-space and empty lines are ignored.
|
||||
Numbers may be preceded by a single - or +.
|
||||
Numbers are terminated by a non-digit character (such as a newline).
|
||||
After a number is read, it is factored.
|
||||
Input lines must not be longer than 255 characters.
|
||||
.Sh DIAGNOSTICS
|
||||
Out of range or invalid input results in
|
||||
.Sq ouch
|
||||
an appropriate error message
|
||||
being written to standard error.
|
||||
.Sh BUGS
|
||||
.Nm primes
|
||||
won't get you a world record.
|
||||
.Nm
|
||||
cannot handle the
|
||||
.Dq 10 most wanted
|
||||
factor list.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: factor.c,v 1.14 2003/08/07 09:37:12 agc Exp $ */
|
||||
/* $NetBSD: factor.c,v 1.15 2004/02/08 11:47:36 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)factor.c 8.4 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: factor.c,v 1.14 2003/08/07 09:37:12 agc Exp $");
|
||||
__RCSID("$NetBSD: factor.c,v 1.15 2004/02/08 11:47:36 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -231,7 +231,9 @@ pr_fact(BIGNUM *val)
|
||||
bnfact = BN_new();
|
||||
BN_set_word(bnfact, *(fact - 1));
|
||||
BN_sqr(bnfact, bnfact, ctx);
|
||||
if (BN_cmp(bnfact, val) > 0) {
|
||||
if (BN_cmp(bnfact, val) > 0
|
||||
|| BN_is_prime(val, PRIME_CHECKS, NULL, NULL,
|
||||
NULL) == 1) {
|
||||
putchar(' ');
|
||||
BN_print_dec_fp(stdout, val);
|
||||
} else
|
||||
@@ -280,23 +282,29 @@ usage(void)
|
||||
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
/* pollard rho, algorithm from Jim Gillogly, May 2000 */
|
||||
/* pollard p-1, algorithm from Jim Gillogly, May 2000 */
|
||||
|
||||
void
|
||||
pollard_pminus1(BIGNUM *val)
|
||||
{
|
||||
BIGNUM *base, *num, *i, *x;
|
||||
BIGNUM *base, *rbase, *num, *i, *x;
|
||||
|
||||
base = BN_new();
|
||||
rbase = BN_new();
|
||||
num = BN_new();
|
||||
i = BN_new();
|
||||
x = BN_new();
|
||||
|
||||
BN_set_word(rbase, 1);
|
||||
newbase:
|
||||
BN_add_word(rbase, 1);
|
||||
BN_set_word(i, 2);
|
||||
BN_set_word(base, 2);
|
||||
BN_copy(base, rbase);
|
||||
|
||||
for (;;) {
|
||||
BN_mod_exp(base, base, i, val, ctx);
|
||||
if (BN_is_one(base))
|
||||
goto newbase;
|
||||
|
||||
BN_copy(x, base);
|
||||
BN_sub_word(x, 1);
|
||||
|
||||
Reference in New Issue
Block a user