Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change a do {} while(1); to a do {} and add debugging

  • Loading branch information...
commit aeff0ed161f92327d109f34da90b75e7db099a53 1 parent 058d022
@leto authored
Showing with 10 additions and 10 deletions.
  1. +5 −3 lib/Math/Factoring.pm
  2. +5 −7 spec/pollard_rho.cc
View
8 lib/Math/Factoring.pm
@@ -28,12 +28,14 @@ sub _random()
my $state = rand_init($n);
my $rand = GMP->new;
Rmpz_urandomm($rand, $state, $n,1);
+ #warn "return rand=$rand";
return $rand;
}
sub _factor_pollard_rho($$$)
{
my ($n,$a,$x0) = @_;
+ warn "_factor_pollard($n,$a,$x0)\n";
my ($x,$y,$q,$d) = map { GMP->new } ( 1 .. 4 );
my ($i,$j) = (1,1);
$q = 1; $x = $x0; $y = $x0;
@@ -61,8 +63,8 @@ sub _factor_pollard_rho($$$)
}
}
}
- return 0;
- } while (1);
+ };
+ return 0;
}
@@ -77,7 +79,7 @@ sub factor($)
my $t;
while( !is_prime($n) ) {
$t = _factor_pollard_rho($n,$a,$x0);
- warn "found t=$t";
+ warn "found t=$t,n=$n";
last if $t == 0;
push @factors, "$t";
$n /= $t;
View
12 spec/pollard_rho.cc
@@ -42,9 +42,9 @@ Integer factor(Integer n, int a_int, int x0)
if (!isprime(d))
return factor(d, (random() & 32) - 16, random() & 31);
else return d;
- }
- } // if ( (i % j) == 0)
- } // while n != 1
+ }
+ }
+ } // while n != 1
return 0;
}
@@ -55,10 +55,8 @@ main (int argc, char *argv[])
int x0, a;
int p;
- if (argc != 2) {
- cerr << "Usage: " << argv[0] << " NumberToFactor" << endl;
- return -1;
- }
+ if (argc != 2) { cerr << "Usage: " << argv[0] << " NumberToFactor" << endl;
+ return -1; }
n = argv[1];

0 comments on commit aeff0ed

Please sign in to comment.
Something went wrong with that request. Please try again.